diff --git a/apps/meteor/tests/end-to-end/api/30-calendar.ts b/apps/meteor/tests/end-to-end/api/30-calendar.ts index 73c534d98ebd7..6ea4947fa9dbf 100644 --- a/apps/meteor/tests/end-to-end/api/30-calendar.ts +++ b/apps/meteor/tests/end-to-end/api/30-calendar.ts @@ -4,7 +4,7 @@ import type { Response } from 'supertest'; import { getCredentials, api, request, credentials } from '../../data/api-data.js'; import { password } from '../../data/user'; -import { createUser, login } from '../../data/users.helper'; +import { createUser, deleteUser, login } from '../../data/users.helper'; describe('[Calendar Events]', function () { this.retries(0); @@ -19,6 +19,8 @@ describe('[Calendar Events]', function () { userCredentials = await login(user2.username, password); }); + after(() => deleteUser(user2)); + describe('[/calendar-events.create]', () => { it('should successfully create an event in the calendar', async () => { let eventId: string | undefined; @@ -155,11 +157,13 @@ describe('[Calendar Events]', function () { }); }); - after(async () => { - await request.post(api('calendar-events.delete')).set(credentials).send({ eventId }); - await request.post(api('calendar-events.delete')).set(credentials).send({ eventId: eventId2 }); - await request.post(api('calendar-events.delete')).set(userCredentials).send({ eventId: eventId3 }); - }); + after(() => + Promise.all([ + request.post(api('calendar-events.delete')).set(credentials).send({ eventId }), + request.post(api('calendar-events.delete')).set(credentials).send({ eventId: eventId2 }), + request.post(api('calendar-events.delete')).set(userCredentials).send({ eventId: eventId3 }), + ]), + ); it('should list only the events with the same date', async () => { await request @@ -233,10 +237,12 @@ describe('[Calendar Events]', function () { }); }); - after(async () => { - await request.post(api('calendar-events.delete')).set(credentials).send({ eventId }); - await request.post(api('calendar-events.delete')).set(userCredentials).send({ eventId: eventId2 }); - }); + after(() => + Promise.all([ + request.post(api('calendar-events.delete')).set(credentials).send({ eventId }), + request.post(api('calendar-events.delete')).set(userCredentials).send({ eventId: eventId2 }), + ]), + ); it('should return the event information', async () => { await request @@ -292,6 +298,14 @@ describe('[Calendar Events]', function () { }); describe('[/calendar-events.import]', () => { + const eventsToRemove: Record[] = []; + + after(() => + Promise.all([ + ...eventsToRemove.map(({ credentials, eventId }) => request.post(api('calendar-events.delete')).set(credentials).send({ eventId })), + ]), + ); + it('should successfully import an event to the calendar', async () => { let eventId: string | undefined; const externalId = `calendar-events.import-${Date.now()}`; @@ -311,11 +325,8 @@ describe('[Calendar Events]', function () { .expect((res: Response) => { expect(res.body).to.have.property('success', true); eventId = res.body.id; + eventsToRemove.push({ credentials, eventId }); }); - - after(async () => { - await request.post(api('calendar-events.delete')).set(credentials).send({ eventId }); - }); }); it('should fail to import an event without an external id', async () => { @@ -400,11 +411,6 @@ describe('[Calendar Events]', function () { let eventId2: string | undefined; const externalId = `calendar-events.import-${Date.now()}`; - after(async () => { - await request.post(api('calendar-events.delete')).set(userCredentials).send({ eventId }); - await request.post(api('calendar-events.delete')).set(credentials).send({ eventId: eventId2 }); - }); - await request .post(api('calendar-events.import')) .set(userCredentials) @@ -417,6 +423,7 @@ describe('[Calendar Events]', function () { }) .then((res) => { eventId = res.body.id; + eventsToRemove.push({ credentials: userCredentials, eventId }); }); await request @@ -435,6 +442,7 @@ describe('[Calendar Events]', function () { expect(res.body).to.have.property('success', true); expect(res.body.id).to.not.be.equal(eventId); eventId2 = res.body.id; + eventsToRemove.push({ credentials, eventId: eventId2 }); }); await request @@ -464,10 +472,6 @@ describe('[Calendar Events]', function () { let eventId: string | undefined; const externalId = `calendar-events.import-twice-${Date.now()}`; - after(async () => { - await request.post(api('calendar-events.delete')).set(credentials).send({ eventId }); - }); - await request .post(api('calendar-events.import')) .set(credentials) @@ -480,6 +484,7 @@ describe('[Calendar Events]', function () { }) .then((res) => { eventId = res.body.id; + eventsToRemove.push({ credentials, eventId }); }); await request