diff --git a/app/comments.test.js b/app/comments.test.js index ddcc817..319c55e 100644 --- a/app/comments.test.js +++ b/app/comments.test.js @@ -6,13 +6,6 @@ import path from 'node:path'; import { saveFindings, parseLocation, postNewCriticalComments, postFindingsReview } from './comments.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', () => { const tempDirs = []; const makeTempDir = prefix => { @@ -194,6 +187,21 @@ describe('postNewCriticalComments', () => { }); describe('postFindingsReview', () => { + const REVIEW_SEVERITY_LABELS = ['🔴 嚴重', '🟡 警告', '🔵 建議']; + const REVIEW_SEVERITY_PATTERN = new RegExp(`\\*\\*嚴重等級\\*\\*:(${REVIEW_SEVERITY_LABELS.join('|')})(?:\\n|$)`); + + function reviewSeverityLabel(comment) { + return comment?.body?.match(REVIEW_SEVERITY_PATTERN)?.[1]; + } + + it('handles missing review severity bodies gracefully', () => { + assert.equal(reviewSeverityLabel(null), undefined); + assert.equal(reviewSeverityLabel(undefined), undefined); + assert.equal(reviewSeverityLabel({}), undefined); + assert.equal(reviewSeverityLabel({ body: null }), undefined); + assert.equal(reviewSeverityLabel({ body: undefined }), undefined); + }); + it('extracts review severity labels only when the format is valid', () => { assert.equal( reviewSeverityLabel({ body: '**嚴重等級**:🔴 嚴重\n**審查員**:Rex' }),