The open alternative to Salesforce, designed for AI.
TypeScript crmcrm-systemcustomergood-first-issuegraphqlhacktoberfestjavascriptmarketingmonoreponestjsopen-sourcepostgresqlreactreactjssalestypescriptweb
fix(tests): make the gmail mock honour the in:sent search filter (#24259)
Thomas Trompettedc6be93b8ee7
diff --git a/packages/twenty-server/test/integration/google/mocks/gmail-message-list-handler.util.ts b/packages/twenty-server/test/integration/google/mocks/gmail-message-list-handler.util.tsindex b4761eba5e4..e4542379544 100644--- a/packages/twenty-server/test/integration/google/mocks/gmail-message-list-handler.util.ts+++ b/packages/twenty-server/test/integration/google/mocks/gmail-message-list-handler.util.ts@@ -3,15 +3,32 @@ import { http, HttpResponse } from 'msw';import { type MswHandler } from 'test/integration/utils/http-mock.util';+// Only the onboarding import sends a positive `in:` term. The full sync's+// `-label:` / `-category:` exclusions and `label:` inclusions stay unapplied.+const INCLUDED_LABEL_REGEX = /(?:^|\s)in:(\w+)/g;++const matchesSearchFilter = (+ message: gmail_v1.Schema$Message,+ searchFilter: string,+): boolean =>+ [...searchFilter.matchAll(INCLUDED_LABEL_REGEX)].every(([, labelName]) =>+ message.labelIds?.includes(labelName.toUpperCase()),+ );+export const gmailMessageListHandler = (messages: gmail_v1.Schema$Message[],): MswHandler =>- http.get('*/gmail/v1/users/me/messages', () =>- HttpResponse.json<gmail_v1.Schema$ListMessagesResponse>({- messages: messages.map((message) => ({+ http.get('*/gmail/v1/users/me/messages', ({ request }) => {+ const searchFilter = new URL(request.url).searchParams.get('q') ?? '';+ const matchingMessages = messages.filter((message) =>+ matchesSearchFilter(message, searchFilter),+ );++ return HttpResponse.json<gmail_v1.Schema$ListMessagesResponse>({+ messages: matchingMessages.map((message) => ({id: message.id,threadId: message.threadId,})),- resultSizeEstimate: messages.length,- }),- );+ resultSizeEstimate: matchingMessages.length,+ });+ });