Skip to content

The open alternative to Salesforce, designed for AI.

Clean up call recordings left behind by call recorder integration tests (#28428)

nitin5d58af959b81
diff --git a/packages/twenty-apps/public/call-recorder/src/__tests__/call-recorder-lifecycle.integration-test.ts b/packages/twenty-apps/public/call-recorder/src/__tests__/call-recorder-lifecycle.integration-test.ts
index f78338895a6..ee6cb6f86ab 100644
--- a/packages/twenty-apps/public/call-recorder/src/__tests__/call-recorder-lifecycle.integration-test.ts
+++ b/packages/twenty-apps/public/call-recorder/src/__tests__/call-recorder-lifecycle.integration-test.ts
@@ -6,6 +6,7 @@ import { MetadataApiClient } from 'twenty-client-sdk/metadata';
import { enqueueJobs, getJobs } from 'twenty-sdk/logic-function';
import { isDefined } from 'twenty-sdk/utils';
import {
+ afterAll,
afterEach,
beforeAll,
beforeEach,
@@ -869,12 +870,14 @@ const waitForQueuedTriggerRunsToDrain = async () => {
scopes: ['transcript'],
});
- await expect
- .poll(() => getJobs([jobId]), {
- timeout: TRIGGER_RUN_DRAIN_TIMEOUT_MS,
- interval: 1_000,
- })
- .toMatchObject([{ jobId, state: 'COMPLETED' }]);
+ await vi.waitFor(
+ async () => {
+ expect(await getJobs([jobId])).toMatchObject([
+ { jobId, state: 'COMPLETED' },
+ ]);
+ },
+ { timeout: TRIGGER_RUN_DRAIN_TIMEOUT_MS, interval: 1_000 },
+ );
};
describe('call recorder app lifecycle (integration)', () => {
@@ -945,6 +948,42 @@ describe('call recorder app lifecycle (integration)', () => {
await destroyCreatedRows();
});
+ afterAll(async () => {
+ if (nextCalendarEventFixtureIndex === 0) {
+ return;
+ }
+
+ vi.stubEnv('TWENTY_APP_ACCESS_TOKEN', applicationAccessToken);
+
+ try {
+ await waitForQueuedTriggerRunsToDrain();
+ } finally {
+ vi.unstubAllEnvs();
+
+ const leftoverCallRecordings = await findCallRecordings({
+ calendarEventId: {
+ in: availableCalendarEventFixtures
+ .slice(0, nextCalendarEventFixtureIndex)
+ .map(({ id }) => id),
+ },
+ });
+
+ await destroyCallRecordings(leftoverCallRecordings.map(({ id }) => id));
+ }
+ }, REAL_QUEUE_TIMEOUT_MS);
+
+ const destroyCallRecordings = async (
+ callRecordingIds: string[],
+ ): Promise<void> => {
+ for (const callRecordingId of callRecordingIds) {
+ await client
+ .mutation({
+ destroyCallRecording: { __args: { id: callRecordingId }, id: true },
+ })
+ .catch(() => {});
+ }
+ };
+
const destroyCreatedRows = async (): Promise<void> => {
const calendarEventRestoreErrors: Error[] = [];
const borrowedCalendarEventIds = borrowedCalendarEventFixtures.map(
@@ -963,13 +1002,7 @@ describe('call recorder app lifecycle (integration)', () => {
]),
];
- for (const callRecordingId of callRecordingIds) {
- await client
- .mutation({
- destroyCallRecording: { __args: { id: callRecordingId }, id: true },
- })
- .catch(() => {});
- }
+ await destroyCallRecordings(callRecordingIds);
for (const fixture of borrowedCalendarEventFixtures) {
try {