Skip to content

Commit

Permalink
add basic tests
Browse files Browse the repository at this point in the history
  • Loading branch information
choden-dev committed Aug 2, 2024
1 parent 977d819 commit e97a107
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 9 deletions.
67 changes: 66 additions & 1 deletion server/src/data-layer/services/BookingHistoryService.test.ts
Original file line number Diff line number Diff line change
@@ -1 +1,66 @@
describe("BookingHistoryService integration tests", () => {})
import { dateToFirestoreTimeStamp } from "data-layer/adapters/DateUtils"
import BookingHistoryService from "./BookingHistoryService"
import { Timestamp } from "firebase-admin/firestore"
import db from "data-layer/adapters/FirestoreCollections"
import { cleanFirestore } from "test-config/TestUtils"

const bookingHistoryService = new BookingHistoryService()
describe("BookingHistoryService integration tests", () => {
afterEach(async () => {
await cleanFirestore()
})

it("Should be able to add an event for deleted bookings", async () => {
const startDate = dateToFirestoreTimeStamp(new Date(2002, 10, 8))
const endDate = dateToFirestoreTimeStamp(new Date(2002, 10, 10))
const currentTime = dateToFirestoreTimeStamp(new Date())

const newEvent = await bookingHistoryService.addBookingDeletedEvent({
uid: "user-removed-from-booking",
start_date: startDate as Timestamp,
end_date: endDate as Timestamp,
event_type: "removed_user_from_booking",
timestamp: currentTime
})

const result = db.bookingHistory.doc("user-removed-from-booking").get()

expect(result).toEqual(newEvent)
})

it("Should be able to add an event for created bookings", async () => {
const startDate = dateToFirestoreTimeStamp(new Date(2002, 10, 8))
const endDate = dateToFirestoreTimeStamp(new Date(2002, 10, 10))
const currentTime = dateToFirestoreTimeStamp(new Date())

const newEvent = await bookingHistoryService.addBookingAddedEvent({
uid: "user-added-to-booking",
start_date: startDate as Timestamp,
end_date: endDate as Timestamp,
event_type: "added_user_to_booking",
timestamp: currentTime
})

const result = db.bookingHistory.doc("user-added-to-booking").get()

expect(result).toEqual(newEvent)
})

it("Should be able to add an event for availability changes", async () => {
const startDate = dateToFirestoreTimeStamp(new Date(2002, 10, 8))
const endDate = dateToFirestoreTimeStamp(new Date(2002, 10, 10))
const currentTime = dateToFirestoreTimeStamp(new Date())

const newEvent = await bookingHistoryService.addAvailibilityChangeEvent({
start_date: startDate as Timestamp,
end_date: endDate as Timestamp,
event_type: "changed_date_availability",
timestamp: currentTime,
change: -69
})

const result = db.bookingHistory.doc(newEvent.id).get()

expect(result).toEqual(newEvent)
})
})
17 changes: 9 additions & 8 deletions server/src/data-layer/services/BookingHistoryService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,31 +15,32 @@ class BookingHistoryService {
* Stores a manual deletion of a booking (by admin) into the booking history collection
*
* @param event the required parameters defined by {@link BookingDeletedEvent}
* @returns the created document
*/
public async addBookingDeletedEvent(
event: BookingDeletedEvent
): Promise<void> {
await db.bookingHistory.add(event)
public async addBookingDeletedEvent(event: BookingDeletedEvent) {
return await db.bookingHistory.add(event)
}

/**
* Stores a manual creation of a booking (by admin) into the booking history collection
*
* @param event the required parameters defined by {@link BookingAddedEvent}
* @returns the created document
*/
public async addBookingAddedEvent(event: BookingAddedEvent): Promise<void> {
await db.bookingHistory.add(event)
public async addBookingAddedEvent(event: BookingAddedEvent) {
return await db.bookingHistory.add(event)
}

/**
* Stores a modification to the booking availability into the booking history collection
*
* @param event the required parameters defined by {@link BookingAvailabilityChangeEvent}
* @returns the created document
*/
public async addAvailibilityChangeEvent(
event: BookingAvailabilityChangeEvent
): Promise<void> {
await db.bookingHistory.add(event)
) {
return await db.bookingHistory.add(event)
}

/**
Expand Down

0 comments on commit e97a107

Please sign in to comment.