The open alternative to Salesforce, designed for AI.
TypeScript crmcrm-systemcustomergood-first-issuegraphqlhacktoberfestjavascriptmarketingmonoreponestjsopen-sourcepostgresqlreactreactjssalestypescriptweb
Fix two integration test flakes: msw passthrough EINVAL and orphaned messages (#28993)
martmull6eec3bc87af2
diff --git a/packages/twenty-server/test/integration/graphql/suites/object-generated/calendar-events.integration-spec.ts b/packages/twenty-server/test/integration/graphql/suites/object-generated/calendar-events.integration-spec.tsindex 640ab360471..d7ceac08299 100644--- a/packages/twenty-server/test/integration/graphql/suites/object-generated/calendar-events.integration-spec.ts+++ b/packages/twenty-server/test/integration/graphql/suites/object-generated/calendar-events.integration-spec.ts@@ -25,9 +25,12 @@ describe('calendarEventsResolver (e2e)', () => {expect(edges.length).toEqual(QUERY_MAX_RECORDS);- const calendarEvent = edges[0].node;+ const seededCalendarEvent = edges.find(+ (edge: { node: { id: string } }) =>+ edge.node.id === CALENDAR_EVENT_DATA_SEED_IDS.ID_1,+ )?.node;- expect(calendarEvent).toMatchSnapshot({+ expect(seededCalendarEvent).toMatchSnapshot({createdAt: expect.any(String),endsAt: expect.any(String),startsAt: expect.any(String),diff --git a/packages/twenty-server/test/integration/graphql/suites/object-generated/messages.integration-spec.ts b/packages/twenty-server/test/integration/graphql/suites/object-generated/messages.integration-spec.tsindex 1016ca7d980..ae278965d61 100644--- a/packages/twenty-server/test/integration/graphql/suites/object-generated/messages.integration-spec.ts+++ b/packages/twenty-server/test/integration/graphql/suites/object-generated/messages.integration-spec.ts@@ -25,9 +25,12 @@ describe('messagesResolver (e2e)', () => {expect(edges.length).toEqual(QUERY_MAX_RECORDS);- const message1 = edges[0].node;+ const seededMessage = edges.find(+ (edge: { node: { id: string } }) =>+ edge.node.id === MESSAGE_DATA_SEED_IDS.ID_1,+ )?.node;- expect(message1).toMatchSnapshot({+ expect(seededMessage).toMatchSnapshot({createdAt: expect.any(String),updatedAt: expect.any(String),});diff --git a/packages/twenty-server/test/integration/resend/suites/inbound-email-body-text.integration-spec.ts b/packages/twenty-server/test/integration/resend/suites/inbound-email-body-text.integration-spec.tsindex 69264b4439c..6a191a01037 100644--- a/packages/twenty-server/test/integration/resend/suites/inbound-email-body-text.integration-spec.ts+++ b/packages/twenty-server/test/integration/resend/suites/inbound-email-body-text.integration-spec.ts@@ -11,6 +11,7 @@ import { type MessageWorkspaceEntity } from 'src/modules/messaging/common/standaimport { type InboundEmailImportService } from 'src/modules/messaging/message-import-manager/drivers/inbound-email/services/inbound-email-import.service';import { updateConfigVariable } from 'test/integration/twenty-config/utils/update-config-variable.util';+import { deleteMessageChannel } from 'test/integration/utils/delete-message-channel.util';import { getAppProviderByClassName } from 'test/integration/utils/get-app-provider-by-class-name.util';import { getCoreRepository } from 'test/integration/utils/get-core-repository.util';import { setupHttpMock } from 'test/integration/utils/http-mock.util';@@ -128,9 +129,7 @@ describe('Inbound email body text (integration)', () => {}, 60000);afterAll(async () => {- await messageChannelRepository- .delete({ id: groupChannelId })- .catch(() => undefined);+ await deleteMessageChannel(groupChannelId).catch(() => undefined);});it('stores the text of an email that only has an HTML body', async () => {diff --git a/packages/twenty-server/test/integration/resend/suites/inbound-email-exclude-group-emails.integration-spec.ts b/packages/twenty-server/test/integration/resend/suites/inbound-email-exclude-group-emails.integration-spec.tsindex 1c8c266a334..06a2cc268ee 100644--- a/packages/twenty-server/test/integration/resend/suites/inbound-email-exclude-group-emails.integration-spec.ts+++ b/packages/twenty-server/test/integration/resend/suites/inbound-email-exclude-group-emails.integration-spec.ts@@ -11,6 +11,7 @@ import { type MessageWorkspaceEntity } from 'src/modules/messaging/common/standaimport { type InboundEmailImportService } from 'src/modules/messaging/message-import-manager/drivers/inbound-email/services/inbound-email-import.service';import { updateConfigVariable } from 'test/integration/twenty-config/utils/update-config-variable.util';+import { deleteMessageChannel } from 'test/integration/utils/delete-message-channel.util';import { getAppProviderByClassName } from 'test/integration/utils/get-app-provider-by-class-name.util';import { getCoreRepository } from 'test/integration/utils/get-core-repository.util';import { setupHttpMock } from 'test/integration/utils/http-mock.util';@@ -124,9 +125,7 @@ describe('Inbound email exclude group emails (integration)', () => {}, 60000);afterAll(async () => {- await messageChannelRepository- .delete({ id: groupChannelId })- .catch(() => undefined);+ await deleteMessageChannel(groupChannelId).catch(() => undefined);});it('skips an email sent from a group address', async () => {diff --git a/packages/twenty-server/test/integration/resend/suites/inbound-email-reply-threading.integration-spec.ts b/packages/twenty-server/test/integration/resend/suites/inbound-email-reply-threading.integration-spec.tsindex 3eebddf6833..65af6303a20 100644--- a/packages/twenty-server/test/integration/resend/suites/inbound-email-reply-threading.integration-spec.ts+++ b/packages/twenty-server/test/integration/resend/suites/inbound-email-reply-threading.integration-spec.ts@@ -15,6 +15,7 @@ import { type MessageWorkspaceEntity } from 'src/modules/messaging/common/standaimport { type InboundEmailImportService } from 'src/modules/messaging/message-import-manager/drivers/inbound-email/services/inbound-email-import.service';import { updateConfigVariable } from 'test/integration/twenty-config/utils/update-config-variable.util';+import { deleteMessageChannel } from 'test/integration/utils/delete-message-channel.util';import { getAppProviderByClassName } from 'test/integration/utils/get-app-provider-by-class-name.util';import { getCoreRepository } from 'test/integration/utils/get-core-repository.util';import { setupHttpMock } from 'test/integration/utils/http-mock.util';@@ -197,9 +198,7 @@ describe('Inbound email reply threading (integration)', () => {}, 60000);afterAll(async () => {- await messageChannelRepository- .delete({ id: groupChannelId })- .catch(() => undefined);+ await deleteMessageChannel(groupChannelId).catch(() => undefined);});it('joins the sent thread when the reply carries the Twenty token in References', async () => {diff --git a/packages/twenty-server/test/integration/utils/delete-message-channel.util.ts b/packages/twenty-server/test/integration/utils/delete-message-channel.util.tsnew file mode 100644index 00000000000..7e5ede957b5--- /dev/null+++ b/packages/twenty-server/test/integration/utils/delete-message-channel.util.ts@@ -0,0 +1,17 @@+import { type MessageChannelMetadataService } from 'src/engine/metadata-modules/message-channel/message-channel-metadata.service';+import { SEED_APPLE_WORKSPACE_ID } from 'src/engine/workspace-manager/dev-seeder/core/constants/seeder-workspaces.constant';++import { getAppProviderByClassName } from 'test/integration/utils/get-app-provider-by-class-name.util';+import { waitForAllJobsToFinish } from 'test/integration/utils/wait-for-all-jobs-to-finish.util';++// A raw repository delete skips the deletion event, so the channel's messages+// stay behind as orphans that later suites see masked.+export const deleteMessageChannel = async (+ messageChannelId: string,+): Promise<void> => {+ await getAppProviderByClassName<MessageChannelMetadataService>(+ 'MessageChannelMetadataService',+ ).delete({ id: messageChannelId, workspaceId: SEED_APPLE_WORKSPACE_ID });++ await waitForAllJobsToFinish();+};diff --git a/packages/twenty-server/test/integration/utils/setup-test.ts b/packages/twenty-server/test/integration/utils/setup-test.tsindex e74b44396ac..8b2ac815492 100644--- a/packages/twenty-server/test/integration/utils/setup-test.ts+++ b/packages/twenty-server/test/integration/utils/setup-test.ts@@ -1,3 +1,6 @@+import dns from 'node:dns';+import net from 'node:net';+import nodeFetch from 'node-fetch';import { type JestConfigWithTsJest } from 'ts-jest';import 'tsconfig-paths/register';@@ -23,6 +26,12 @@ const deactivateSeededCreateCompanyWorkflowVersion = async () => {};export default async (_: unknown, projectConfig: JestConfigWithTsJest) => {+ // Happy Eyeballs swaps the TCP handle under a connecting localhost socket and+ // msw's passthrough keeps the stale one (mswjs/interceptors#753): read EINVAL.+ // Resolving IPv4 first keeps localhost reachable without the fallback.+ dns.setDefaultResultOrder('ipv4first');+ net.setDefaultAutoSelectFamily(false);+// node-fetch rides node:http, which msw patches; native undici fetch// escapes interception.globalThis.fetch = nodeFetch as unknown as typeof globalThis.fetch;