Skip to content

Commit

Permalink
Test that system fields are not exposed in table validators (#27195)
Browse files Browse the repository at this point in the history
Test that system fields are not exposed in table validators.
This is not a behavior change, just making the tests clearer.

GitOrigin-RevId: 363b0b6f224fd36ef40d8955614d3bd1fe81c4a7
  • Loading branch information
thomasballinger authored and Convex, Inc. committed Jun 18, 2024
1 parent cc0d914 commit 29a1037
Showing 1 changed file with 20 additions and 10 deletions.
30 changes: 20 additions & 10 deletions src/server/schema.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -720,22 +720,32 @@ test("Infer", () => {
assert<Equals<Actual, Expected>>();
});

test("defineSchema exposes table validators", () => {
describe("defineSchema/defineTable expose table validators", () => {
const obj = {
ref: v.id("reference"),
string: v.string(),
} as const;
const table = defineTable(obj);
const actual = table.validator;
const expected = v.object(obj);
expect(actual).toEqual(expected);
assert<Equals<typeof actual, typeof expected>>();
const schema = defineSchema({ table });

const schema = defineSchema({
table: defineTable(obj),
test("defineTable", () => {
const actual = table.validator;
const expected = v.object(obj);
expect(actual).toEqual(expected);
assert<Equals<typeof actual, typeof expected>>();
});

test("defineSchema", () => {
const actual = schema.tables.table.validator;
const expected = v.object(obj);
expect(actual).toEqual(expected);
assert<Equals<typeof actual, typeof expected>>();
});

const actual2 = schema.tables.table.validator;
expect(actual2).toEqual(expected);
assert<Equals<typeof actual2, typeof expected>>();
test("system tables are not present", () => {
expect(table.validator).not.toHaveProperty("_id");
expect(table.validator).not.toHaveProperty("_creationTime");
expect(schema.tables.table.validator).not.toHaveProperty("_id");
expect(schema.tables.table.validator).not.toHaveProperty("_creationTime");
});
});

0 comments on commit 29a1037

Please sign in to comment.