The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
Trim search before the exact email and partner ID match
Rafi5c0eb16e56fe
diff --git a/apps/web/lib/api/partners/program-enrollment-query.ts b/apps/web/lib/api/partners/program-enrollment-query.tsindex 3df1b16547..4a4627ca5d 100644--- a/apps/web/lib/api/partners/program-enrollment-query.ts+++ b/apps/web/lib/api/partners/program-enrollment-query.ts@@ -29,11 +29,13 @@ export function isExactPartnerIdQuery(query: string): boolean {*/export function buildPartnerEmailSearchWhere({email,- search,+ search: rawSearch,}: {email?: string | null;search?: string | null;}): Prisma.PartnerWhereInput {+ const search = rawSearch?.trim();+if (email) {return { email };}diff --git a/apps/web/tests/partners/partner-email-search-where.test.ts b/apps/web/tests/partners/partner-email-search-where.test.tsnew file mode 100644index 0000000000..a66c6880cf--- /dev/null+++ b/apps/web/tests/partners/partner-email-search-where.test.ts@@ -0,0 +1,36 @@+import { buildPartnerEmailSearchWhere } from "@/lib/api/partners/program-enrollment-query";+import { describe, expect, it, vi } from "vitest";++vi.mock("@/lib/prisma", () => ({+ sanitizeFullTextSearch: (value: string) => value,+}));++describe("buildPartnerEmailSearchWhere", () => {+ // The candidate path decides the exact routes on the trimmed value, so this+ // builder must judge the same value: a pasted " pn_… " is routed to the+ // database as an exact ID, and an untrimmed exact match would find nothing.+ it.each([+ [+ "a padded partner ID",+ " pn_dlszeepb38rvcnrfbd0srkzb ",+ { id: "pn_dlszeepb38rvcnrfbd0srkzb" },+ ],+ ["a padded email", " [email protected] ", { email: "[email protected]" }],+ ])("trims %s before the exact match", (_label, search, expected) => {+ expect(buildPartnerEmailSearchWhere({ search })).toEqual(expected);+ });++ it("full-text searches the trimmed free text", () => {+ expect(buildPartnerEmailSearchWhere({ search: " steven " })).toEqual({+ OR: [+ { email: { search: "steven" } },+ { name: { search: "steven" } },+ { companyName: { search: "steven" } },+ ],+ });+ });++ it("treats a blank search as absent", () => {+ expect(buildPartnerEmailSearchWhere({ search: " " })).toEqual({});+ });+});