import TagAssociationMapper from "../resources/tagAssociation/mapper"; import {ITagAssociation} from "../resources/tagAssociation/index"; describe("TagAssociationMapper", () => { it("should map an tag association to a tag model", () => { const mapper = new TagAssociationMapper(); const model: ITagAssociation = mapper.toModel({ "type": "tag-association", "relationships": { "topic": { "data": { id: "99999", type: "topic" } }, "entity": { "data": null } }, "id": "0100322a-5e5f-11e8-8ba0-db1638c712d6", "attributes": { "confidence_score": 0.34, "label": "Trekking", "score": 0.93 } }); expect(model.id).toBe("0100322a-5e5f-11e8-8ba0-db1638c712d6"); expect(model.confidenceScore).toBe(0.34); expect(model.label).toBe("Trekking"); expect(model.score).toBe(0.93); expect(model.tag_type).toBe("topic"); expect(model.tag_id).toBe("99999"); }); it("properly assigns target to the a tag association model", () => { const mapper = new TagAssociationMapper(); const model: ITagAssociation = mapper.toModel({ "type": "tag-association", "relationships": { "target": { "data": { id: "1234", type: "poi" } } }, "id": "0100322a-5e5f-11e8-8ba0-db1638c712d6", "attributes": { "confidence_score": 0.34, "label": "Trekking", "score": 0.93 } }, ([{ type: "poi", id: "1234", attributes: { name: "my POI" }, relationships: { "containing-place": { data: { type: "place", id: "362228" } } } }] as any)); expect(model.target.id).toBe("1234"); expect(model.target.type).toBe("poi"); }); });