Define TypeBox enum schemas (CallStatus, NodeStatus, OperationType, EdgeType) with Nullable helper
This commit is contained in:
@@ -1,7 +1,102 @@
|
||||
import { describe, it, expect } from 'vitest';
|
||||
import { describe, it, expect } from "vitest";
|
||||
import { Value } from "@alkdev/typebox/value";
|
||||
import {
|
||||
CallStatusEnum,
|
||||
NodeStatusEnum,
|
||||
OperationTypeEnum,
|
||||
EdgeTypeEnum,
|
||||
Nullable,
|
||||
type CallStatus,
|
||||
type NodeStatus,
|
||||
type OperationType,
|
||||
type EdgeType,
|
||||
} from "../../src/schema/enums";
|
||||
|
||||
describe('schema enums', () => {
|
||||
it('placeholder', () => {
|
||||
expect(true).toBe(true);
|
||||
describe("CallStatusEnum", () => {
|
||||
const valid: CallStatus[] = [
|
||||
"pending",
|
||||
"running",
|
||||
"completed",
|
||||
"failed",
|
||||
"aborted",
|
||||
];
|
||||
it.each(valid)("accepts %s", (v) => {
|
||||
expect(Value.Check(CallStatusEnum, v)).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
it("rejects invalid values", () => {
|
||||
expect(Value.Check(CallStatusEnum, "idle")).toBe(false);
|
||||
expect(Value.Check(CallStatusEnum, "unknown")).toBe(false);
|
||||
expect(Value.Check(CallStatusEnum, 42)).toBe(false);
|
||||
expect(Value.Check(CallStatusEnum, null)).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe("NodeStatusEnum", () => {
|
||||
const valid: NodeStatus[] = [
|
||||
"idle",
|
||||
"waiting",
|
||||
"ready",
|
||||
"running",
|
||||
"completed",
|
||||
"failed",
|
||||
"skipped",
|
||||
"aborted",
|
||||
];
|
||||
it.each(valid)("accepts %s", (v) => {
|
||||
expect(Value.Check(NodeStatusEnum, v)).toBe(true);
|
||||
});
|
||||
|
||||
it("rejects invalid values", () => {
|
||||
expect(Value.Check(NodeStatusEnum, "pending")).toBe(false);
|
||||
expect(Value.Check(NodeStatusEnum, "unknown")).toBe(false);
|
||||
expect(Value.Check(NodeStatusEnum, 1)).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe("OperationTypeEnum", () => {
|
||||
const valid: OperationType[] = ["query", "mutation", "subscription"];
|
||||
it.each(valid)("accepts %s", (v) => {
|
||||
expect(Value.Check(OperationTypeEnum, v)).toBe(true);
|
||||
});
|
||||
|
||||
it("rejects invalid values", () => {
|
||||
expect(Value.Check(OperationTypeEnum, "fetch")).toBe(false);
|
||||
expect(Value.Check(OperationTypeEnum, 0)).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe("EdgeTypeEnum", () => {
|
||||
const valid: EdgeType[] = [
|
||||
"triggered",
|
||||
"depends_on",
|
||||
"typed",
|
||||
"sequential",
|
||||
"conditional",
|
||||
];
|
||||
it.each(valid)("accepts %s", (v) => {
|
||||
expect(Value.Check(EdgeTypeEnum, v)).toBe(true);
|
||||
});
|
||||
|
||||
it("rejects invalid values", () => {
|
||||
expect(Value.Check(EdgeTypeEnum, "parent")).toBe(false);
|
||||
expect(Value.Check(EdgeTypeEnum, false)).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe("Nullable", () => {
|
||||
it("accepts null", () => {
|
||||
const schema = Nullable(EdgeTypeEnum);
|
||||
expect(Value.Check(schema, null)).toBe(true);
|
||||
});
|
||||
|
||||
it("accepts valid enum values", () => {
|
||||
const schema = Nullable(EdgeTypeEnum);
|
||||
expect(Value.Check(schema, "typed")).toBe(true);
|
||||
});
|
||||
|
||||
it("rejects invalid non-null values", () => {
|
||||
const schema = Nullable(EdgeTypeEnum);
|
||||
expect(Value.Check(schema, "invalid")).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user