Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions packages/backend/src/event/classes/gcal.event.parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,29 @@ export class GcalEventParser {
return [...seriesChanges, ...baseChanges];
}

async instanceToStandalone(
session?: ClientSession,
): Promise<Event_Transition[]> {
const event = gEventToCompassEvent(this.#event, this.userId);

const {
recurrence, // eslint-disable-line @typescript-eslint/no-unused-vars
gRecurringEventId, // eslint-disable-line @typescript-eslint/no-unused-vars
...eventWithoutProps
} = event;

return this.upsertCompassEvent(
{
$unset: { recurrence: 1, gRecurringEventId: 1 },
$set: {
...eventWithoutProps,
updatedAt: new Date(),
},
},
session,
);
}

async standaloneToSeries(session?: ClientSession) {
this.#logger.info(
`UPDATING ${this.getTransitionString()}: ${this.#event.id} to series`,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Categories_Recurrence } from "@core/types/event.types";
import { gSchema$Event } from "@core/types/gcal";
import { UtilDriver } from "@backend/__tests__/drivers/util.driver";
import {
cleanupCollections,
Expand Down Expand Up @@ -60,6 +61,46 @@ describe("GcalSyncProcessor UPSERT: INSTANCE", () => {
expect(updatedInstance?.title).toEqual(instanceTitle);
});

it("should handle DETACHING an INSTANCE into a STANDALONE event", async () => {
const { user } = await UtilDriver.setupTestUser();

const { gcalEvents } = await simulateDbAfterGcalImport(user._id.toString());

const origInstance = gcalEvents.instances[0];

const standalone = {
...origInstance,
summary: "Detached Instance Event",
} as gSchema$Event;

delete (standalone as { recurringEventId?: string }).recurringEventId;
delete (standalone as { recurrence?: string[] }).recurrence;

const processor = new GcalSyncProcessor(user._id.toString());
const changes = await processor.processEvents([standalone]);

expect(changes).toHaveLength(1);
expect(changes).toEqual(
expect.arrayContaining([
expect.objectContaining({
title: standalone.summary,
category: Categories_Recurrence.RECURRENCE_INSTANCE,
transition: ["RECURRENCE_INSTANCE", "STANDALONE_CONFIRMED"],
operation: "RECURRENCE_INSTANCE_UPDATED",
}),
]),
);

const updatedStandalone = await mongoService.event.findOne({
gEventId: standalone.id!,
user: user._id.toString(),
});

expect(updatedStandalone).toBeDefined();
expect(updatedStandalone?.gRecurringEventId).toBeUndefined();
expect(updatedStandalone?.recurrence).toBeUndefined();
});

it("should handle UPDATING a REGULAR, BASE and TIMED INSTANCE", async () => {
const { user } = await UtilDriver.setupTestUser();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ export class GcalSyncProcessor {
return parser.createSeries(session);
case "STANDALONE->>RECURRENCE_BASE_CONFIRMED":
return parser.standaloneToSeries(session);
case "RECURRENCE_INSTANCE->>STANDALONE_CONFIRMED":
return parser.instanceToStandalone(session);
case "RECURRENCE_BASE->>STANDALONE_CONFIRMED":
return parser.seriesToStandalone(session);
case "RECURRENCE_INSTANCE->>RECURRENCE_BASE_CONFIRMED":
Expand Down
Loading