Initial Commit
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
import { describe, expect, it } from "@suaveplan/testing/runner";
|
||||
import {
|
||||
GRAPHQL_UI_GRAPHIQL_CODES,
|
||||
type GraphqlUiGraphiqlCode,
|
||||
GraphqlUiGraphiqlError,
|
||||
} from "./error-codes.js";
|
||||
|
||||
describe("GRAPHQL_UI_GRAPHIQL_CODES registry", () => {
|
||||
it("exposes the two contract-layer codes", { timeout: 5000 }, () => {
|
||||
expect(GRAPHQL_UI_GRAPHIQL_CODES.ASSET_MISSING).toBe(
|
||||
"GRAPHQL_UI_GRAPHIQL.ASSET_MISSING"
|
||||
);
|
||||
expect(GRAPHQL_UI_GRAPHIQL_CODES.ENDPOINT_COLLISION).toBe(
|
||||
"GRAPHQL_UI_GRAPHIQL.ENDPOINT_COLLISION"
|
||||
);
|
||||
});
|
||||
|
||||
it("registry is frozen", { timeout: 5000 }, () => {
|
||||
expect(Object.isFrozen(GRAPHQL_UI_GRAPHIQL_CODES)).toBe(true);
|
||||
});
|
||||
|
||||
it("GraphqlUiGraphiqlError mirrors code in graphiqlCode + name", {
|
||||
timeout: 5000,
|
||||
}, () => {
|
||||
const err = new GraphqlUiGraphiqlError(
|
||||
GRAPHQL_UI_GRAPHIQL_CODES.ASSET_MISSING,
|
||||
"boom"
|
||||
);
|
||||
expect(err).toBeInstanceOf(GraphqlUiGraphiqlError);
|
||||
expect(err.graphiqlCode).toBe(GRAPHQL_UI_GRAPHIQL_CODES.ASSET_MISSING);
|
||||
expect(err.code).toBe(GRAPHQL_UI_GRAPHIQL_CODES.ASSET_MISSING);
|
||||
expect(err.name).toBe("GraphqlUiGraphiqlError");
|
||||
expect(err.message).toBe("boom");
|
||||
});
|
||||
|
||||
it("GraphqlUiGraphiqlError accepts cause + context", {
|
||||
timeout: 5000,
|
||||
}, () => {
|
||||
const cause = new Error("downstream");
|
||||
const err = new GraphqlUiGraphiqlError(
|
||||
GRAPHQL_UI_GRAPHIQL_CODES.ENDPOINT_COLLISION,
|
||||
"collision",
|
||||
{ cause, context: { path: "/graphql/ui" } }
|
||||
);
|
||||
expect(err.cause).toBe(cause);
|
||||
expect(err.context).toEqual({ path: "/graphql/ui" });
|
||||
});
|
||||
|
||||
it("GraphqlUiGraphiqlCode narrows correctly", { timeout: 5000 }, () => {
|
||||
const code: GraphqlUiGraphiqlCode =
|
||||
GRAPHQL_UI_GRAPHIQL_CODES.ENDPOINT_COLLISION;
|
||||
expect(code).toBe("GRAPHQL_UI_GRAPHIQL.ENDPOINT_COLLISION");
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user