Skip to content

Commit

Permalink
add tests for service
Browse files Browse the repository at this point in the history
  • Loading branch information
choden-dev committed Sep 16, 2024
1 parent 2b68f08 commit e5f210d
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions server/src/data-layer/services/EventService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit e5f210d

Please sign in to comment.