Feat/SW-1737 design mystay multiroom * feat(SW-1737) Fixed member view of guest details * feat(SW-1737) fix merge issues * feat(SW-1737) Fixed price details * feat(SW-1737) removed unused imports * feat(SW-1737) removed true as statement * feat(SW-1737) updated store handling * feat(SW-1737) fixed bug showing double numbers * feat(SW-1737) small design fixed * feat(SW-1737) fixed rebase errors * feat(SW-1737) fixed create booking error with dates * feat(SW-1737) fixed view multiroom as singleroom * feat(SW-1737) fixes for multiroom * feat(SW-1737) fixed bookingsummary * feat(SW-1737) dont hide modify dates * feat(SW-1737) updated breakfast to handle number * feat(SW-1737) Added red color if member rate * feat(SW-1737) fix PR comments * feat(SW-1737) updated member tiers svg * feat(SW-1737) updated how to handle paymentMethodDescription * feat(SW-1737) fixes after testing mystay * feat(SW-1737) updated Room type to just use whats used * feat(SW-1737) fixed access * feat(SW-1737) refactor my stay after PR comments * feat(SW-1737) fix roomNumber translation * feat(SW-1737) removed log Approved-by: Arvid Norlin
154 lines
4.8 KiB
TypeScript
154 lines
4.8 KiB
TypeScript
import { describe, expect, it } from "@jest/globals"
|
|
|
|
import accessBooking, {
|
|
ACCESS_GRANTED,
|
|
ERROR_BAD_REQUEST,
|
|
ERROR_FORBIDDEN,
|
|
ERROR_NOT_FOUND,
|
|
ERROR_UNAUTHORIZED,
|
|
} from "./accessBooking"
|
|
|
|
import type { SafeUser } from "@/types/user"
|
|
import type { Guest } from "@/server/routers/booking/output"
|
|
|
|
describe("Access booking", () => {
|
|
describe("for logged in booking", () => {
|
|
it("should enable access if all is provided", () => {
|
|
expect(accessBooking(loggedIn, "Booking", user)).toBe(ACCESS_GRANTED)
|
|
})
|
|
it("should enable access if all is provided and be case-insensitive", () => {
|
|
expect(accessBooking(loggedIn, "BoOkInG", user)).toBe(ACCESS_GRANTED)
|
|
})
|
|
it("should prompt to login", () => {
|
|
expect(accessBooking(loggedIn, "Booking", null)).toBe(ERROR_UNAUTHORIZED)
|
|
})
|
|
it("should deny access", () => {
|
|
expect(accessBooking(loggedIn, "NotBooking", user)).toBe(ERROR_NOT_FOUND)
|
|
})
|
|
})
|
|
describe("for anonymous booking", () => {
|
|
it("should enable access if all is provided", () => {
|
|
const cookieString = new URLSearchParams({
|
|
confirmationNumber: "123456789",
|
|
firstName: "Anonymous",
|
|
lastName: "Booking",
|
|
email: "logged+out@scandichotels.com",
|
|
}).toString()
|
|
expect(accessBooking(loggedOut, "Booking", null, cookieString)).toBe(
|
|
ACCESS_GRANTED
|
|
)
|
|
})
|
|
it("should enable access if all is provided and be case-insensitive for first name", () => {
|
|
const cookieString = new URLSearchParams({
|
|
confirmationNumber: "123456789",
|
|
firstName: "AnOnYmOuS",
|
|
lastName: "Booking",
|
|
email: "logged+out@scandichotels.com",
|
|
}).toString()
|
|
expect(accessBooking(loggedOut, "Booking", null, cookieString)).toBe(
|
|
ACCESS_GRANTED
|
|
)
|
|
})
|
|
it("should enable access if all is provided and be case-insensitive for last name", () => {
|
|
const cookieString = new URLSearchParams({
|
|
confirmationNumber: "123456789",
|
|
firstName: "Anonymous",
|
|
lastName: "Booking",
|
|
email: "logged+out@scandichotels.com",
|
|
}).toString()
|
|
expect(accessBooking(loggedOut, "BoOkInG", null, cookieString)).toBe(
|
|
ACCESS_GRANTED
|
|
)
|
|
})
|
|
it("should enable access if all is provided and be case-insensitive for email", () => {
|
|
const cookieString = new URLSearchParams({
|
|
confirmationNumber: "123456789",
|
|
firstName: "Anonymous",
|
|
lastName: "Booking",
|
|
email: "LOGGED+out@scandichotels.com",
|
|
}).toString()
|
|
expect(accessBooking(loggedOut, "Booking", null, cookieString)).toBe(
|
|
ACCESS_GRANTED
|
|
)
|
|
})
|
|
it("should prompt logout if user is logged in", () => {
|
|
const cookieString = new URLSearchParams({
|
|
confirmationNumber: "123456789",
|
|
firstName: "Anonymous",
|
|
lastName: "Booking",
|
|
email: "logged+out@scandichotels.com",
|
|
}).toString()
|
|
expect(accessBooking(loggedOut, "Booking", user, cookieString)).toBe(
|
|
ERROR_FORBIDDEN
|
|
)
|
|
})
|
|
it("should prompt for more if first name is missing", () => {
|
|
const cookieString = new URLSearchParams({
|
|
confirmationNumber: "123456789",
|
|
lastName: "Booking",
|
|
email: "logged+out@scandichotels.com",
|
|
}).toString()
|
|
expect(accessBooking(loggedOut, "Booking", null, cookieString)).toBe(
|
|
ERROR_BAD_REQUEST
|
|
)
|
|
})
|
|
it("should prompt for more if email is missing", () => {
|
|
const cookieString = new URLSearchParams({
|
|
confirmationNumber: "123456789",
|
|
firstName: "Anonymous",
|
|
lastName: "Booking",
|
|
}).toString()
|
|
expect(accessBooking(loggedOut, "Booking", null, cookieString)).toBe(
|
|
ERROR_BAD_REQUEST
|
|
)
|
|
})
|
|
it("should prompt for more if cookie is invalid", () => {
|
|
const cookieString = new URLSearchParams({}).toString()
|
|
expect(accessBooking(loggedOut, "Booking", null, cookieString)).toBe(
|
|
ERROR_BAD_REQUEST
|
|
)
|
|
})
|
|
it("should deny access", () => {
|
|
expect(accessBooking(loggedOut, "NotBooking", null)).toBe(ERROR_NOT_FOUND)
|
|
})
|
|
})
|
|
})
|
|
|
|
const user: SafeUser = {
|
|
address: {
|
|
city: undefined,
|
|
country: "Sweden",
|
|
countryCode: "SE",
|
|
streetAddress: undefined,
|
|
zipCode: undefined,
|
|
},
|
|
dateOfBirth: "",
|
|
email: "",
|
|
firstName: "",
|
|
language: undefined,
|
|
lastName: "",
|
|
membership: undefined,
|
|
memberships: [],
|
|
name: "",
|
|
phoneNumber: undefined,
|
|
profileId: "",
|
|
}
|
|
|
|
const loggedOut: Guest = {
|
|
email: "logged+out@scandichotels.com",
|
|
firstName: "Anonymous",
|
|
lastName: "Booking",
|
|
membershipNumber: "",
|
|
phoneNumber: "+46701234567",
|
|
countryCode: "SE",
|
|
}
|
|
|
|
const loggedIn: Guest = {
|
|
email: "logged+in@scandichotels.com",
|
|
firstName: "Authenticated",
|
|
lastName: "Booking",
|
|
membershipNumber: "01234567890123",
|
|
phoneNumber: "+46701234567",
|
|
countryCode: "SE",
|
|
}
|