-
Notifications
You must be signed in to change notification settings - Fork 70
Expand file tree
/
Copy pathmap.event.test.ts
More file actions
97 lines (86 loc) · 2.85 KB
/
Copy pathmap.event.test.ts
File metadata and controls
97 lines (86 loc) · 2.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import { ObjectId } from "bson";
import { Origin, Priorities } from "@core/constants/core.constants";
import { MapEvent } from "@core/mappers/map.event";
import { Categories_Event, type Schema_Event } from "@core/types/event.types";
import {
createMockBaseEvent,
createMockInstance,
} from "@core/util/test/ccal.event.factory";
describe("MapEvent.removeProviderData", () => {
it("removes gEventId from a base event", () => {
const _id = new ObjectId().toString();
const event = createMockBaseEvent({ _id, gEventId: _id });
const result = MapEvent.removeProviderData(event);
expect((result as Schema_Event).gEventId).toBeUndefined();
});
it("removes gEventId, gRecurringEventId and recurrence eventId from an instance event", () => {
const _id = new ObjectId().toString();
const event = createMockInstance(_id, _id);
const result = MapEvent.removeProviderData(event);
expect((result as Schema_Event).gEventId).toBeUndefined();
expect((result as Schema_Event).gRecurringEventId).toBeUndefined();
expect((result as Schema_Event).recurrence?.eventId).toBeUndefined();
});
});
describe("MapEvent.toSomeday", () => {
const baseEvent: Schema_Event = {
_id: "event-1",
title: "Grid event",
startDate: "2024-03-19T10:00:00.000Z",
endDate: "2024-03-19T11:00:00.000Z",
isAllDay: false,
isSomeday: false,
origin: Origin.COMPASS,
priority: Priorities.WORK,
user: "user-1",
};
it("maps a calendar event into a someday payload with the given dates", () => {
const result = MapEvent.toSomeday(baseEvent, {
category: Categories_Event.SOMEDAY_WEEK,
endDate: "2024-03-23",
order: 2,
startDate: "2024-03-17",
});
expect(result).toEqual(
expect.objectContaining({
_id: "event-1",
endDate: "2024-03-23",
isAllDay: false,
isSomeday: true,
order: 2,
priority: Priorities.WORK,
startDate: "2024-03-17",
title: "Grid event",
}),
);
});
it("rewrites the recurrence FREQ for the destination list", () => {
const result = MapEvent.toSomeday(
{ ...baseEvent, recurrence: { rule: ["RRULE:FREQ=DAILY;COUNT=5"] } },
{
category: Categories_Event.SOMEDAY_MONTH,
endDate: "2024-03-31",
order: 0,
startDate: "2024-03-01",
},
);
expect(result.recurrence?.rule).toEqual(["RRULE:FREQ=MONTHLY;COUNT=5"]);
});
it("defaults missing priority and user", () => {
const result = MapEvent.toSomeday(
{
...baseEvent,
priority: undefined,
user: undefined as unknown as string,
},
{
category: Categories_Event.SOMEDAY_WEEK,
endDate: "2024-03-23",
order: 0,
startDate: "2024-03-17",
},
);
expect(result.priority).toBe(Priorities.UNASSIGNED);
expect(result.user).toBe("");
});
});