Convex test does not validate schemas
This is a problem I've been having for a while now, and It's probably time to fix it.
this code runs perfectly fine:
with the following schema:
Any Ideas on exactly why this is happening?
this code runs perfectly fine:
test("create + getByAuthId + get", async () => {
const t = convexTest(schema);
// 1) create a new user via your create mutation
const newUser: User = {
authId: AuthId("auth-1"),
invalid: "invalid",
};
const userId = await t.mutation(internal.users.create, newUser);
// 2) fetch by authId
const byAuth = await t.query(internal.users.getByAuthId, { authId: AuthId("auth-1") });
expect(byAuth).toMatchObject(Option.some(newUser));
// 3) fetch by generated ID
const byId = await t.query(internal.users.get, { userId });
expect(byId).toMatchObject(Option.some(newUser));
}); test("create + getByAuthId + get", async () => {
const t = convexTest(schema);
// 1) create a new user via your create mutation
const newUser: User = {
authId: AuthId("auth-1"),
invalid: "invalid",
};
const userId = await t.mutation(internal.users.create, newUser);
// 2) fetch by authId
const byAuth = await t.query(internal.users.getByAuthId, { authId: AuthId("auth-1") });
expect(byAuth).toMatchObject(Option.some(newUser));
// 3) fetch by generated ID
const byId = await t.query(internal.users.get, { userId });
expect(byId).toMatchObject(Option.some(newUser));
});with the following schema:
export const User = v.union(
v.object({
...BaseUser.fields,
...AdminOnly.fields
}),
v.object({
...BaseUser.fields,
...EmployeeOnly.fields
}),
);
export type User = typeof User.type
// =============================================================================
// USER TABLE DEFINITION
// =============================================================================
export const usersTable = defineTable(User)
.index("by_auth_id", ["authId"])
.index("by_role", ["role"])
.index("by_deleted_at", ["deletedAt"]);
export default defineSchema({
//...
users: usersTable,
});export const User = v.union(
v.object({
...BaseUser.fields,
...AdminOnly.fields
}),
v.object({
...BaseUser.fields,
...EmployeeOnly.fields
}),
);
export type User = typeof User.type
// =============================================================================
// USER TABLE DEFINITION
// =============================================================================
export const usersTable = defineTable(User)
.index("by_auth_id", ["authId"])
.index("by_role", ["role"])
.index("by_deleted_at", ["deletedAt"]);
export default defineSchema({
//...
users: usersTable,
});Any Ideas on exactly why this is happening?
