Skip to content

Commit f478413

Browse files
committed
🐛 fix(recurring-events): refine event recurrence handling and update related tests
1 parent 5a02317 commit f478413

File tree

8 files changed

+356
-377
lines changed

8 files changed

+356
-377
lines changed

packages/backend/src/event/classes/compass.event.generator.ts

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ import {
2020
isBase,
2121
parseCompassEventDate,
2222
} from "@core/util/event/event.util";
23+
import { GenericError } from "@backend/common/errors/generic/generic.errors";
24+
import { error } from "@backend/common/errors/handlers/error.handler";
2325
import mongoService from "@backend/common/services/mongo.service";
24-
import { GenericError } from "../../common/errors/generic/generic.errors";
25-
import { error } from "../../common/errors/handlers/error.handler";
2626

2727
export class CompassEventFactory {
2828
private static async findCompassEvent(
@@ -209,10 +209,7 @@ export class CompassEventFactory {
209209
const payload = event.payload as Schema_Event;
210210
const hasRRule = Array.isArray(payload.recurrence?.rule);
211211
const hasRecurringBase = !!payload.recurrence?.eventId;
212-
const isSomeday = payload.isSomeday;
213212
const nullRecurrence = payload.recurrence?.rule === null;
214-
const baseToStandaloneTransition = nullRecurrence && hasRecurringBase;
215-
const baseToSomedayTransition = isSomeday && hasRecurringBase;
216213

217214
const dbEvent = await CompassEventFactory.findCompassEvent(
218215
event.payload._id,
@@ -228,16 +225,7 @@ export class CompassEventFactory {
228225
);
229226
}
230227

231-
if (baseToStandaloneTransition || baseToSomedayTransition) {
232-
return CompassEventFactory.genAllEvents(
233-
{
234-
...event,
235-
applyTo: RecurringEventUpdateScope.ALL_EVENTS,
236-
} as CompassAllEvents,
237-
session,
238-
);
239-
}
240-
228+
if (nullRecurrence) delete payload.recurrence?.rule;
241229
if (hasRRule && hasRecurringBase) delete payload.recurrence?.rule;
242230
if (nullRecurrence && !hasRecurringBase) delete payload.recurrence;
243231

packages/backend/src/event/controllers/event.controller.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
CompassCoreEventSchema,
88
CompassEvent,
99
CompassEventStatus,
10+
CompassThisEvent,
1011
Params_DeleteMany,
1112
Payload_Order,
1213
RecurringEventUpdateScope,
@@ -70,7 +71,7 @@ class EventController {
7071

7172
await this.processEvents([
7273
{
73-
payload: event as CompassEvent["payload"],
74+
payload: event as CompassThisEvent["payload"],
7475
status: CompassEventStatus.CANCELLED,
7576
applyTo: applyTo as RecurringEventUpdateScope.THIS_EVENT,
7677
},
@@ -141,7 +142,7 @@ class EventController {
141142
const { body, query, params, session } = req;
142143
const user = session?.getUserId() as string;
143144
const _id = params["id"] as string;
144-
const payload = { ...body, user, _id } as CompassEvent["payload"];
145+
const payload = { ...body, user, _id } as CompassThisEvent["payload"];
145146
const applyTo = query["applyTo"] as RecurringEventUpdateScope.THIS_EVENT;
146147

147148
await this.processEvents([

packages/backend/src/sync/services/sync/__tests__/compass-sync-processor-this-event/base.test.ts

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
cleanupTestDb,
1818
setupTestDb,
1919
} from "@backend/__tests__/helpers/mock.db.setup";
20+
import { GenericError } from "@backend/common/errors/generic/generic.errors";
2021
import {
2122
testCompassEventNotInGcal,
2223
testCompassSeries,
@@ -167,9 +168,7 @@ describe.each([{ calendarProvider: CalendarProvider.GOOGLE }])(
167168
status: CompassEventStatus.CONFIRMED,
168169
},
169170
]),
170-
).rejects.toThrow(
171-
`You cannot edit a base event with this option(${RecurringEventUpdateScope.THIS_EVENT})`,
172-
);
171+
).rejects.toThrow(GenericError.BadRequest.description);
173172
});
174173

175174
it("should not directly update the description field of a base event", async () => {
@@ -221,9 +220,7 @@ describe.each([{ calendarProvider: CalendarProvider.GOOGLE }])(
221220
status: CompassEventStatus.CONFIRMED,
222221
},
223222
]),
224-
).rejects.toThrow(
225-
`You cannot edit a base event with this option(${RecurringEventUpdateScope.THIS_EVENT})`,
226-
);
223+
).rejects.toThrow(GenericError.BadRequest.description);
227224
});
228225

229226
it("should not directly update the priority field of a base event", async () => {
@@ -277,9 +274,7 @@ describe.each([{ calendarProvider: CalendarProvider.GOOGLE }])(
277274
status: CompassEventStatus.CONFIRMED,
278275
},
279276
]),
280-
).rejects.toThrow(
281-
`You cannot edit a base event with this option(${RecurringEventUpdateScope.THIS_EVENT})`,
282-
);
277+
).rejects.toThrow(GenericError.BadRequest.description);
283278
});
284279

285280
it("should directly update the startDate field of a base event", async () => {
@@ -333,9 +328,7 @@ describe.each([{ calendarProvider: CalendarProvider.GOOGLE }])(
333328
status: CompassEventStatus.CONFIRMED,
334329
},
335330
]),
336-
).rejects.toThrow(
337-
`You cannot edit a base event with this option(${RecurringEventUpdateScope.THIS_EVENT})`,
338-
);
331+
).rejects.toThrow(GenericError.BadRequest.description);
339332
});
340333

341334
it("should directly update the endDate field of a base event", async () => {
@@ -389,9 +382,7 @@ describe.each([{ calendarProvider: CalendarProvider.GOOGLE }])(
389382
status: CompassEventStatus.CONFIRMED,
390383
},
391384
]),
392-
).rejects.toThrow(
393-
`You cannot edit a base event with this option(${RecurringEventUpdateScope.THIS_EVENT})`,
394-
);
385+
).rejects.toThrow(GenericError.BadRequest.description);
395386
});
396387

397388
it("should directly update the recurrence field of a base event", async () => {
@@ -445,9 +436,7 @@ describe.each([{ calendarProvider: CalendarProvider.GOOGLE }])(
445436
status: CompassEventStatus.CONFIRMED,
446437
},
447438
]),
448-
).rejects.toThrow(
449-
`You cannot edit a base event with this option(${RecurringEventUpdateScope.THIS_EVENT})`,
450-
);
439+
).rejects.toThrow(GenericError.BadRequest.description);
451440
});
452441
});
453442
});
@@ -503,9 +492,7 @@ describe.each([{ calendarProvider: CalendarProvider.GOOGLE }])(
503492
status: CompassEventStatus.CANCELLED,
504493
},
505494
]),
506-
).rejects.toThrow(
507-
`You cannot edit a base event with this option(${RecurringEventUpdateScope.THIS_EVENT})`,
508-
);
495+
).rejects.toThrow(GenericError.BadRequest.description);
509496
},
510497
);
511498
});

0 commit comments

Comments
 (0)