Skip to content

Commit 243a3b4

Browse files
committed
♻️ Refactor: rename mockGcalEvents to mockAndCategorizeGcalEvents
1 parent 1aabdd6 commit 243a3b4

10 files changed

+25
-23
lines changed

packages/backend/src/__tests__/mocks.gcal/factories/gcal.event.factory.set.ts renamed to packages/backend/src/__tests__/mocks.gcal/factories/gcal.event.batch.ts

+6-8
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { faker } from "@faker-js/faker/.";
12
import { gSchema$EventBase } from "@core/types/gcal";
23
import {
34
generateGcalId,
@@ -6,9 +7,9 @@ import {
67
mockRegularGcalEvent,
78
} from "./gcal.event.factory";
89

9-
/* Sets of events, pre-organized as a convenience for testing */
10+
/* Batch of events, pre-organized as a convenience for testing */
1011

11-
export const mockGcalEvents = (
12+
export const mockAndCategorizeGcalEvents = (
1213
baseId?: string,
1314
fixedStart?: string,
1415
fixedEnd?: string,
@@ -18,14 +19,14 @@ export const mockGcalEvents = (
1819
const endDateTime = fixedEnd || "2025-07-16T10:56:29.000Z";
1920

2021
// Create a base recurring event
22+
const tz = faker.location.timeZone();
2123
const baseRecurringEvent = mockRecurringGcalBaseEvent({
2224
id: baseId || generateGcalId(),
2325
summary: "Recurrence",
2426
recurrence: ["RRULE:FREQ=WEEKLY"],
25-
start: { dateTime: startDateTime, timeZone: "UTC" },
26-
end: { dateTime: endDateTime, timeZone: "UTC" },
27+
start: { dateTime: startDateTime, timeZone: tz },
28+
end: { dateTime: endDateTime, timeZone: tz },
2729
}) as gSchema$EventBase;
28-
console.log("mocked base with:", baseId);
2930

3031
// Create instances of the recurring event
3132
const instances = mockRecurringGcalInstances(baseRecurringEvent, 2, 7);
@@ -45,9 +46,6 @@ export const mockGcalEvents = (
4546

4647
const all = [baseRecurringEvent, ...instances, regularEvent, cancelledEvent];
4748

48-
const instanceIds = instances.map((i) => i.id);
49-
console.log("mocked instanceIds:", instanceIds);
50-
5149
return {
5250
gcalEvents: {
5351
baseRecurringEvent,

packages/backend/src/__tests__/mocks.gcal/factories/gcal.event.factory.ts

+1
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ export const mockRecurringGcalInstances = (
104104
},
105105
};
106106
// remove properties that are reserved for the base event
107+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
107108
const { recurrence, ...instanceWithoutRecurrence } = instance;
108109
return instanceWithoutRecurrence;
109110
});

packages/backend/src/sync/services/import/sync.import.full.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ import {
44
cleanupTestMongo,
55
setupTestDb,
66
} from "@backend/__tests__/helpers/mock.db.setup";
7-
import { mockGcalEvents } from "@backend/__tests__/mocks.gcal/factories/gcal.event.factory.set";
7+
import { mockAndCategorizeGcalEvents } from "@backend/__tests__/mocks.gcal/factories/gcal.event.batch";
88
import { mockGcal } from "@backend/__tests__/mocks.gcal/factories/gcal.factory";
99
import mongoService from "@backend/common/services/mongo.service";
1010
import { createSyncImport } from "./sync.import";
1111

1212
// Mock Google Calendar API responses,
1313
jest.mock("googleapis", () => {
14-
const { gcalEvents } = mockGcalEvents();
14+
const { gcalEvents } = mockAndCategorizeGcalEvents();
1515
const googleapis = mockGcal({ events: gcalEvents.all });
1616
return googleapis;
1717
});

packages/backend/src/sync/services/import/sync.import.series.test.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import {
77
cleanupTestMongo,
88
setupTestDb,
99
} from "@backend/__tests__/helpers/mock.db.setup";
10+
import { mockAndCategorizeGcalEvents } from "@backend/__tests__/mocks.gcal/factories/gcal.event.batch";
1011
import { mockRecurringGcalBaseEvent } from "@backend/__tests__/mocks.gcal/factories/gcal.event.factory";
11-
import { mockGcalEvents } from "@backend/__tests__/mocks.gcal/factories/gcal.event.factory.set";
1212
import mongoService from "@backend/common/services/mongo.service";
1313
import { createSyncImport } from "./sync.import";
1414

@@ -17,7 +17,7 @@ jest.mock("@backend/common/services/gcal/gcal.service", () => ({
1717
__esModule: true,
1818
default: {
1919
getEventInstances: jest.fn().mockResolvedValue({
20-
data: { items: mockGcalEvents().gcalEvents.instances },
20+
data: { items: mockAndCategorizeGcalEvents().gcalEvents.instances },
2121
}),
2222
},
2323
}));
@@ -53,7 +53,8 @@ describe("SyncImport: Series", () => {
5353

5454
/* Assert */
5555
// make sure this is the same function being used in the mock at the top of this file
56-
const expectedInstances = mockGcalEvents().gcalEvents.instances.length;
56+
const expectedInstances =
57+
mockAndCategorizeGcalEvents().gcalEvents.instances.length;
5758
// validate return value
5859
expect(result.insertedCount).toEqual(1 + expectedInstances);
5960

packages/backend/src/sync/services/sync/__tests__/gcal.sync.processor.delete.test.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ import {
1717
} from "@backend/__tests__/helpers/mock.db.setup";
1818
import { simulateDbAfterGcalImport } from "@backend/__tests__/helpers/mock.events.init";
1919
import { createRecurrenceSeries } from "@backend/__tests__/mocks.db/ccal.mock.db.util";
20+
import { mockAndCategorizeGcalEvents } from "@backend/__tests__/mocks.gcal/factories/gcal.event.batch";
2021
import {
2122
mockRecurringGcalBaseEvent,
2223
mockRecurringGcalEvents,
2324
} from "@backend/__tests__/mocks.gcal/factories/gcal.event.factory";
24-
import { mockGcalEvents } from "@backend/__tests__/mocks.gcal/factories/gcal.event.factory.set";
2525
import { RecurringEventRepository } from "@backend/event/services/recur/repo/recur.event.repo";
2626
import { Change_Gcal } from "@backend/sync/sync.types";
2727
import { GcalSyncProcessor } from "../gcal.sync.processor";
@@ -38,7 +38,7 @@ jest.mock("@backend/common/services/gcal/gcal.service", () => ({
3838
// because you'll need to use the timestamp as the id as part
3939
// of the cancellation payload
4040
data: {
41-
items: mockGcalEvents(
41+
items: mockAndCategorizeGcalEvents(
4242
"ggvs54k2i7tco3vo",
4343
"2025-07-16T09:56:29.000Z",
4444
"2025-07-16T10:56:29.000Z",
@@ -130,7 +130,7 @@ describe("GcalSyncProcessor: DELETE", () => {
130130
);
131131

132132
// Also log the GCal mock instance IDs for comparison
133-
const mockInstanceIds = mockGcalEvents(
133+
const mockInstanceIds = mockAndCategorizeGcalEvents(
134134
MOCK_BASE_GCAL_ID,
135135
fixedStart,
136136
fixedEnd,

packages/backend/src/sync/services/sync/__tests__/gcal.sync.processor.upsert.base.split.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
setupTestDb,
99
} from "@backend/__tests__/helpers/mock.db.setup";
1010
import { simulateDbAfterGcalImport } from "@backend/__tests__/helpers/mock.events.init";
11-
import { mockGcalEvents } from "@backend/__tests__/mocks.gcal/factories/gcal.event.factory.set";
11+
import { mockAndCategorizeGcalEvents } from "@backend/__tests__/mocks.gcal/factories/gcal.event.batch";
1212
import { mockCancelledInstance } from "@backend/__tests__/mocks.gcal/mocks.gcal/factories/gcal.event.factory";
1313
import { RecurringEventRepository } from "@backend/event/services/recur/repo/recur.event.repo";
1414
import { GcalSyncProcessor } from "../gcal.sync.processor";
@@ -23,7 +23,7 @@ jest.mock("@backend/common/services/gcal/gcal.service", () => ({
2323
__esModule: true,
2424
default: {
2525
getEventInstances: jest.fn().mockResolvedValue({
26-
data: { items: mockGcalEvents().gcalEvents.instances },
26+
data: { items: mockAndCategorizeGcalEvents().gcalEvents.instances },
2727
}),
2828
},
2929
}));

packages/backend/src/sync/services/sync/__tests__/gcal.sync.processor.upsert.base.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import {
88
setupTestDb,
99
} from "@backend/__tests__/helpers/mock.db.setup";
1010
import { simulateDbAfterGcalImport } from "@backend/__tests__/helpers/mock.events.init";
11+
import { mockAndCategorizeGcalEvents } from "@backend/__tests__/mocks.gcal/factories/gcal.event.batch";
1112
import { mockRecurringGcalBaseEvent } from "@backend/__tests__/mocks.gcal/factories/gcal.event.factory";
12-
import { mockGcalEvents } from "@backend/__tests__/mocks.gcal/factories/gcal.event.factory.set";
1313
import { RecurringEventRepository } from "@backend/event/services/recur/repo/recur.event.repo";
1414
import { GcalSyncProcessor } from "../gcal.sync.processor";
1515
import {
@@ -25,7 +25,7 @@ jest.mock("@backend/common/services/gcal/gcal.service", () => ({
2525
__esModule: true,
2626
default: {
2727
getEventInstances: jest.fn().mockResolvedValue({
28-
data: { items: mockGcalEvents().gcalEvents.instances },
28+
data: { items: mockAndCategorizeGcalEvents().gcalEvents.instances },
2929
}),
3030
},
3131
}));

packages/backend/src/sync/services/sync/__tests__/gcal.sync.processor.upsert.standalone.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import {
77
setupTestDb,
88
} from "@backend/__tests__/helpers/mock.db.setup";
99
import { simulateDbAfterGcalImport } from "@backend/__tests__/helpers/mock.events.init";
10+
import { mockAndCategorizeGcalEvents } from "@backend/__tests__/mocks.gcal/factories/gcal.event.batch";
1011
import { mockRegularGcalEvent } from "@backend/__tests__/mocks.gcal/factories/gcal.event.factory";
11-
import { mockGcalEvents } from "@backend/__tests__/mocks.gcal/factories/gcal.event.factory.set";
1212
import { RecurringEventRepository } from "@backend/event/services/recur/repo/recur.event.repo";
1313
import { GcalSyncProcessor } from "../gcal.sync.processor";
1414

@@ -17,7 +17,7 @@ jest.mock("@backend/common/services/gcal/gcal.service", () => ({
1717
__esModule: true,
1818
default: {
1919
getEventInstances: jest.fn().mockResolvedValue({
20-
data: { items: mockGcalEvents().gcalEvents.instances },
20+
data: { items: mockAndCategorizeGcalEvents().gcalEvents.instances },
2121
}),
2222
},
2323
}));

packages/backend/src/sync/services/sync/gcal.sync.processor.ts

-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@ export class GcalSyncProcessor {
9191

9292
if (status === "CANCELLED") {
9393
logger.info(`Cancelling INSTANCE: ${gEvent.id} (Gcal)`);
94-
console.log("trying to delete via gEventId:", gEvent.id);
9594
await this.recurringEventRepo.cancelInstance(gEvent.id, {
9695
idKey: "gEventId",
9796
});

packages/core/src/util/test/ccal.event.factory.ts

+3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import dayjs from "dayjs";
2+
import timezone from "dayjs/plugin/timezone";
23
import { ObjectId } from "mongodb";
34
import { faker } from "@faker-js/faker/.";
45
import { Origin, Priorities } from "@core/constants/core.constants";
@@ -10,6 +11,8 @@ import {
1011
} from "@core/types/event.types";
1112
import { appendWithRfc5545Timestamp } from "@core/util/date/date.util";
1213

14+
dayjs.extend(timezone);
15+
1316
export const createMockStandaloneEvent = (
1417
overrides: Partial<Schema_Event> = {},
1518
): WithCompassId<Schema_Event> => {

0 commit comments

Comments
 (0)