Merged in fix/refactor-currency-display (pull request #3434)
fix(SW-3616): Handle EuroBonus point type everywhere * Add tests to formatPrice * formatPrice * More work replacing config with api points type * More work replacing config with api points type * More fixing with currency * maybe actually fixed it * Fix MyStay * Clean up * Fix comments * Merge branch 'master' into fix/refactor-currency-display * Fix calculateTotalPrice for EB points + SF points + cash Approved-by: Joakim Jäderberg
This commit is contained in:
@@ -1,27 +1,25 @@
|
||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||
import { createIntl, createIntlCache } from "react-intl"
|
||||
import { beforeAll, describe, expect, it, vi } from "vitest"
|
||||
|
||||
import { calculateTotalPrice } from "./helpers"
|
||||
|
||||
const cache = createIntlCache()
|
||||
|
||||
const createTestIntl = (locale: string = "en-US") =>
|
||||
createIntl({ locale, messages: {}, onError: () => {} }, cache)
|
||||
|
||||
describe("calculateTotalPrice", () => {
|
||||
const baseRoom: Parameters<typeof calculateTotalPrice>[0][0] = {
|
||||
totalPrice: 0,
|
||||
isCancelled: false,
|
||||
cheques: 0,
|
||||
roomPoints: 0,
|
||||
roomPointType: null,
|
||||
totalPoints: 0,
|
||||
roomPoints: 0,
|
||||
vouchers: 0,
|
||||
}
|
||||
|
||||
const mockIntlSimple = {
|
||||
formatMessage: vi.fn(({}, values) => {
|
||||
if (values?.numberOfVouchers === 1) return "Voucher"
|
||||
return "Vouchers"
|
||||
}),
|
||||
formatNumber: vi.fn((num) => String(num)),
|
||||
} as any
|
||||
|
||||
vi.mock("@scandic-hotels/common/utils/numberFormatting", () => ({
|
||||
formatPrice: (_intl: any, price: number, currency: string) =>
|
||||
`${price} ${currency}`,
|
||||
@@ -40,7 +38,7 @@ describe("calculateTotalPrice", () => {
|
||||
const result = calculateTotalPrice(
|
||||
rooms,
|
||||
"SEK" as any,
|
||||
mockIntlSimple,
|
||||
createTestIntl(),
|
||||
false
|
||||
)
|
||||
expect(result).toBe("1500 SEK")
|
||||
@@ -60,7 +58,7 @@ describe("calculateTotalPrice", () => {
|
||||
const result = calculateTotalPrice(
|
||||
rooms,
|
||||
"SEK" as any,
|
||||
mockIntlSimple,
|
||||
createTestIntl(),
|
||||
false
|
||||
)
|
||||
expect(result).toBe("1000 SEK")
|
||||
@@ -70,7 +68,7 @@ describe("calculateTotalPrice", () => {
|
||||
const result = calculateTotalPrice(
|
||||
[{ ...baseRoom, vouchers: 2, totalPrice: -1, isCancelled: false }],
|
||||
"SEK" as any,
|
||||
mockIntlSimple,
|
||||
createTestIntl(),
|
||||
false
|
||||
)
|
||||
expect(result).toContain("2 Vouchers")
|
||||
@@ -84,19 +82,17 @@ describe("calculateTotalPrice", () => {
|
||||
totalPrice: 100,
|
||||
isCancelled: false,
|
||||
totalPoints: 0,
|
||||
roomPoints: 0,
|
||||
},
|
||||
{
|
||||
...baseRoom,
|
||||
totalPrice: 0,
|
||||
totalPoints: 20000,
|
||||
roomPoints: 20000,
|
||||
roomPointType: "Scandic",
|
||||
isCancelled: false,
|
||||
},
|
||||
],
|
||||
"SEK" as any,
|
||||
mockIntlSimple,
|
||||
createTestIntl(),
|
||||
false
|
||||
)
|
||||
|
||||
@@ -109,7 +105,7 @@ describe("calculateTotalPrice", () => {
|
||||
const result = calculateTotalPrice(
|
||||
rooms,
|
||||
"SEK" as any,
|
||||
mockIntlSimple,
|
||||
createTestIntl(),
|
||||
false
|
||||
)
|
||||
expect(result).toContain("2 CC")
|
||||
@@ -131,7 +127,7 @@ describe("calculateTotalPrice", () => {
|
||||
},
|
||||
],
|
||||
"SEK" as any,
|
||||
mockIntlSimple,
|
||||
createTestIntl(),
|
||||
false
|
||||
)
|
||||
expect(result).toMatch(/1 Voucher \+ 500 SEK/)
|
||||
@@ -151,10 +147,10 @@ describe("calculateTotalPrice", () => {
|
||||
},
|
||||
],
|
||||
"SEK" as any,
|
||||
mockIntlSimple,
|
||||
createTestIntl(),
|
||||
false
|
||||
)
|
||||
expect(result).toMatch(/1 EuroBonus \+ 500 SEK/)
|
||||
expect(result).toMatch(/1 EB Point \+ 500 SEK/)
|
||||
})
|
||||
|
||||
it("should combine Eurobonus points, Scandic Friends points and Cash", () => {
|
||||
@@ -172,9 +168,9 @@ describe("calculateTotalPrice", () => {
|
||||
},
|
||||
],
|
||||
"SEK" as any,
|
||||
mockIntlSimple,
|
||||
createTestIntl(),
|
||||
false
|
||||
)
|
||||
expect(result).toMatch(/500 Points \+ 1 EuroBonus \+ 500 SEK/)
|
||||
expect(result).toMatch(/1 EB Point \+ 500 Points \+ 500 SEK/)
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user