1 +import assert from 'node:assert/strict';
2 +import test from 'node:test';
8 +} from './isp-start-day.mjs';
10 +test('parses an explicit report date', () => {
11 + const date = parseDateArg(['--date', '2026-07-17']);
14 + [date.getFullYear(), date.getMonth(), date.getDate()],
19 +test('rejects an invalid report date', () => {
21 + () => parseDateArg(['--date', '2026-02-30']),
22 + /Invalid date: 2026-02-30/,
26 +function officeBody(accountId, values) {
27 + const cells = Array.from({ length: 31 }, (_, index) => {
28 + const value = values[index + 1];
30 + ? `<td data-highlight-colour="#fff0b3">${value}</td>`
35 + <tr><td data-highlight-colour="#fff0b3">A</td><td>Abwesend</td></tr>
38 + <table><tr><td>R&D</td><td>${accountId}</td>${cells}</tr></table>
42 +test('checks through month-end and proposes missing office values', () => {
43 + const values = Object.fromEntries(
44 + [15, 16, 17, 20, 21, 22, 23, 24, 27, 28, 29].map((day) => [day, 'A']),
46 + const output = parseOffice(
47 + officeBody('account-1', values),
49 + new Date(2026, 6, 15, 12),
52 + assert.match(output, /30:_\/no-color/);
53 + assert.match(output, /31:_\/no-color/);
54 + assert.match(output, /Future workdays missing planning: 30, 31/);
55 + assert.match(output, /Proposed update: 30=A \(from 23\), 31=A \(from 24\)/);
56 + assert.match(output, /Confirm or correct each value \(B\/BP\/H\/A\/AP\)/);
59 +const readyTicket = {
61 + fields: { status: { name: 'Ready to Sync' }, summary: 'Review me' },
63 +const friday = new Date(2026, 6, 17, 12);
65 +function pr(overrides = {}) {
68 + title: 'RD-1 Review me',
69 + headRefName: 'feature/RD-1',
71 + updatedAt: '2026-07-16T12:00:00Z',
76 +test('flags Ready to Sync without an open PR', () => {
77 + const result = jiraReviewFindings([readyTicket], [], friday);
79 + assert.match(result.action.join('\n'), /RD-1.*no open PR/);
80 + assert.equal(result.waiting.length, 0);
83 +test('flags requested review changes', () => {
84 + const result = jiraReviewFindings(
86 + [pr({ reviewDecision: 'CHANGES_REQUESTED' })],
90 + assert.match(result.action.join('\n'), /PR #42.*changes requested/);
93 +test('flags review activity older than one workday', () => {
94 + const result = jiraReviewFindings(
96 + [pr({ updatedAt: '2026-07-15T12:00:00Z' })],
100 + assert.match(result.action.join('\n'), /PR #42.*stale since 2026-07-15/);
103 +test('keeps recently active review work waiting', () => {
104 + const result = jiraReviewFindings([readyTicket], [pr()], friday);
106 + assert.equal(result.action.length, 0);
107 + assert.match(result.waiting.join('\n'), /RD-1.*PR #42.*waiting for review/);
110 +test('does not call an approved PR stale', () => {
111 + const result = jiraReviewFindings(
113 + [pr({ reviewDecision: 'APPROVED', updatedAt: '2026-07-14T12:00:00Z' })],
117 + assert.equal(result.action.length, 0);
118 + assert.match(result.waiting.join('\n'), /RD-1.*PR #42.*approved/);
121 +test('does not apply review findings to other Jira states', () => {
124 + fields: { ...readyTicket.fields, status: { name: 'In Progress' } },
126 + const result = jiraReviewFindings([ticket], [], friday);
128 + assert.deepEqual(result, { action: [], waiting: [] });