Merged in chore/refactor-paymentclient (pull request #3219)
chore: Refactor PaymentClient * Extract function mustGuaranteeBooking * Break apart PaymentClient Approved-by: Joakim Jäderberg
This commit is contained in:
@@ -0,0 +1,98 @@
|
||||
import { describe, expect, it } from "vitest"
|
||||
|
||||
import { mustGuaranteeBooking } from "./helpers"
|
||||
|
||||
const buildRoom = (
|
||||
overrides: Partial<{
|
||||
memberMustBeGuaranteed: boolean
|
||||
mustBeGuaranteed: boolean
|
||||
guest: { join: boolean; membershipNo?: string }
|
||||
}> = {}
|
||||
) => ({
|
||||
room: {
|
||||
memberMustBeGuaranteed: false,
|
||||
mustBeGuaranteed: false,
|
||||
guest: { join: false, membershipNo: undefined },
|
||||
...overrides,
|
||||
},
|
||||
})
|
||||
|
||||
describe("mustGuaranteeBooking", () => {
|
||||
it("returns true when the first room requires a member guarantee for a logged-in user", () => {
|
||||
const rooms = [
|
||||
buildRoom({
|
||||
memberMustBeGuaranteed: true,
|
||||
mustBeGuaranteed: false,
|
||||
}),
|
||||
]
|
||||
|
||||
const booking = { rooms: [{}] }
|
||||
|
||||
expect(
|
||||
mustGuaranteeBooking({
|
||||
isUserLoggedIn: true,
|
||||
booking,
|
||||
rooms,
|
||||
})
|
||||
).toBe(true)
|
||||
})
|
||||
|
||||
it("returns memberMustBeGuaranteed when guest has membership details and counter rate code", () => {
|
||||
const rooms = [
|
||||
buildRoom(),
|
||||
buildRoom({
|
||||
memberMustBeGuaranteed: true,
|
||||
guest: { join: true },
|
||||
}),
|
||||
]
|
||||
|
||||
const booking = { rooms: [{}, { counterRateCode: "COUNTER" }] }
|
||||
|
||||
expect(
|
||||
mustGuaranteeBooking({
|
||||
isUserLoggedIn: false,
|
||||
booking,
|
||||
rooms,
|
||||
})
|
||||
).toBe(true)
|
||||
})
|
||||
|
||||
it("returns false when member condition is not met despite counter rate code", () => {
|
||||
const rooms = [
|
||||
buildRoom(),
|
||||
buildRoom({
|
||||
memberMustBeGuaranteed: false,
|
||||
guest: { join: true },
|
||||
}),
|
||||
]
|
||||
|
||||
const booking = { rooms: [{}, { counterRateCode: "COUNTER" }] }
|
||||
|
||||
expect(
|
||||
mustGuaranteeBooking({
|
||||
isUserLoggedIn: false,
|
||||
booking,
|
||||
rooms,
|
||||
})
|
||||
).toBe(false)
|
||||
})
|
||||
|
||||
it("falls back to mustBeGuaranteed when no member-specific rules apply", () => {
|
||||
const rooms = [
|
||||
buildRoom({
|
||||
memberMustBeGuaranteed: false,
|
||||
mustBeGuaranteed: true,
|
||||
}),
|
||||
]
|
||||
|
||||
const booking = { rooms: [{}] }
|
||||
|
||||
expect(
|
||||
mustGuaranteeBooking({
|
||||
isUserLoggedIn: false,
|
||||
booking,
|
||||
rooms,
|
||||
})
|
||||
).toBe(true)
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user