Files
code-review/app/comments.test.js
T

32 lines
1.4 KiB
JavaScript

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], /嚴重問題/);
});
});