test: cover review edge cases and repair paths

This commit is contained in:
2026-05-13 06:23:45 +00:00
parent 8f413439b3
commit 3f3ead0f08
8 changed files with 243 additions and 41 deletions
+31
View File
@@ -0,0 +1,31 @@
import { describe, it } from 'node:test';
import assert from 'node:assert/strict';
import { postOldFindingsComment, postNewNonCriticalComment, postNewCriticalComments } from './comments.js';
describe('comment publishers', () => {
it('skips publishing when there are no matching findings', async () => {
let called = 0;
await postOldFindingsComment([], async () => { called += 1; });
await postNewNonCriticalComment([], async () => { called += 1; });
await postNewCriticalComments([], async () => { called += 1; });
assert.equal(called, 0);
});
it('publishes old, non-critical, and critical comments in separate calls', async () => {
const bodies = [];
const findings = [
{ level: 'warning', role: 'Rex', location: 'a.js:1', suggestion: 'fix', is_new: false },
{ level: 'info', role: 'Maya', location: 'b.js:2', suggestion: 'note', is_new: true },
{ level: 'critical', role: 'Aria', location: 'c.js:3', suggestion: 'stop', is_new: true },
];
await postOldFindingsComment(findings, async body => bodies.push(body));
await postNewNonCriticalComment(findings, async body => bodies.push(body));
await postNewCriticalComments(findings, async body => bodies.push(body));
assert.equal(bodies.length, 3);
assert.match(bodies[0], /舊有未解決問題/);
assert.match(bodies[1], /新發現問題/);
assert.match(bodies[2], /嚴重問題/);
});
});