Merged in feat/sw-3642-inject-sas-eb-payment (pull request #3243)
feat(SW-3642): Enable SAS EB payments * Wip add SAS eb payment * Add validate payment call * Check booking status payment method to determine validation * Clean up getPaymentData * Fix PartnerPoints casing * Add comment for validatePartnerPayment error handling * Remove comment Approved-by: Joakim Jäderberg
This commit is contained in:
@@ -1,6 +1,13 @@
|
||||
import { describe, expect, it } from "vitest"
|
||||
|
||||
import { mustGuaranteeBooking } from "./helpers"
|
||||
import { Lang } from "@scandic-hotels/common/constants/language"
|
||||
import { PaymentMethodEnum } from "@scandic-hotels/common/constants/paymentMethod"
|
||||
|
||||
import {
|
||||
getPaymentData,
|
||||
getPaymentMethod,
|
||||
mustGuaranteeBooking,
|
||||
} from "./helpers"
|
||||
|
||||
const buildRoom = (
|
||||
overrides: Partial<{
|
||||
@@ -96,3 +103,179 @@ describe("mustGuaranteeBooking", () => {
|
||||
).toBe(true)
|
||||
})
|
||||
})
|
||||
|
||||
describe("getPaymentData", () => {
|
||||
it("returns correct URLs and method when guarantee is true", () => {
|
||||
const result = getPaymentData({
|
||||
paymentMethod: PaymentMethodEnum.swish,
|
||||
lang: Lang.en,
|
||||
guarantee: true,
|
||||
bookingMustBeGuaranteed: false,
|
||||
hasOnlyFlexRates: true,
|
||||
isRedemptionBooking: false,
|
||||
})
|
||||
|
||||
expect(result).toEqual({
|
||||
paymentMethod: PaymentMethodEnum.swish,
|
||||
success: `/en/hotelreservation/payment-callback/success`,
|
||||
error: `/en/hotelreservation/payment-callback/error`,
|
||||
cancel: `/en/hotelreservation/payment-callback/cancel`,
|
||||
})
|
||||
})
|
||||
|
||||
it("returns correct URLs and method when bookingMustBeGuaranteed", () => {
|
||||
const result = getPaymentData({
|
||||
paymentMethod: PaymentMethodEnum.swish,
|
||||
lang: Lang.en,
|
||||
guarantee: false,
|
||||
bookingMustBeGuaranteed: true,
|
||||
hasOnlyFlexRates: true,
|
||||
isRedemptionBooking: false,
|
||||
})
|
||||
|
||||
expect(result).toEqual({
|
||||
paymentMethod: PaymentMethodEnum.swish,
|
||||
success: `/en/hotelreservation/payment-callback/success`,
|
||||
error: `/en/hotelreservation/payment-callback/error`,
|
||||
cancel: `/en/hotelreservation/payment-callback/cancel`,
|
||||
})
|
||||
})
|
||||
|
||||
it("returns correct URLs and method when has only flex rates is false", () => {
|
||||
const result = getPaymentData({
|
||||
paymentMethod: PaymentMethodEnum.swish,
|
||||
lang: Lang.en,
|
||||
guarantee: false,
|
||||
bookingMustBeGuaranteed: false,
|
||||
hasOnlyFlexRates: false,
|
||||
isRedemptionBooking: false,
|
||||
})
|
||||
|
||||
expect(result).toEqual({
|
||||
paymentMethod: PaymentMethodEnum.swish,
|
||||
success: `/en/hotelreservation/payment-callback/success`,
|
||||
error: `/en/hotelreservation/payment-callback/error`,
|
||||
cancel: `/en/hotelreservation/payment-callback/cancel`,
|
||||
})
|
||||
})
|
||||
|
||||
it("returns null when payment isn't required", () => {
|
||||
const result = getPaymentData({
|
||||
paymentMethod: PaymentMethodEnum.swish,
|
||||
lang: Lang.en,
|
||||
guarantee: false,
|
||||
bookingMustBeGuaranteed: false,
|
||||
hasOnlyFlexRates: true,
|
||||
isRedemptionBooking: false,
|
||||
})
|
||||
|
||||
expect(result).toBeNull()
|
||||
})
|
||||
|
||||
it("returns saved credit card when provided", () => {
|
||||
const result = getPaymentData({
|
||||
paymentMethod: PaymentMethodEnum.card,
|
||||
lang: Lang.en,
|
||||
guarantee: false,
|
||||
bookingMustBeGuaranteed: false,
|
||||
hasOnlyFlexRates: false,
|
||||
isRedemptionBooking: false,
|
||||
savedCreditCard: {
|
||||
alias: "My Visa",
|
||||
expirationDate: "12/25",
|
||||
cardType: "visa",
|
||||
id: "",
|
||||
type: "",
|
||||
truncatedNumber: "",
|
||||
},
|
||||
})
|
||||
|
||||
expect(result).toEqual({
|
||||
paymentMethod: PaymentMethodEnum.card,
|
||||
success: `/en/hotelreservation/payment-callback/success`,
|
||||
error: `/en/hotelreservation/payment-callback/error`,
|
||||
cancel: `/en/hotelreservation/payment-callback/cancel`,
|
||||
card: {
|
||||
alias: "My Visa",
|
||||
expiryDate: "12/25",
|
||||
cardType: "visa",
|
||||
},
|
||||
})
|
||||
})
|
||||
|
||||
it("returns correct URLs and method when isRedemptionBooking is true and type is PartnerPoints", () => {
|
||||
const result = getPaymentData({
|
||||
paymentMethod: PaymentMethodEnum.PartnerPoints,
|
||||
lang: Lang.en,
|
||||
guarantee: false,
|
||||
bookingMustBeGuaranteed: false,
|
||||
hasOnlyFlexRates: true,
|
||||
isRedemptionBooking: true,
|
||||
})
|
||||
|
||||
expect(result).toEqual({
|
||||
paymentMethod: PaymentMethodEnum.PartnerPoints,
|
||||
success: `/en/hotelreservation/payment-callback/success`,
|
||||
error: `/en/hotelreservation/payment-callback/error`,
|
||||
cancel: `/en/hotelreservation/payment-callback/cancel`,
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe("getPaymentMethod", () => {
|
||||
it("returns card when hasFlexRates is true", () => {
|
||||
const hasFlexRates = true
|
||||
const isRedemptionBooking = false
|
||||
const redemptionType = "scandic"
|
||||
const method = getPaymentMethod({
|
||||
paymentMethod: PaymentMethodEnum.swish,
|
||||
hasFlexRates,
|
||||
isRedemptionBooking,
|
||||
redemptionType,
|
||||
})
|
||||
|
||||
expect(method).toBe(PaymentMethodEnum.card)
|
||||
})
|
||||
|
||||
it("returns PartnerPoints when is redemption and redemptionType is partner", () => {
|
||||
const hasFlexRates = false
|
||||
const isRedemptionBooking = true
|
||||
const redemptionType = "partner"
|
||||
const method = getPaymentMethod({
|
||||
paymentMethod: PaymentMethodEnum.swish,
|
||||
hasFlexRates,
|
||||
isRedemptionBooking,
|
||||
redemptionType,
|
||||
})
|
||||
|
||||
expect(method).toBe(PaymentMethodEnum.PartnerPoints)
|
||||
})
|
||||
|
||||
it("returns paymentMethod when not redemption but redemptionType is partner", () => {
|
||||
const hasFlexRates = false
|
||||
const isRedemptionBooking = false
|
||||
const redemptionType = "partner"
|
||||
const method = getPaymentMethod({
|
||||
paymentMethod: PaymentMethodEnum.swish,
|
||||
hasFlexRates,
|
||||
isRedemptionBooking,
|
||||
redemptionType,
|
||||
})
|
||||
|
||||
expect(method).toBe(PaymentMethodEnum.swish)
|
||||
})
|
||||
|
||||
it("returns card when payment method is string", () => {
|
||||
const hasFlexRates = false
|
||||
const isRedemptionBooking = false
|
||||
const redemptionType = "scandic"
|
||||
const method = getPaymentMethod({
|
||||
paymentMethod: "something-else",
|
||||
hasFlexRates,
|
||||
isRedemptionBooking,
|
||||
redemptionType,
|
||||
})
|
||||
|
||||
expect(method).toBe(PaymentMethodEnum.card)
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user