Text search not case insensitive in testing environment
Hi for some reason my case insensitive test doesn't pass despite it working when i run the function from the dashboard.
Here's the test:
My schema:
My implementation:
Here's the test:
test("searchPacts - case insensitive search", async () => {
const { t, user1Id } = await setup();
await createPactWithMembership(t, user1Id, "MORNING YOGA", true);
await t.withIdentity({ subject: USER1_CLERK_ID }).run(async (ctx) => {
const results = await PactDiscoverModel.searchPacts(ctx, "morning");
expect(results).toHaveLength(1);
expect(results[0].title).toBe("MORNING YOGA");
});
});test("searchPacts - case insensitive search", async () => {
const { t, user1Id } = await setup();
await createPactWithMembership(t, user1Id, "MORNING YOGA", true);
await t.withIdentity({ subject: USER1_CLERK_ID }).run(async (ctx) => {
const results = await PactDiscoverModel.searchPacts(ctx, "morning");
expect(results).toHaveLength(1);
expect(results[0].title).toBe("MORNING YOGA");
});
});My schema:
pacts: defineTable({
title: v.string(),
category: v.string(),
frequency: v.string(),
fineAmount: v.number(),
proofDetails: v.string(),
selectedProofMethod: v.optional(v.string()),
selectedDataType: v.optional(v.string()),
minimumValue: v.optional(v.string()),
selectedJoinType: v.optional(joinTypeValidator),
selectedAccessRights: v.optional(v.string()),
createdBy: v.id("users"),
createdAt: v.optional(v.number()),
isArchived: v.optional(v.boolean()),
archivedAt: v.optional(v.number()),
})
.index("by_creator", ["createdBy"])
.index("by_category", ["category"])
.index("by_archived", ["isArchived"])
.index("by_join_type", ["selectedJoinType"])
.searchIndex("search_title", {
searchField: "title",
filterFields: ["isArchived", "selectedJoinType"],
}),pacts: defineTable({
title: v.string(),
category: v.string(),
frequency: v.string(),
fineAmount: v.number(),
proofDetails: v.string(),
selectedProofMethod: v.optional(v.string()),
selectedDataType: v.optional(v.string()),
minimumValue: v.optional(v.string()),
selectedJoinType: v.optional(joinTypeValidator),
selectedAccessRights: v.optional(v.string()),
createdBy: v.id("users"),
createdAt: v.optional(v.number()),
isArchived: v.optional(v.boolean()),
archivedAt: v.optional(v.number()),
})
.index("by_creator", ["createdBy"])
.index("by_category", ["category"])
.index("by_archived", ["isArchived"])
.index("by_join_type", ["selectedJoinType"])
.searchIndex("search_title", {
searchField: "title",
filterFields: ["isArchived", "selectedJoinType"],
}),My implementation:
const pactTitleResults = await ctx.db
.query("pacts")
.withSearchIndex("search_title", (q) =>
q.search("title", searchQuery).eq("isArchived", false)
)
.collect();
console.log("pactTitleResultss", pactTitleResults);const pactTitleResults = await ctx.db
.query("pacts")
.withSearchIndex("search_title", (q) =>
q.search("title", searchQuery).eq("isArchived", false)
)
.collect();
console.log("pactTitleResultss", pactTitleResults);