test(comments review): 抽出嚴重等級解析斷言
This commit is contained in:
+19
-2
@@ -6,6 +6,13 @@ import path from 'node:path';
|
|||||||
import { saveFindings, parseLocation, postNewCriticalComments, postFindingsReview } from './comments.js';
|
import { saveFindings, parseLocation, postNewCriticalComments, postFindingsReview } from './comments.js';
|
||||||
import { FINDINGS_PATH } from './config.js';
|
import { FINDINGS_PATH } from './config.js';
|
||||||
|
|
||||||
|
const REVIEW_SEVERITY_PATTERN = /\*\*嚴重等級\*\*:(🔴 嚴重|🟡 警告|🔵 建議)(?:\n|$)/;
|
||||||
|
const REVIEW_SEVERITY_LABELS = ['🔴 嚴重', '🟡 警告', '🔵 建議'];
|
||||||
|
|
||||||
|
function reviewSeverityLabel(comment) {
|
||||||
|
return comment.body.match(REVIEW_SEVERITY_PATTERN)?.[1];
|
||||||
|
}
|
||||||
|
|
||||||
describe('saveFindings', () => {
|
describe('saveFindings', () => {
|
||||||
const tempDirs = [];
|
const tempDirs = [];
|
||||||
const makeTempDir = prefix => {
|
const makeTempDir = prefix => {
|
||||||
@@ -187,6 +194,16 @@ describe('postNewCriticalComments', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('postFindingsReview', () => {
|
describe('postFindingsReview', () => {
|
||||||
|
it('extracts review severity labels only when the format is valid', () => {
|
||||||
|
assert.equal(
|
||||||
|
reviewSeverityLabel({ body: '**嚴重等級**:🔴 嚴重\n**審查員**:Rex' }),
|
||||||
|
'🔴 嚴重',
|
||||||
|
);
|
||||||
|
assert.equal(reviewSeverityLabel({ body: '**審查員**:Rex' }), undefined);
|
||||||
|
assert.equal(reviewSeverityLabel({ body: '**嚴重等級**:' }), undefined);
|
||||||
|
assert.equal(reviewSeverityLabel({ body: '**嚴重等級**:高風險' }), undefined);
|
||||||
|
});
|
||||||
|
|
||||||
it('posts one review with statistics and sorted line comments', async () => {
|
it('posts one review with statistics and sorted line comments', async () => {
|
||||||
const reviewCalls = [];
|
const reviewCalls = [];
|
||||||
const findings = [
|
const findings = [
|
||||||
@@ -209,8 +226,8 @@ describe('postFindingsReview', () => {
|
|||||||
['app/a.js', 'app/b.js', 'app/c.js'],
|
['app/a.js', 'app/b.js', 'app/c.js'],
|
||||||
);
|
);
|
||||||
assert.deepEqual(
|
assert.deepEqual(
|
||||||
reviewCalls[0].comments.map(c => c.body.match(/嚴重等級\*\*:(.+)/)?.[1]),
|
reviewCalls[0].comments.map(reviewSeverityLabel),
|
||||||
['🔴 嚴重', '🟡 警告', '🔵 建議'],
|
REVIEW_SEVERITY_LABELS,
|
||||||
);
|
);
|
||||||
assert.deepEqual(
|
assert.deepEqual(
|
||||||
reviewCalls[0].comments.map(c => c.new_position),
|
reviewCalls[0].comments.map(c => c.new_position),
|
||||||
|
|||||||
Reference in New Issue
Block a user