import VideoMapper from "../resources/video/mapper"; import {IVideo, IVideoResource} from "../resources/video"; import {IJsonApiResource} from "../interfaces"; import VideoSource from "../resources/videoSource"; describe("VideoMapper", () => { it("correctly maps a video to a video model", () => { const mapper = new VideoMapper(); const resource: IVideoResource = { "type": "video", "id": "520", "attributes": { "url": "https://www.lonelyplanet.com/video/lonely-planets-best-destinations-to-visit-in-2018/v/vid/520", "tags": [ "tallinn", "belfast", ], "iframe_embed": "", "html5_embed": "", "modify_date": "2018-07-23T12:56:12.389721Z", "create_date": "2017-10-18T02:52:25.890979Z", "name": "Lonely Planet's best destinations to visit in 2018", "slug": "lonely-planets-best-destinations-to-visit-in-2018", "live": true, "reference_id": "1234567", "short_description": "Short description", "description": "Long description", "duration": 115220, "is_360": true, "episode": 1, "season": 2, "format": "format", "host": "Video Host", "director": "Video Director", "year": "2017", "pixel": "", "featured_order": 1, "featured_priority": true, "spotlight": true, "hub": true, "thumbnail_url": "https://s3.amazonaws.com/static-asset/op-video-sync/images/qa/t-5615400608001-brightcove-lonely-planets-best-destinations-to-visit-in-2018-20171028-052134.jpg", "poster_url": "https://s3.amazonaws.com/static-asset/op-video-sync/images/qa/p-5615400608001-brightcove-lonely-planets-best-destinations-to-visit-in-2018-20171028-052135.jpg", "hero_url": "https://s3.amazonaws.com/static-asset/op-video-sync/images/qa/p-5615400608001-brightcove-hero.jpg", "graphic_url": "https://lonelyplanetstatic.imgix.net/op-video-sync/assets/logo_bestintravel.svg", "provider_id": "5615400608001", "provider_name": "brightcove", "start_date": "2017-10-18T02:50:11Z", "end_date": "2017-11-18T02:50:11Z", }, }; const model: IVideo = mapper.toModel(resource); expect(model.id).toBe("520"); expect(model.url).toBe("https://www.lonelyplanet.com/video/lonely-planets-best-destinations-to-visit-in-2018/v/vid/520"); expect(model.iframeEmbed).toBe(""); expect(model.html5Embed).toBe(""); expect(model.updatedAt).toBe("2018-07-23T12:56:12.389721Z"); expect(model.createdAt).toBe("2017-10-18T02:52:25.890979Z"); expect(model.name).toBe("Lonely Planet's best destinations to visit in 2018"); expect(model.slug).toBe("lonely-planets-best-destinations-to-visit-in-2018"); expect(model.live).toBe(true); expect(model.referenceId).toBe("1234567"); expect(model.shortDescription).toBe("Short description"); expect(model.longDescription).toBe("Long description"); expect(model.duration).toBe(115220); expect(model.isSpherical).toBe(true); expect(model.episode).toBe(1); expect(model.season).toBe(2); expect(model.format).toBe("format"); expect(model.host).toBe("Video Host"); expect(model.director).toBe("Video Director"); expect(model.year).toBe("2017"); expect(model.pixel).toBe(""); expect(model.featuredOrder).toBe(1); expect(model.featuredPriority).toBe(true); expect(model.spotlight).toBe(true); expect(model.hub).toBe(true); expect(model.thumbnailUrl).toBe("https://s3.amazonaws.com/static-asset/op-video-sync/images/qa/t-5615400608001-brightcove-lonely-planets-best-destinations-to-visit-in-2018-20171028-052134.jpg"); expect(model.posterUrl).toBe("https://s3.amazonaws.com/static-asset/op-video-sync/images/qa/p-5615400608001-brightcove-lonely-planets-best-destinations-to-visit-in-2018-20171028-052135.jpg"); expect(model.heroUrl).toBe("https://s3.amazonaws.com/static-asset/op-video-sync/images/qa/p-5615400608001-brightcove-hero.jpg"); expect(model.graphicUrl).toBe("https://lonelyplanetstatic.imgix.net/op-video-sync/assets/logo_bestintravel.svg"); expect(model.providerId).toBe("5615400608001"); expect(model.providerName).toBe("brightcove"); expect(model.startDate).toBe("2017-10-18T02:50:11Z"); expect(model.endDate).toBe("2017-11-18T02:50:11Z"); }); it("correctly maps included video sources", () => { const mapper = new VideoMapper(); const resource: IVideoResource = { "type": "video", "id": "520", "attributes": {}, "relationships": { "sources": { "data": [{ "id": "192744", "type": "source" }, { "id": "3636", "type": "source" }] } } }; const included = [ { "attributes": { "app_name": "rtmp://cp150446.edgefcs.net/ondemand", "codec": "H264", "container": "MP4", "create_date": "2018-07-23T05:19:33.763459Z", "encoding_rate": 513000, "height": 270, "modify_date": "2018-07-23T05:19:33.763418Z", "size": 7436881, "source_type": null, "src": null, "stream_name": "mp4:5104226627001/5104226627001_5630804281001_5615400608001.mp4?__nn__=1497926354001&slist=5104226627001/&auth=daEdSaxcuc8cvd7b_dsc6cVc4bSa6aCatbx-bBvvla-hca-olACrrry_BJyp_IEDA_FsC&aifp=bcosuds", "width": 480 }, "id": "192744", "links": { "self": "/videos/520/sources/192743" }, "relationships": { "video": { "data": { "id": "520", "type": "video" }, "links": { "related": "/videos/520" } } }, "type": "source" }, { "attributes": { "app_name": null, "codec": "H264", "container": "MP4", "create_date": "2018-05-10T14:26:56.446425Z", "encoding_rate": 1827000, "height": 540, "modify_date": "2018-05-10T14:26:56.446406Z", "size": 26371304, "source_type": null, "src": "https://f1.media.brightcove.com/12/5104226627001/5104226627001_5630805396001_5615400608001.mp4?pubId=5104226627001&videoId=5615400608001", "stream_name": null, "width": 960 }, "id": "3636", "links": { "self": "/videos/520/sources/3636" }, "relationships": { "video": { "data": { "id": "520", "type": "video" }, "links": { "related": "/videos/520" } } }, "type": "source" }, ]; const model: IVideo = mapper.toModel(resource, included as IJsonApiResource[]); expect(model.sources).toHaveLength(2); expect(model.sources[0].id).toBe("192744"); expect(model.sources[1].id).toBe("3636"); expect(model.sources[0].constructor.name).toBe("VideoSource"); expect(model.sources[1].constructor.name).toBe("VideoSource"); }); });