Skip to content

Commit dfe1958

Browse files
🐛 fix(calendar-event-transiton): calendar event to someday fix (#973)
1 parent 57ee145 commit dfe1958

34 files changed

+723
-505
lines changed

jest.config.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,9 @@ module.exports = {
102102
testEnvironment: "node",
103103
testMatch: ["<rootDir>/packages/core/**/?(*.)+(spec|test).[tj]s?(x)"],
104104
setupFiles: ["<rootDir>/packages/core/src/__tests__/core.test.init.ts"],
105+
setupFilesAfterEnv: [
106+
"<rootDir>/packages/core/src/__tests__/core.test.start.ts",
107+
],
105108
},
106109
{
107110
displayName: "web",

packages/core/src/__mocks__/v1/events/events.misc.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
1+
import { ObjectId } from "bson";
12
import { Origin, Priorities } from "@core/constants/core.constants";
23
import { Schema_Event } from "@core/types/event.types";
34

45
/**
56
* Assortment of events with no direct relation to another
67
*/
78

8-
const USER = "6227e1a1623abad10d70afbf";
9+
const USER = new ObjectId().toString();
910

1011
export const CHILL_ALL_DAY: Schema_Event = {
11-
_id: "620c177bfadfdec705cdd69c",
12+
_id: new ObjectId().toString(),
1213
gEventId: "6csjad336cs3ibb469imcb9kc9gj6bb26ss30bb56kojgoj464o66ohh60",
1314
user: USER,
1415
origin: Origin.GOOGLE_IMPORT,
@@ -20,7 +21,7 @@ export const CHILL_ALL_DAY: Schema_Event = {
2021
endDate: "2022-09-24",
2122
};
2223
export const CLIMB: Schema_Event = {
23-
_id: "62322b127837957382660217",
24+
_id: new ObjectId().toString(),
2425
gEventId: "ccq34eb261j3ab9jckpj6b9kcos6cbb26pi38b9pc5i64e9mcgp3ao9p6o",
2526
user: USER,
2627
origin: Origin.GOOGLE_IMPORT,
@@ -32,7 +33,7 @@ export const CLIMB: Schema_Event = {
3233
endDate: "2022-03-01T19:00:00-06:00",
3334
};
3435
export const EUROPE_TRIP: Schema_Event = {
35-
_id: "6262d2840138892cb743444a",
36+
_id: new ObjectId().toString(),
3637
user: USER,
3738
origin: Origin.COMPASS,
3839
title: "Europe Trip",
@@ -44,7 +45,7 @@ export const EUROPE_TRIP: Schema_Event = {
4445
order: 2,
4546
};
4647
export const LEARN_CHINESE: Schema_Event = {
47-
_id: "awk92akknm",
48+
_id: new ObjectId().toString(),
4849
description: "",
4950
isSomeday: true,
5051
origin: Origin.COMPASS,
@@ -56,7 +57,7 @@ export const LEARN_CHINESE: Schema_Event = {
5657
order: 1,
5758
};
5859
export const MARCH_1: Schema_Event = {
59-
_id: "62322b127837957382660212",
60+
_id: new ObjectId().toString(),
6061
gEventId: "2ip0l4k0kqhg22cagtmrlml5mn",
6162
user: USER,
6263
origin: Origin.GOOGLE_IMPORT,
@@ -68,7 +69,7 @@ export const MARCH_1: Schema_Event = {
6869
endDate: "2022-03-02",
6970
};
7071
export const GROCERIES: Schema_Event = {
71-
_id: "620c177bfadfdec705cdd70a",
72+
_id: new ObjectId().toString(),
7273
gEventId: "pihjll1k75s1g9019ru6tkb97c",
7374
user: USER,
7475
origin: Origin.GOOGLE_IMPORT,
@@ -80,7 +81,7 @@ export const GROCERIES: Schema_Event = {
8081
endDate: "2022-02-21T12:45:00-06:00",
8182
};
8283
export const MULTI_WEEK: Schema_Event = {
83-
_id: "62322b12783795738266022e",
84+
_id: new ObjectId().toString(),
8485
gEventId: "1k2rgneltn79cbchccut08alqs",
8586
user: USER,
8687
origin: Origin.GOOGLE_IMPORT,
@@ -93,7 +94,7 @@ export const MULTI_WEEK: Schema_Event = {
9394
endDate: "2022-09-22T00:00:00-06:00",
9495
};
9596
export const TY_TIM: Schema_Event = {
96-
_id: "62322b127837957382660231",
97+
_id: new ObjectId().toString(),
9798
gEventId: "726v6dgnasekgmv5hc1jifpumm",
9899
user: USER,
99100
origin: Origin.GOOGLE_IMPORT,
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { mockBSON } from "@core/__tests__/mock.setup";
2+
3+
mockBSON();
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { faker as mockFaker } from "@faker-js/faker";
2+
3+
export const mockBSON = () => {
4+
jest.mock("bson", () => ({
5+
ObjectId: class ObjectId {
6+
#value: string;
7+
8+
constructor(value?: string) {
9+
if (value && !ObjectId.isValid(value)) {
10+
throw new Error("Invalid ObjectId");
11+
}
12+
13+
this.#value = value ?? mockFaker.database.mongodbObjectId();
14+
}
15+
16+
toString() {
17+
return this.#value;
18+
}
19+
20+
static isValid(value?: string) {
21+
return /^[a-fA-F0-9]{24}$/.test(value ?? "");
22+
}
23+
},
24+
}));
25+
};

packages/core/src/types/event.types.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { ObjectId } from "bson";
1+
import { ObjectId } from "bson";
22
import type { Query } from "express-serve-static-core";
33
import { z } from "zod";
44
import {
@@ -150,13 +150,17 @@ export enum CompassEventStatus {
150150
CANCELLED = "CANCELLED",
151151
}
152152

153+
export const idSchema = z.string().refine(ObjectId.isValid, {
154+
message: "Invalid id",
155+
});
156+
153157
export const eventDateSchema = z.union([
154158
z.string().datetime({ offset: true }),
155159
z.string().date(),
156160
]);
157161

158162
export const CoreEventSchema = z.object({
159-
_id: z.string().optional(),
163+
_id: idSchema.optional(),
160164
description: z.string().nullable().optional(),
161165
endDate: eventDateSchema,
162166
isAllDay: z.boolean().optional(),
@@ -195,14 +199,18 @@ export const EventUpdateSchema = z.object({
195199
export const CompassCoreEventSchema = CoreEventSchema.omit({
196200
recurrence: true,
197201
}).extend({
198-
_id: z.string(),
202+
_id: idSchema,
199203
recurrence: CompassEventRecurrence.omit({ rule: true })
200204
.extend({
201205
rule: z.union([z.null(), z.array(z.string())]),
202206
})
203207
.optional(),
204208
});
205209

210+
export const CompassCoreCalendarEventSchema = CompassCoreEventSchema.extend({
211+
isSomeday: z.literal(false),
212+
});
213+
206214
const BaseCompassEventSchema = z.object({
207215
status: z
208216
.nativeEnum(CompassEventStatus)

packages/web/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@
4444
"redux": "^4.1.1",
4545
"redux-saga": "^1.1.3",
4646
"regenerator-runtime": "^0.14.1",
47-
"reselect": "^4.0.0",
4847
"sass-loader": "^13.2.0",
4948
"socket.io-client": "^4.7.5",
5049
"style-loader": "^3.2.1",
@@ -81,6 +80,7 @@
8180
"eslint-plugin-react": "^7.28.0",
8281
"eslint-plugin-react-hooks": "^5.1.0",
8382
"eslint-plugin-testing-library": "^5.0.5",
83+
"@faker-js/faker": "^9.6.0",
8484
"jest": "^29.0.3",
8585
"jest-environment-jsdom": "^29.7.0",
8686
"jest-styled-components": "^7.0.5",

packages/web/src/__tests__/Calendar/calendar.interactions.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { CalendarView } from "@web/views/Calendar";
1010

1111
it("displays alert upon server error", async () => {
1212
server.use(
13-
rest.get(`${ENV_WEB.API_BASEURL}/event`, (req, res, ctx) => {
13+
rest.get(`${ENV_WEB.API_BASEURL}/event`, (_req, res, ctx) => {
1414
return res(
1515
ctx.status(500),
1616
ctx.json({

packages/web/src/__tests__/__mocks__/server/mock.handlers.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { ObjectId } from "bson";
12
import { rest } from "msw";
23
import {
34
CLIMB,
@@ -17,7 +18,7 @@ export const globalHandlers = [
1718
return res(
1819
ctx.json([
1920
{
20-
_id: "somedayFoo",
21+
_id: new ObjectId().toString(),
2122
description: "somesomesome",
2223
isSomeday: true,
2324
origin: "compass",

packages/web/src/__tests__/utils/test.util.ts

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,3 @@ export const mockResizeObserver = () => {
3434
export const mockScroll = () => {
3535
window.HTMLElement.prototype.scroll = jest.fn();
3636
};
37-
38-
export const mockBSON = () => {
39-
jest.mock("bson", () => ({
40-
ObjectId: class ObjectId {
41-
toString() {
42-
return crypto.randomUUID();
43-
}
44-
45-
static isValid(value?: string) {
46-
return value?.length === 36;
47-
}
48-
},
49-
}));
50-
};
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
1+
import { mockBSON } from "@core/__tests__/mock.setup";
2+
13
process.env.API_BASEURL = "http://localhost:3000/api";
24
process.env.GOOGLE_CLIENT_ID = "mockedClientId";
5+
6+
mockBSON();

0 commit comments

Comments
 (0)