Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

796 backend events endpoint only include forms url at given time #799

44 changes: 41 additions & 3 deletions server/src/middleware/tests/EventController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import { Event, EventReservation } from "../../data-layer/models/firebase"
import { Timestamp } from "firebase-admin/firestore"

const earlierStartDate = Timestamp.fromDate(new Date(2023, 1, 1))
const startDate = Timestamp.fromDate(new Date(2024, 1, 1))
const startDate = Timestamp.fromDate(new Date(Date.now() + 60000)) // plus one min
const laterStartDate = Timestamp.fromDate(new Date(Date.now() + 120000)) // plus two min
const endDate = Timestamp.fromDate(new Date(2024, 1, 2))
/**
* Event with the earlier start date
Expand All @@ -18,14 +19,24 @@ const event1: Event = {
}

/**
* Event witht the later start date
* Event with the later start date
*/
const event2: Event = {
title: "Straight Zhao",
location: "UASC",
physical_start_date: startDate,
sign_up_start_date: startDate,
sign_up_end_date: endDate
sign_up_end_date: endDate,
google_forms_link: "https://random.com/event2"
}

const event3: Event = {
title: "Another Event",
location: "Krispy Kreme",
physical_start_date: laterStartDate,
sign_up_start_date: earlierStartDate,
sign_up_end_date: earlierStartDate,
google_forms_link: "https://random.com/event3"
}
const reservation1: Omit<EventReservation, "timestamp"> = {
first_name: "John",
Expand Down Expand Up @@ -62,6 +73,33 @@ describe("EventController endpoint tests", () => {
expect(res.body.data).not.toContainEqual({ ...event2, id: id2 })
expect(res.status).toEqual(200)
})

it("should include google_forms_link if event is within 1 minute", async () => {
const { id: id2 } = await eventService.createEvent(event2)

const res = await request.get("/events").send()

expect(res.body.data).toContainEqual(
expect.objectContaining({
id: id2,
google_forms_link: "https://random.com/event2"
})
)
})

it("should not include google_forms_link if event is not within 1 minute", async () => {
await eventService.createEvent(event3)

const res = await request.get("/events").send()

expect(res.body.data).toContainEqual(
expect.not.objectContaining({
google_forms_link: expect.not.stringContaining(
"https://random.com/event3"
)
AzizPatel786 marked this conversation as resolved.
Show resolved Hide resolved
})
)
})
})

describe("/events/signup", () => {
Expand Down
13 changes: 13 additions & 0 deletions server/src/service-layer/controllers/EventController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,19 @@ export class EventController extends Controller {
}

const res = await eventService.getAllEvents(limit, snapshot)
const currentTime = Timestamp.now()

res.events.forEach((event) => {
const eventStartTime = event.physical_start_date
const timeDifference =
eventStartTime.toMillis() - currentTime.toMillis()

// 1 minute (60000 milliseconds)
if (timeDifference > 60000) {
delete event.google_forms_link
}
AzizPatel786 marked this conversation as resolved.
Show resolved Hide resolved
})

return { nextCursor: res.nextCursor, data: res.events }
} catch (e) {
return {
Expand Down
Loading