import LodgingMapper from "../resources/lodging/mapper"; import { ILodging } from "../resources/lodging"; describe("LodgingMapper", () => { it("should map a lodging entry to a lodging model", () => { const mapper = new LodgingMapper(); const now = new Date().getTime(); const model = mapper.toModel({ type: "lodging", id: "1234", attributes: { name: "Some hotel somewhere", score: 3, star_rating: 3, }, relationships: { "containing-place": { data: { type: "place", id: "362228" } }, providers: { data: [{ type: "lodging_provider", id: "bdc123", }] }, poi: { data: { id: "7890", type: "poi", } } }, }, [{ id: "362228", attributes: { name: "Nashville", place_type: "city" }, relationships: { ancestry: { data: [ { id: "362228", type: "place" }, { id: "07041776", type: "place" }, { id: "298234", type: "place" }, { id: "123456", type: "place" }, { id: "11001010", type: "place" }, { id: "11001011", type: "place" }, { id: "11001100", type: "place" }, ], links: {}, }, }, type: "place", }, { id: "9999", attributes: { attribution: [ { name: "JQ", organization: "Lonely Planet", }, ], caption: "Marriott in Downtown Nashville", height: 0, orientation: "square", path: "/images/hotel/840x460_watermarked_standard_bluecom/dbf/dbf016669d926ad0aef7f1ed670eeef4315f93d7.jpg", tags: ["Hotel information"], width: 0, }, type: "image", links: { pixels: "http://aff.bstatic.com/images/hotel/840x460_watermarked_standard_bluecom/dbf/dbf016669d926ad0aef7f1ed670eeef4315f93d7.jpg", self: "/lodgings/df668581-38e8-498b-9666-a26dd169b72d/image_associations/122166503/image" }, relationships: { lodging: { data: { type: "lodging", id: "1234", }, } } }, { id: "bdc1234", attributes: { website: "https://www.somehotel.com" }, type: "lodging_provider", links: { self: "/lodging_provider/bdc1234" }, relationships: { lodging: { data: { type: "lodging", id: "1234", }, } } }, { id: "7890", attributes: { name: "Atlas name for some hotel" }, type: "poi", links: { self: "/poi/7890" }, relationships: { "containing-place": { data: { id: "90909", type: "place", }, } } }, { id: "07041776", attributes: { name: "United States", place_type: "country" }, type: "place" }, { id: "298234", attributes: { name: "North America", place_type: "continent" }, type: "place" }, { id: "123456", attributes: { name: "Downtown", place_type: "neighborhood" }, type: "place" }, { id: "11001010", attributes: { name: "Tennessee", place_type: "region" }, type: "place" }, { id: "11001011", attributes: { name: "Middle Tennessee", place_type: "region" }, type: "place" }, { id: "11001100", attributes: { name: "Americas", place_type: "region" }, type: "place" }]); expect(model.name).toEqual("Some hotel somewhere"); expect(model.starRating).toEqual(3); expect(model.containingPlaceName).toEqual("Nashville"); expect(model.containingCityName).toEqual("Nashville"); expect(model.containingCountryName).toEqual("United States"); expect(model.containingContinentName).toEqual("North America"); expect(model.containingNeighborhoodName).toEqual("Downtown"); expect(model.containingRegionNames).toEqual(["Tennessee", "Middle Tennessee", "Americas"]); expect(model.images.length).toBe(1); expect(model.images[0].path).toBe("/images/hotel/840x460_watermarked_standard_bluecom/dbf/dbf016669d926ad0aef7f1ed670eeef4315f93d7.jpg"); expect(model.images[0].url).toBe("https://lpbookingcom.imgix.net/images/hotel/840x460_watermarked_standard_bluecom/dbf/dbf016669d926ad0aef7f1ed670eeef4315f93d7.jpg"); expect(model.images[0].attribution).toEqual([ { name: "JQ", organization: "Lonely Planet", }, ]); expect(model.images[0].caption).toBe("Marriott in Downtown Nashville"); expect(model.images[0].height).toBe(0); expect(model.images[0].orientation).toBe("square"); expect(model.images[0].tags).toEqual(["Hotel information"]); expect(model.images[0].width).toBe(0); expect(model.providers[0].id).toBe("bdc1234"); expect(model.providers[0].provider).toBe("bdc"); expect(model.providers[0].website).toBe("https://www.somehotel.com"); expect(model.poi.name).toBe("Atlas name for some hotel"); }); });