import AssociationEntryMapper from "../resources/associationEntry/mapper"; import {IAssociationEntry} from "../resources/associationEntry/index"; describe("AssociationEntryMapper", () => { it("should map an association-entry to an associationEntry model", () => { const mapper = new AssociationEntryMapper(); const model: IAssociationEntry = mapper.toModel({ "type": "association-entry", "relationships": { "target": null }, "id": "0100322a-5e5f-11e8-8ba0-db1638c712d6", "attributes": { "matches_source": true, "created_at": "2018-05-23T10:46:56.337288", "updated_at": "2018-05-24T10:46:56.337288" } }); expect(model.id).toBe("0100322a-5e5f-11e8-8ba0-db1638c712d6"); expect(model.matchesSource).toBe(true); expect(model.createdAt).toBe("2018-05-23T10:46:56.337288"); expect(model.updatedAt).toBe("2018-05-24T10:46:56.337288"); }); it("properly assigns target to the an association-entry model", () => { const mapper = new AssociationEntryMapper(); const model: IAssociationEntry = mapper.toModel({ "type": "association-entry", "relationships": { "target": { "data": { id: "1234", type: "poi" } } }, "id": "0100322a-5e5f-11e8-8ba0-db1638c712d6", "attributes": { "matches_source": true, "created_at": "2018-05-23T10:46:56.337288", "updated_at": "2018-05-23T10:46:56.337288" } }, ([{ type: "poi", id: "1234", attributes: { name: "my POI" }, relationships: { "containing-place": { data: { type: "place", id: "362228" } } } }] as any)); expect(model.target.id).toBe("1234") }); });