Hello, when testing a function that uses the index "by_creation_time" , convex-test are failing and reporting an error. It looks like to me the code is valid, so I believe it's a convex-test issue:
Example:
Code
export const deleteNotifications = internalMutation({
handler: async ctx => {
const now = Date.now();
const staleTimestamp = now - 30 * 24 * 60 * 60 * 1000;
const notificationsToDelete = await ctx.db
.query('notifications')
.withIndex('by_creation_time', q => q.lt('_creationTime', staleTimestamp))
.take(500);
await asyncMap(notificationsToDelete, async notification => {
await ctx.db.delete(notification._id);
});
},
});
Test
import {convexTest} from 'convex-test';
import {expect, test, vi} from 'vitest';
import schema from './schema';
import {internal} from './_generated/api';
test('Delete old notifications', async () => {
// ...
const t = convexTest(schema);
await t.mutation(internal.notifications.deleteNotifications);
// ...
Error while running tests
Cannot use index "by_creation_time" for table "notifications" because it is not declared in the schema.
Just reporting the issue, thanks in advance if you fix it. Have a nice day Convex team 🙋♂️