Initial Commit

This commit is contained in:
2026-05-27 23:29:53 +01:00
commit fbc70f96e6
10000 changed files with 1102152 additions and 0 deletions

View File

@@ -0,0 +1,63 @@
import { describe, expect, it } from "@suaveplan/testing/runner";
import { AUDIENCE_RULES_CODES, AudienceRulesError } from "./error-codes.js";
describe("AUDIENCE_RULES_CODES + AudienceRulesError", () => {
it("registers four namespaced codes", { timeout: 5000 }, () => {
expect(AUDIENCE_RULES_CODES.INVALID_INPUT).toBe(
"AUDIENCE_RULES.INVALID_INPUT"
);
expect(AUDIENCE_RULES_CODES.SEGMENT_NOT_FOUND).toBe(
"AUDIENCE_RULES.SEGMENT_NOT_FOUND"
);
expect(AUDIENCE_RULES_CODES.UNKNOWN_OPERATOR).toBe(
"AUDIENCE_RULES.UNKNOWN_OPERATOR"
);
expect(AUDIENCE_RULES_CODES.PROVIDER_FAILED).toBe(
"AUDIENCE_RULES.PROVIDER_FAILED"
);
});
it("every registered code constructs an AudienceRulesError with namespaced code", {
timeout: 5000,
}, () => {
for (const code of Object.values(AUDIENCE_RULES_CODES)) {
const err = new AudienceRulesError(code, "msg");
expect(err).toBeInstanceOf(AudienceRulesError);
expect(err.code).toBe(code);
expect(err.message).toBe("msg");
}
});
it("every code exposes its discriminants on the instance", {
timeout: 5000,
}, () => {
const err = new AudienceRulesError(
AUDIENCE_RULES_CODES.SEGMENT_NOT_FOUND,
"missing",
{ segmentId: "seg_1", tenantId: "tenant-1" }
);
expect(err.segmentId).toBe("seg_1");
expect(err.tenantId).toBe("tenant-1");
});
it("leaves discriminants undefined when not provided", {
timeout: 5000,
}, () => {
const err = new AudienceRulesError(
AUDIENCE_RULES_CODES.INVALID_INPUT,
"x"
);
expect(err.segmentId).toBeUndefined();
expect(err.tenantId).toBeUndefined();
});
it("preserves cause across constructor", { timeout: 5000 }, () => {
const cause = new Error("root");
const err = new AudienceRulesError(
AUDIENCE_RULES_CODES.PROVIDER_FAILED,
"wrapped",
{ cause }
);
expect(err.cause).toBe(cause);
});
});