riatsila
riatsila
CCConvex Community
Created by riatsila on 9/20/2024 in #support-community
Sorting different on backend vs frontend in React
I have a weird bug where I have a query that sorts a table of tasks based on "start_date".
const tasks = await ctx.db.query("tasks")
.withIndex("by_project", (q) => q.eq("project_id", projectId))
.order("asc")
.collect();
console.log(tasks);
return tasks;
const tasks = await ctx.db.query("tasks")
.withIndex("by_project", (q) => q.eq("project_id", projectId))
.order("asc")
.collect();
console.log(tasks);
return tasks;
When logging on the backend the sort is completed correctly, but the object received on the frontend is sorted by _creationtime. const tasks = useQuery(api.tasks.getByProjectId, project?._id ? {projectId: project._id}: "skip"); Can sort tasks again on the frontend, but wondering if there's anything obvious I'm missing that would cause this behaviour!
7 replies
CCConvex Community
Created by riatsila on 9/2/2024 in #support-community
t.withIdentity with custom claims
We currently have some helper functions which check custom claims on the getUserIdentity object e.g. "orgId". Am I right in thinking that in convex-test (0.0.28) these custom claims currently aren't supported when using t.withIdentity?
3 replies
CCConvex Community
Created by riatsila on 8/15/2024 in #support-community
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?
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}\``);
4 replies