Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions packages/convex-helpers/server/zod4.convextozod.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,14 @@
Infer,
v,
VFloat64,
VLiteral,

Check warning on line 10 in packages/convex-helpers/server/zod4.convextozod.test.ts

View workflow job for this annotation

GitHub Actions / Test and lint

'VLiteral' is defined but never used. Allowed unused vars must match /^_/u
VString,
VUnion,

Check warning on line 12 in packages/convex-helpers/server/zod4.convextozod.test.ts

View workflow job for this annotation

GitHub Actions / Test and lint

'VUnion' is defined but never used. Allowed unused vars must match /^_/u
} from "convex/values";
import { convexToZod, Zid, zid, ZodValidatorFromConvex } from "./zod4";
import { isSameType } from "zod-compare/zod4";
import { literals } from "../validators";
import { ignoreUnionOrder } from "./zod4.zodtoconvex.test";

Check warning on line 17 in packages/convex-helpers/server/zod4.convextozod.test.ts

View workflow job for this annotation

GitHub Actions / Test and lint

'ignoreUnionOrder' is defined but never used. Allowed unused vars must match /^_/u

test("Zid is a record key", () => {
const myZid = zid("users");
Expand Down Expand Up @@ -205,6 +209,40 @@
});
});
});

// https://github.com/get-convex/convex-helpers/issues/861
test("regression: literals helper", () => {
testConvexToZod(
v.object({
firstName: v.string(),
lastName: v.string(),
gender: literals("male", "female", "other"),
}),
z.object({
firstName: z.string(),
lastName: z.string(),
gender: z.union([
z.literal("male"),
z.literal("female"),
z.literal("other"),
]),
}),
);
});

// https://github.com/get-convex/convex-helpers/issues/861#issuecomment-3593231904
test("regression: spreading an enum into v.union", () => {
enum Gender {
Male = "male",
Female = "female",
Other = "other",
}

testConvexToZod(
v.union(...Object.values(Gender).map(v.literal)),
z.literal([Gender.Male, Gender.Female, Gender.Other]),

Check failure on line 243 in packages/convex-helpers/server/zod4.convextozod.test.ts

View workflow job for this annotation

GitHub Actions / Test and lint

Argument of type 'ZodLiteral<Gender>' is not assignable to parameter of type 'ZodLiteral<Gender> & "Expected type must exactly match ZodValidatorFromConvex<C>"'.
);
});
});

// Type equality helper: checks if two types are exactly equal (bidirectionally assignable)
Expand Down
Loading