Merged in chore/remove-enrichHotel-call (pull request #3244)
Chore/remove enrichHotel call * chore: remove enrichHotel api call * include cityId when errors happen * remove unused funciton and cleanup code * tests no longer expect us to have called a function that is not used * remove commented code Approved-by: Linus Flood
This commit is contained in:
@@ -4,7 +4,7 @@ import { Lang } from "@scandic-hotels/common/constants/language"
|
||||
import { getCacheClient } from "@scandic-hotels/common/dataCache"
|
||||
|
||||
import * as api from "../../../api"
|
||||
import { getCity } from "./getCity"
|
||||
// import { getCity } from "./getCity"
|
||||
import { getLocationsByCountries } from "./getLocationsByCountries"
|
||||
|
||||
import type { CitiesGroupedByCountry } from "../../../types/locations"
|
||||
@@ -35,15 +35,16 @@ vi.mock("./getCity", () => {
|
||||
vi.mock("@scandic-hotels/common/logger/createLogger", () => {
|
||||
return {
|
||||
createLogger: () => ({
|
||||
error: vi.fn(),
|
||||
info: vi.fn(),
|
||||
warn: vi.fn(),
|
||||
error: vi.fn(),
|
||||
}),
|
||||
}
|
||||
})
|
||||
|
||||
const mockedGetCacheClient = getCacheClient as unknown as Mock
|
||||
const mockedApiGet = api.get as unknown as Mock
|
||||
const mockedGetCity = getCity as unknown as Mock
|
||||
// const mockedGetCity = getCity as unknown as Mock
|
||||
|
||||
describe("getLocationsByCountries", () => {
|
||||
const mockedCacheClient = {
|
||||
@@ -125,20 +126,6 @@ describe("getLocationsByCountries", () => {
|
||||
json: async () => apiPayload,
|
||||
})
|
||||
|
||||
// getCity returns enriched city object for hotel relationship
|
||||
const mockedCity: Awaited<ReturnType<typeof getCity>> = {
|
||||
cityIdentifier: "remote-ci-1",
|
||||
ianaTimeZoneId: "Europe/Stockholm",
|
||||
id: "remote-city-id",
|
||||
isPublished: true,
|
||||
keywords: [],
|
||||
name: "RemoteCity",
|
||||
timeZoneId: "Europe/Stockholm",
|
||||
type: "cities",
|
||||
}
|
||||
|
||||
mockedGetCity.mockResolvedValueOnce(mockedCity)
|
||||
|
||||
const citiesByCountry = {
|
||||
CountryX: [{ name: "CityAA" }],
|
||||
} as unknown as CitiesGroupedByCountry
|
||||
@@ -164,16 +151,13 @@ describe("getLocationsByCountries", () => {
|
||||
expect(cityNode!.country).toBe("CountryX") // country assigned based on citiesByCountry
|
||||
|
||||
expect(hotelNode).toBeDefined()
|
||||
expect(mockedGetCity).toHaveBeenCalledWith({
|
||||
cityUrl: "https://api/cities/city1",
|
||||
serviceToken: "token",
|
||||
})
|
||||
|
||||
// hotel relationships.city should be the object returned by getCity (merged)
|
||||
expect(hotelNode?.relationships).toBeDefined()
|
||||
expect(hotelNode?.relationships.city).toEqual(
|
||||
expect.objectContaining({
|
||||
id: mockedCity.id,
|
||||
name: mockedCity.name,
|
||||
id: "city1",
|
||||
name: "City1",
|
||||
})
|
||||
)
|
||||
})
|
||||
@@ -192,19 +176,6 @@ describe("getLocationsByCountries", () => {
|
||||
json: async () => apiPayload,
|
||||
})
|
||||
|
||||
// getCity returns enriched city object for hotel relationship
|
||||
const mockedCity: Awaited<ReturnType<typeof getCity>> = {
|
||||
cityIdentifier: "remote-ci-1",
|
||||
ianaTimeZoneId: "Europe/Stockholm",
|
||||
id: "remote-city-id",
|
||||
isPublished: true,
|
||||
keywords: [],
|
||||
name: "RemoteCity",
|
||||
timeZoneId: "Europe/Stockholm",
|
||||
type: "cities",
|
||||
}
|
||||
mockedGetCity.mockResolvedValue(mockedCity)
|
||||
|
||||
const citiesByCountry = {
|
||||
CountryX: [{ name: "CityAA" }],
|
||||
} as unknown as CitiesGroupedByCountry
|
||||
@@ -230,17 +201,13 @@ describe("getLocationsByCountries", () => {
|
||||
.filter((n) => n.type === "hotels")
|
||||
.find((n) => n.name === "Hotel1")
|
||||
expect(hotel1).toBeDefined()
|
||||
expect(mockedGetCity).toHaveBeenCalledWith({
|
||||
cityUrl: "https://api/cities/city1",
|
||||
serviceToken: "token",
|
||||
})
|
||||
|
||||
// hotel relationships.city should be the object returned by getCity (merged)
|
||||
expect(hotel1?.relationships).toBeDefined()
|
||||
expect(hotel1?.relationships.city).toEqual(
|
||||
expect.objectContaining({
|
||||
id: mockedCity.id,
|
||||
name: mockedCity.name,
|
||||
id: "city1",
|
||||
name: "City1",
|
||||
})
|
||||
)
|
||||
|
||||
@@ -248,20 +215,15 @@ describe("getLocationsByCountries", () => {
|
||||
.filter((n) => n.type === "hotels")
|
||||
.find((n) => n.name === "Hotel2")
|
||||
expect(hotel2).toBeDefined()
|
||||
expect(mockedGetCity).toHaveBeenCalledWith({
|
||||
cityUrl: "https://api/cities/city2",
|
||||
serviceToken: "token",
|
||||
})
|
||||
|
||||
// hotel relationships.city should be the object returned by getCity (merged)
|
||||
expect(hotel2?.relationships).toBeDefined()
|
||||
expect(hotel2?.relationships.city).toEqual(
|
||||
expect.objectContaining({
|
||||
id: mockedCity.id,
|
||||
name: mockedCity.name,
|
||||
id: "city2",
|
||||
name: "City2",
|
||||
})
|
||||
)
|
||||
|
||||
expect(mockedGetCity).toHaveBeenCalledTimes(2)
|
||||
})
|
||||
|
||||
it("filters out unpublished cities", async () => {
|
||||
|
||||
Reference in New Issue
Block a user