Testing with document Ids as a field
Trying out convex test and this code is resulting in an error, do I need to test create a record in the orgs table and then send that to the test mutation & match?
error:
function generateMockID() {
return uuidv4().replace(/-/g, "");
}
test("sending messages", async () => {
const orgId = generateMockID() as Id<'orgs'>;
console.log(orgId);
const t = convexTest(schema);
await t.mutation(api.tasks.insert, {
task: {
name: "Task 1",
text: "This is a task",
slug:"TEST-001",
org_id: orgId,
}
});
await t.mutation(api.tasks.insert, {
task: {
name: "Task 2",
text: "This is another task",
slug:"TEST-002",
org_id: orgId,
}
});
const tasks = await t.query(api.tasks.getAll);
expect(tasks).toMatchObject([
{
name: "Task 1",
text: "This is a task",
slug:"TEST-001",
org_id: orgId,
} ,
{
name: "Task 2",
text: "This is another task",
slug:"TEST-002",
org_id: orgId,
}
]);
});function generateMockID() {
return uuidv4().replace(/-/g, "");
}
test("sending messages", async () => {
const orgId = generateMockID() as Id<'orgs'>;
console.log(orgId);
const t = convexTest(schema);
await t.mutation(api.tasks.insert, {
task: {
name: "Task 1",
text: "This is a task",
slug:"TEST-001",
org_id: orgId,
}
});
await t.mutation(api.tasks.insert, {
task: {
name: "Task 2",
text: "This is another task",
slug:"TEST-002",
org_id: orgId,
}
});
const tasks = await t.query(api.tasks.getAll);
expect(tasks).toMatchObject([
{
name: "Task 1",
text: "This is a task",
slug:"TEST-001",
org_id: orgId,
} ,
{
name: "Task 2",
text: "This is another task",
slug:"TEST-002",
org_id: orgId,
}
]);
});error:
FAIL convex/tests/tasks.test.ts > sending messages
Error: Validator error: Expected ID for table "orgs", got `af9c0e9660b94258873a98c0a1b5c198`
❯ validateValidator node_modules/convex-test/dist/index.js:682:23
681| return;
682| }
683| case "array": {
| ^
684| if (!Array.isArray(value)) {
685| throw new Error(`Validator error: Expected \`Array\`, got \`${value}\``); FAIL convex/tests/tasks.test.ts > sending messages
Error: Validator error: Expected ID for table "orgs", got `af9c0e9660b94258873a98c0a1b5c198`
❯ validateValidator node_modules/convex-test/dist/index.js:682:23
681| return;
682| }
683| case "array": {
| ^
684| if (!Array.isArray(value)) {
685| throw new Error(`Validator error: Expected \`Array\`, got \`${value}\``);