Approval needs an active sheet (lock sheet, version, round); a base only from a still-published round version; rights.mfa before rights.capability; withdrawal of a published round refused; approver separation at publish; deprecate and working copy serialised; closed codes; append-only acks; upload policy bound to the registering editor. pgTAP 017-019 added.
45 lines
2.0 KiB
TypeScript
45 lines
2.0 KiB
TypeScript
import { readFile } from 'node:fs/promises'
|
|
import { join } from 'node:path'
|
|
import { SHEET_FAILURE_KINDS, SheetFailure, classifySheetError } from '../src/sheets'
|
|
import { migrationsDir } from './db/harness'
|
|
|
|
/**
|
|
* The closed failure kinds of the sheet workflow (V1-2.1). The census reads
|
|
* every closed code M4 and M5 raise (`raise exception '<code>'`, a lowercase
|
|
* dotted word; free-text messages are not codes) so a code added on the server
|
|
* can never reach a page as `unavailable` for want of a kind.
|
|
*/
|
|
const SHEET_MIGRATIONS = [
|
|
'20261028100000_sheet_access_hardening.sql',
|
|
'20261028110000_sheet_review_workflow.sql',
|
|
]
|
|
|
|
async function raisedCodes(): Promise<string[]> {
|
|
const codes = new Set<string>()
|
|
for (const file of SHEET_MIGRATIONS) {
|
|
const sql = await readFile(join(migrationsDir, file), 'utf8')
|
|
for (const match of sql.matchAll(/raise exception '([a-z_]+(?:\.[a-z_]+)*)'/g))
|
|
codes.add(match[1])
|
|
}
|
|
return [...codes].sort()
|
|
}
|
|
|
|
describe('sheet failure kinds', () => {
|
|
it('names every closed code the sheet migrations raise', async () => {
|
|
const kinds = new Set<string>(SHEET_FAILURE_KINDS)
|
|
const codes = await raisedCodes()
|
|
expect(codes.length).toBeGreaterThan(50)
|
|
expect(codes.filter((code) => !kinds.has(code))).toEqual([])
|
|
})
|
|
|
|
it('folds an answer into its kind and fails closed on anything else', () => {
|
|
expect(classifySheetError({ code: 'P0001', message: 'view.asset.unknown' })).toBe('view.asset.unknown')
|
|
expect(classifySheetError({ code: '42501', message: 'rights.mfa' })).toBe('rights.mfa')
|
|
expect(classifySheetError({ code: '40P01', message: 'deadlock detected' })).toBe('conflict_retry')
|
|
expect(classifySheetError({ code: '23505', message: 'duplicate key value' })).toBe('unavailable')
|
|
expect(classifySheetError({}, 401)).toBe('session_expired')
|
|
expect(classifySheetError(new TypeError('fetch failed'))).toBe('network')
|
|
expect(classifySheetError(new SheetFailure('draft.exists'))).toBe('draft.exists')
|
|
})
|
|
})
|