The open alternative to Salesforce, designed for AI.
TypeScript crmcrm-systemcustomergood-first-issuegraphqlhacktoberfestjavascriptmarketingmonoreponestjsopen-sourcepostgresqlreactreactjssalestypescriptweb
Stop chat specs from waiting out every snooze between tests (#29603)
Charles Bocheteca50ce59848
diff --git a/packages/twenty-server/test/integration/graphql/suites/chat-channel/utils/chat-channel-test.util.ts b/packages/twenty-server/test/integration/graphql/suites/chat-channel/utils/chat-channel-test.util.tsindex 45faaef04db..4b998b29279 100644--- a/packages/twenty-server/test/integration/graphql/suites/chat-channel/utils/chat-channel-test.util.ts+++ b/packages/twenty-server/test/integration/graphql/suites/chat-channel/utils/chat-channel-test.util.ts@@ -9,6 +9,7 @@ import { findOneRoleByLabel } from 'test/integration/metadata/suites/role/utils/import { updateOneRole } from 'test/integration/metadata/suites/role/utils/update-one-role.util';import { makeMetadataApiRequest } from 'test/integration/metadata/suites/utils/make-metadata-api-request.util';import { destroyAgentChatThread } from 'test/integration/utils/destroy-agent-chat-thread.util';+import { removeAgentChatSnoozeEndJobs } from 'test/integration/utils/remove-agent-chat-snooze-end-jobs.util';import { expectEventually } from 'test/integration/utils/expect-eventually.util';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';@@ -554,6 +555,7 @@ export const setUpChatChannelTests = () => {afterEach(async () => {jest.restoreAllMocks();+ await removeAgentChatSnoozeEndJobs({ threadIds: createdThreadIds });const orphanedThreadCount =await countThreadsInDeletedChannels(createdChannelIds);diff --git a/packages/twenty-server/test/integration/graphql/suites/chat-thread-participant/chat-thread-participant-mentions.integration-spec.ts b/packages/twenty-server/test/integration/graphql/suites/chat-thread-participant/chat-thread-participant-mentions.integration-spec.tsindex 71fe4877332..0991e5edc18 100644--- a/packages/twenty-server/test/integration/graphql/suites/chat-thread-participant/chat-thread-participant-mentions.integration-spec.ts+++ b/packages/twenty-server/test/integration/graphql/suites/chat-thread-participant/chat-thread-participant-mentions.integration-spec.ts@@ -94,27 +94,6 @@ describe('Chat thread participant mentions through the authenticated API', () =>expect(await findOpenThreadsSummary()).toEqual(before);});- it('follows a chat the member files as done, so new activity brings it back', async () => {- const threadId = await createTestThread();-- await setShareWithJony(threadId, true);- await runInboxAction('READ', threadId, {- token: APPLE_JONY_MEMBER_ACCESS_TOKEN,- });-- expect(- await findMyParticipant(threadId, APPLE_JONY_MEMBER_ACCESS_TOKEN),- ).toMatchObject({ isSubscribed: false, archivedAt: null });-- await runInboxAction('ARCHIVE', threadId, {- token: APPLE_JONY_MEMBER_ACCESS_TOKEN,- });-- expect(- await findMyParticipant(threadId, APPLE_JONY_MEMBER_ACCESS_TOKEN),- ).toMatchObject({ isSubscribed: true, archivedAt: expect.any(String) });- });-it('flags the open chats the member was mentioned in or assigned that are unread', async () => {const initialSummary = await findOpenThreadsSummary();const mentionedThreadId = await createTestThread();diff --git a/packages/twenty-server/test/integration/graphql/suites/chat-thread-participant/chat-thread-participant-sharing-and-assignment.integration-spec.ts b/packages/twenty-server/test/integration/graphql/suites/chat-thread-participant/chat-thread-participant-sharing-and-assignment.integration-spec.tsindex 094c26d5c84..7c4348f89a5 100644--- a/packages/twenty-server/test/integration/graphql/suites/chat-thread-participant/chat-thread-participant-sharing-and-assignment.integration-spec.ts+++ b/packages/twenty-server/test/integration/graphql/suites/chat-thread-participant/chat-thread-participant-sharing-and-assignment.integration-spec.ts@@ -353,15 +353,6 @@ describe('Chat thread participant sharing, subscription and assignment through t);});- it('refuses to change the subscription of a member who cannot read the chat', async () => {- const threadId = await createTestThread();- const response = await runInboxAction('UNSUBSCRIBE', threadId, {- token: APPLE_JONY_MEMBER_ACCESS_TOKEN,- });-- expect(response.body.errors[0].extensions.code).toBe('NOT_FOUND');- });-it('assigns a chat to a member who could not read it, who then finds it unread in their inbox', async () => {const threadId = await createTestThread();const response = await assign(diff --git a/packages/twenty-server/test/integration/graphql/suites/chat-thread-participant/utils/chat-thread-participant-test.util.ts b/packages/twenty-server/test/integration/graphql/suites/chat-thread-participant/utils/chat-thread-participant-test.util.tsindex 749184f22de..4c854d07275 100644--- a/packages/twenty-server/test/integration/graphql/suites/chat-thread-participant/utils/chat-thread-participant-test.util.ts+++ b/packages/twenty-server/test/integration/graphql/suites/chat-thread-participant/utils/chat-thread-participant-test.util.ts@@ -15,6 +15,7 @@ import { findManyOperationFactory } from 'test/integration/graphql/utils/find-maimport { makeGraphqlApiRequest } from 'test/integration/graphql/utils/make-graphql-api-request.util';import { makeMetadataApiRequest } from 'test/integration/metadata/suites/utils/make-metadata-api-request.util';import { destroyAgentChatThread } from 'test/integration/utils/destroy-agent-chat-thread.util';+import { removeAgentChatSnoozeEndJobs } from 'test/integration/utils/remove-agent-chat-snooze-end-jobs.util';import { getAppProviderByClassName } from 'test/integration/utils/get-app-provider-by-class-name.util';import { setManualRecordShare } from 'test/integration/utils/set-manual-record-share.util';import { type AgentChatThreadService } from 'src/engine/metadata-modules/ai/ai-chat/services/agent-chat-thread.service';@@ -337,6 +338,7 @@ export const setUpChatThreadParticipantTests = () => {afterEach(async () => {jest.restoreAllMocks();+ await removeAgentChatSnoozeEndJobs({ threadIds: createdThreadIds });for (const manualShare of enabledManualShares.splice(0)) {await setShareWithMember({ ...manualShare, enabled: false });diff --git a/packages/twenty-server/test/integration/utils/remove-agent-chat-snooze-end-jobs.util.ts b/packages/twenty-server/test/integration/utils/remove-agent-chat-snooze-end-jobs.util.tsnew file mode 100644index 00000000000..478e0f0e40c--- /dev/null+++ b/packages/twenty-server/test/integration/utils/remove-agent-chat-snooze-end-jobs.util.ts@@ -0,0 +1,24 @@+import { removeDelayedJobs } from 'test/integration/utils/wait-for-all-jobs-to-finish.util';++import { MessageQueue } from 'src/engine/core-modules/message-queue/message-queue.constants';+import { END_AGENT_CHAT_CHANNEL_SNOOZE_JOB_NAME } from 'src/engine/metadata-modules/ai/ai-chat/jobs/end-agent-chat-channel-snooze-job-name.constant';+import { END_AGENT_CHAT_THREAD_SNOOZE_JOB_NAME } from 'src/engine/metadata-modules/ai/ai-chat/jobs/end-agent-chat-thread-snooze-job-name.constant';++const SNOOZE_END_JOB_NAMES = [+ END_AGENT_CHAT_THREAD_SNOOZE_JOB_NAME,+ END_AGENT_CHAT_CHANNEL_SNOOZE_JOB_NAME,+];++// A snooze end reschedules itself until the database clock reaches it, so the+// job drain between tests would otherwise wait out every snooze a test left+export const removeAgentChatSnoozeEndJobs = ({+ threadIds,+}: {+ threadIds: string[];+}) =>+ removeDelayedJobs({+ queueName: MessageQueue.delayedJobsQueue,+ shouldRemove: (job) =>+ SNOOZE_END_JOB_NAMES.includes(job.name) &&+ threadIds.includes(job.data?.threadId),+ });diff --git a/packages/twenty-server/test/integration/utils/wait-for-all-jobs-to-finish.util.ts b/packages/twenty-server/test/integration/utils/wait-for-all-jobs-to-finish.util.tsindex 0ddd502ae88..9de6469a386 100644--- a/packages/twenty-server/test/integration/utils/wait-for-all-jobs-to-finish.util.ts+++ b/packages/twenty-server/test/integration/utils/wait-for-all-jobs-to-finish.util.ts@@ -1,4 +1,4 @@-import { Queue } from 'bullmq';+import { type Job, Queue } from 'bullmq';import IORedis from 'ioredis';import { MessageQueue } from 'src/engine/core-modules/message-queue/message-queue.constants';@@ -221,6 +221,35 @@ export const waitForAllJobsToFinish = async (): Promise<void> => {global.jobDrainState.lastStalledFingerprint = null;};+export const removeDelayedJobs = async ({+ queueName,+ shouldRemove,+}: {+ queueName: MessageQueue;+ shouldRemove: (job: Job) => boolean;+}): Promise<void> => {+ const queue = getQueues().find(({ name }) => name === queueName);++ if (!queue) {+ return;+ }++ const delayedJobs = await queue.getDelayed();++ await Promise.all(+ delayedJobs.filter(shouldRemove).map(async (job) => {+ try {+ await job.remove();+ } catch (error) {+ // Promoted or removed since it was listed+ if (await job.isDelayed()) {+ throw error;+ }+ }+ }),+ );+};+export const closeQueueConnections = async (): Promise<void> => {if (queues) {await Promise.allSettled(queues.map((queue) => queue.close()));