Skip to content

Commit

Permalink
797 backend delete all code relating to event sign ups (#800)
Browse files Browse the repository at this point in the history
* Remove all code related to event signups

* Deleted event signup endpoint
* Deleted SSE endpoint

* Removed relevant endpoint tests

* Remove EventReservation service methods and tests

* Remove event reservations from firebase and subcollection

* Note that `Event.max_occupancy` is kept as this could still be useful.

* Also note that `FirestoreSubcollections.ts` was kept as this could be used in the future.

* Also removed the event request for signup

* Remove extra comments and generate swagger
  • Loading branch information
jeffplays2005 authored Oct 7, 2024
1 parent ea46d39 commit e275f84
Show file tree
Hide file tree
Showing 11 changed files with 6 additions and 753 deletions.
68 changes: 0 additions & 68 deletions client/src/models/__generated__/schema.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 1 addition & 6 deletions server/src/data-layer/adapters/FirestoreSubcollections.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
// credit https://plainenglish.io/blog/using-firestore-with-typescript-in-the-v9-sdk-cf36851bb099
import "dotenv/config"
import firestore from "./Firestore"
import { EventReservation } from "data-layer/models/firebase"

const FirestoreSubcollections = {
reservations: (eventId: string) =>
firestore.subcollection<EventReservation>("events", eventId, "reservations")
} as const
const FirestoreSubcollections = {} as const

export default FirestoreSubcollections
24 changes: 0 additions & 24 deletions server/src/data-layer/models/firebase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,30 +130,6 @@ export interface BookingChange {
new_check_out: Timestamp // New check-out timestamp
}

export interface EventReservation {
/**
* The first name of the user who made this event reservation
*/
first_name: string
/**
* The last name of the user who made this event reservation
*/
last_name: string
/**
* The email of the user who made this even reservation
*/
email: string
/**
* Boolean to check if the user is a member
* @example true
*/
is_member: boolean
/**
* This is the timestamp of when the reservation was made
*/
timestamp: Timestamp
}

export interface Event {
/**
* The title of this event
Expand Down
164 changes: 1 addition & 163 deletions server/src/data-layer/services/EventService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
dateToFirestoreTimeStamp,
removeUnderscoresFromTimestamp
} from "data-layer/adapters/DateUtils"
import { Event, EventReservation } from "data-layer/models/firebase"
import { Event } from "data-layer/models/firebase"
import FirestoreCollections from "data-layer/adapters/FirestoreCollections"
import { Timestamp } from "firebase-admin/firestore"

Expand Down Expand Up @@ -46,21 +46,6 @@ const futureEvent: Event = {
sign_up_end_date: Timestamp.fromDate(new Date(now.getUTCFullYear() + 1, 1, 1))
}

const reservation1: EventReservation = {
first_name: "John",
last_name: "Appleseed",
email: "[email protected]",
is_member: true,
timestamp: Timestamp.fromDate(startDate)
}
const reservation2: EventReservation = {
first_name: "Jane",
last_name: "Pearseed",
email: "[email protected]",
is_member: false,
timestamp: Timestamp.fromDate(startDate)
}

describe("EventService integration tests", () => {
afterEach(async () => {
await cleanFirestore()
Expand Down Expand Up @@ -160,151 +145,4 @@ describe("EventService integration tests", () => {

expect(fetchedEvent).toBe(undefined)
})

it("Should delete an event and also all reservations", async () => {
const newEvent = await eventService.createEvent(event1)
const newReservation1 = await eventService.addReservation(
newEvent.id,
reservation1
)
const newReservation2 = await eventService.addReservation(
newEvent.id,
reservation2
)

await eventService.deleteEvent(newEvent.id)

const fetchedReservation1 = await eventService.getReservationById(
newEvent.id,
newReservation1.id
)
expect(fetchedReservation1).toBe(undefined)
const fetchedReservation2 = await eventService.getReservationById(
newEvent.id,
newReservation2.id
)
expect(fetchedReservation2).toBe(undefined)
})

it("Should not delete other reservations when deleting an event document", async () => {
const newEvent = await eventService.createEvent(event1)
await eventService.addReservation(newEvent.id, reservation1)
await eventService.addReservation(newEvent.id, reservation2)
const newEvent2 = await eventService.createEvent(event2)
const newReservation3 = await eventService.addReservation(
newEvent2.id,
reservation1
)
const newReservation4 = await eventService.addReservation(
newEvent2.id,
reservation2
)

await eventService.deleteEvent(newEvent.id)
const fetchedReservation3 = await eventService.getReservationById(
newEvent2.id,
newReservation3.id
)
expect(fetchedReservation3).toEqual(reservation1)
const fetchedReservation4 = await eventService.getReservationById(
newEvent2.id,
newReservation4.id
)
expect(fetchedReservation4).toEqual(reservation2)
})

/**
* Event reservation nested collection methods
*/
describe("EventReservation integration tests", () => {
it("Should be able to add a event reservation", async () => {
const newEvent = await eventService.createEvent(event1)

const reservation = await eventService.addReservation(
newEvent.id,
reservation1
)
const fetchedReservation = await FirestoreCollections.events
.doc(newEvent.id)
.collection("reservations") // subject to place as a constant somewhere
.doc(reservation.id)
.get()
expect(fetchedReservation.data()).toEqual(reservation1)
})

it("Should be able to get an event reservation", async () => {
const newEvent = await eventService.createEvent(event1)
const reservation = await eventService.addReservation(
newEvent.id,
reservation1
)
const fetchedReservation = await eventService.getReservationById(
newEvent.id,
reservation.id
)
expect(fetchedReservation).toEqual(reservation1)
})

it("Should get the total count of active event reservations", async () => {
// An older event shouldn't be counted.
const oldEvent = await eventService.createEvent(event1)
await eventService.addReservation(oldEvent.id, reservation1)
// Should only count reservations for future events
const newEvent = await eventService.createEvent(futureEvent)
await eventService.addReservation(newEvent.id, reservation1)
await eventService.addReservation(newEvent.id, reservation2)

const eventCounts = await eventService.getActiveReservationsCount()
expect(eventCounts).toStrictEqual({ [newEvent.id]: 2 })
})

it("Should get all event reservations", async () => {
const newEvent = await eventService.createEvent(event1)
await eventService.addReservation(newEvent.id, reservation1)
await eventService.addReservation(newEvent.id, reservation2)
const reservations = await eventService.getAllReservations(newEvent.id)
expect(reservations.length).toBe(2)
expect(reservations).toContainEqual(reservation1)
expect(reservations).toContainEqual(reservation2)
})

it("Should be able to update an event reservation", async () => {
const newEvent = await eventService.createEvent(event1)

const reservation = await eventService.addReservation(
newEvent.id,
reservation1
)

await eventService.updateReservation(newEvent.id, reservation.id, {
first_name: "Jan"
})

const fetchedReservation = await FirestoreCollections.events
.doc(newEvent.id)
.collection("reservations") // subject to place as a constant somewhere
.doc(reservation.id)
.get()

expect(fetchedReservation.data().first_name).toBe("Jan")
})

it("Should be able to delete an event reservation", async () => {
const newEvent = await eventService.createEvent(event1)

const reservation = await eventService.addReservation(
newEvent.id,
reservation1
)

await eventService.deleteReservation(newEvent.id, reservation.id)

const fetchedReservation = await FirestoreCollections.events
.doc(newEvent.id)
.collection("reservations") // subject to place as a constant somewhere
.doc(reservation.id)
.get()
expect(fetchedReservation.data()).toBe(undefined)
})
})
})
Loading

0 comments on commit e275f84

Please sign in to comment.