From e5f210dbc692129bd501ddaa742d5290ee01b4c4 Mon Sep 17 00:00:00 2001 From: bcho892 Date: Mon, 16 Sep 2024 12:56:36 +1200 Subject: [PATCH] add tests for service --- .../data-layer/services/EventService.test.ts | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/server/src/data-layer/services/EventService.test.ts b/server/src/data-layer/services/EventService.test.ts index a2363966..11bc95f0 100644 --- a/server/src/data-layer/services/EventService.test.ts +++ b/server/src/data-layer/services/EventService.test.ts @@ -13,6 +13,8 @@ const eventService = new EventService() const startDate = dateToFirestoreTimeStamp(new Date(2024, 1, 1)) const endDate = dateToFirestoreTimeStamp(new Date(2024, 1, 2)) +const laterStartDate = dateToFirestoreTimeStamp(new Date(2024, 2, 2)) + const event1: Event = { title: "UASC new event", description: "Grand opening of the website.", @@ -58,6 +60,33 @@ describe("EventService integration tests", () => { await cleanFirestore() }) + it("Should be able to fetch the latest X events (based on when the event actually starts), descending", async () => { + const { id: idEarly } = await eventService.createEvent(event1) + const { id: idLater } = await eventService.createEvent({ + ...event1, + physical_start_date: laterStartDate + }) + + const page1Events = await eventService.getAllEvents(1) + expect(page1Events.events).toHaveLength(1) + expect( + page1Events.events.some((event) => event.id === idLater) + ).toBeTruthy() + + expect(page1Events.nextCursor).toBeDefined() + + let snapshot + if (page1Events.nextCursor) { + snapshot = await eventService.getEventSnapshot(page1Events.nextCursor) + } + + const page2Events = await eventService.getAllEvents(1, snapshot) + expect(page2Events.events).toHaveLength(1) + expect( + page2Events.events.some((event) => event.id === idEarly) + ).toBeTruthy() + }) + it("Should be able to add an event", async () => { const newEvent = await eventService.createEvent(event1)