49 lines
1.4 KiB
TypeScript
49 lines
1.4 KiB
TypeScript
/**
|
|
* DMP error-codes spec-conformance — `DMP_CODES` is frozen and every
|
|
* thrown `DmpError` references a code from the registry.
|
|
*/
|
|
|
|
import { describe, expect, it } from "@suaveplan/testing/runner";
|
|
import { DMP_CODES, DmpError } from "../src/index.js";
|
|
|
|
describe("DMP_CODES is frozen", () => {
|
|
it("DMP_CODES is frozen", { timeout: 5000 }, () => {
|
|
expect(Object.isFrozen(DMP_CODES)).toBe(true);
|
|
});
|
|
|
|
it("every value is namespaced under DMP.", { timeout: 5000 }, () => {
|
|
for (const v of Object.values(DMP_CODES)) {
|
|
expect(v).toMatch(/^DMP\./);
|
|
}
|
|
});
|
|
|
|
it("every code can construct a DmpError that preserves it", {
|
|
timeout: 5000,
|
|
}, () => {
|
|
for (const code of Object.values(DMP_CODES)) {
|
|
const e = new DmpError(code, "ok");
|
|
expect(e.code).toBe(code);
|
|
}
|
|
});
|
|
|
|
it("registry contains the codes the codecs/trust modules throw", {
|
|
timeout: 5000,
|
|
}, () => {
|
|
const expected = [
|
|
"EMPTY_REQUEST",
|
|
"UNKNOWN_REQUEST_KIND",
|
|
"MAX_CHUNKS_EXCEEDED",
|
|
"BITSET_LENGTH_MISMATCH",
|
|
"BITSET_PADDING_NONZERO",
|
|
"UNORDERED_RESPONSE",
|
|
"GENERATION_STALE",
|
|
"CODEC_MISMATCH",
|
|
"ENVELOPE_MALFORMED",
|
|
"THROTTLE_EXCEEDED",
|
|
] as const;
|
|
for (const k of expected) {
|
|
expect(DMP_CODES).toHaveProperty(k);
|
|
}
|
|
});
|
|
});
|