]>
Commit | Line | Data |
---|---|---|
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ | |
2 | ||
3 | import 'mocha' | |
4 | import * as chai from 'chai' | |
5 | import { Video, VideoPlaylistPrivacy } from '@shared/models' | |
6 | import { | |
7 | getVideosList, | |
8 | ServerInfo, | |
9 | setAccessTokensToServers, | |
10 | setDefaultVideoChannel, | |
11 | uploadVideo | |
12 | } from '../../../../shared/extra-utils' | |
13 | import { cleanupTests, flushAndRunServer } from '../../../../shared/extra-utils/server/servers' | |
14 | ||
15 | const expect = chai.expect | |
16 | ||
17 | describe('Test services', function () { | |
18 | let server: ServerInfo = null | |
19 | let playlistUUID: string | |
20 | let playlistDisplayName: string | |
21 | let video: Video | |
22 | ||
23 | before(async function () { | |
24 | this.timeout(30000) | |
25 | ||
26 | server = await flushAndRunServer(1) | |
27 | ||
28 | await setAccessTokensToServers([ server ]) | |
29 | await setDefaultVideoChannel([ server ]) | |
30 | ||
31 | { | |
32 | const videoAttributes = { | |
33 | name: 'my super name' | |
34 | } | |
35 | await uploadVideo(server.url, server.accessToken, videoAttributes) | |
36 | ||
37 | const res = await getVideosList(server.url) | |
38 | video = res.body.data[0] | |
39 | } | |
40 | ||
41 | { | |
42 | const created = await server.playlistsCommand.create({ | |
43 | attributes: { | |
44 | displayName: 'The Life and Times of Scrooge McDuck', | |
45 | privacy: VideoPlaylistPrivacy.PUBLIC, | |
46 | videoChannelId: server.videoChannel.id | |
47 | } | |
48 | }) | |
49 | ||
50 | playlistUUID = created.uuid | |
51 | playlistDisplayName = 'The Life and Times of Scrooge McDuck' | |
52 | ||
53 | await server.playlistsCommand.addElement({ | |
54 | playlistId: created.id, | |
55 | attributes: { | |
56 | videoId: video.id | |
57 | } | |
58 | }) | |
59 | } | |
60 | }) | |
61 | ||
62 | it('Should have a valid oEmbed video response', async function () { | |
63 | for (const basePath of [ '/videos/watch/', '/w/' ]) { | |
64 | const oembedUrl = 'http://localhost:' + server.port + basePath + video.uuid | |
65 | ||
66 | const res = await server.servicesCommand.getOEmbed({ oembedUrl }) | |
67 | const expectedHtml = '<iframe width="560" height="315" sandbox="allow-same-origin allow-scripts" ' + | |
68 | `title="${video.name}" src="http://localhost:${server.port}/videos/embed/${video.uuid}" ` + | |
69 | 'frameborder="0" allowfullscreen></iframe>' | |
70 | const expectedThumbnailUrl = 'http://localhost:' + server.port + video.previewPath | |
71 | ||
72 | expect(res.body.html).to.equal(expectedHtml) | |
73 | expect(res.body.title).to.equal(video.name) | |
74 | expect(res.body.author_name).to.equal(server.videoChannel.displayName) | |
75 | expect(res.body.width).to.equal(560) | |
76 | expect(res.body.height).to.equal(315) | |
77 | expect(res.body.thumbnail_url).to.equal(expectedThumbnailUrl) | |
78 | expect(res.body.thumbnail_width).to.equal(850) | |
79 | expect(res.body.thumbnail_height).to.equal(480) | |
80 | } | |
81 | }) | |
82 | ||
83 | it('Should have a valid playlist oEmbed response', async function () { | |
84 | for (const basePath of [ '/videos/watch/playlist/', '/w/p/' ]) { | |
85 | const oembedUrl = 'http://localhost:' + server.port + basePath + playlistUUID | |
86 | ||
87 | const res = await server.servicesCommand.getOEmbed({ oembedUrl }) | |
88 | const expectedHtml = '<iframe width="560" height="315" sandbox="allow-same-origin allow-scripts" ' + | |
89 | `title="${playlistDisplayName}" src="http://localhost:${server.port}/video-playlists/embed/${playlistUUID}" ` + | |
90 | 'frameborder="0" allowfullscreen></iframe>' | |
91 | ||
92 | expect(res.body.html).to.equal(expectedHtml) | |
93 | expect(res.body.title).to.equal('The Life and Times of Scrooge McDuck') | |
94 | expect(res.body.author_name).to.equal(server.videoChannel.displayName) | |
95 | expect(res.body.width).to.equal(560) | |
96 | expect(res.body.height).to.equal(315) | |
97 | expect(res.body.thumbnail_url).exist | |
98 | expect(res.body.thumbnail_width).to.equal(280) | |
99 | expect(res.body.thumbnail_height).to.equal(157) | |
100 | } | |
101 | }) | |
102 | ||
103 | it('Should have a valid oEmbed response with small max height query', async function () { | |
104 | for (const basePath of [ '/videos/watch/', '/w/' ]) { | |
105 | const oembedUrl = 'http://localhost:' + server.port + basePath + video.uuid | |
106 | const format = 'json' | |
107 | const maxHeight = 50 | |
108 | const maxWidth = 50 | |
109 | ||
110 | const res = await server.servicesCommand.getOEmbed({ oembedUrl, format, maxHeight, maxWidth }) | |
111 | const expectedHtml = '<iframe width="50" height="50" sandbox="allow-same-origin allow-scripts" ' + | |
112 | `title="${video.name}" src="http://localhost:${server.port}/videos/embed/${video.uuid}" ` + | |
113 | 'frameborder="0" allowfullscreen></iframe>' | |
114 | ||
115 | expect(res.body.html).to.equal(expectedHtml) | |
116 | expect(res.body.title).to.equal(video.name) | |
117 | expect(res.body.author_name).to.equal(server.videoChannel.displayName) | |
118 | expect(res.body.height).to.equal(50) | |
119 | expect(res.body.width).to.equal(50) | |
120 | expect(res.body).to.not.have.property('thumbnail_url') | |
121 | expect(res.body).to.not.have.property('thumbnail_width') | |
122 | expect(res.body).to.not.have.property('thumbnail_height') | |
123 | } | |
124 | }) | |
125 | ||
126 | after(async function () { | |
127 | await cleanupTests([ server ]) | |
128 | }) | |
129 | }) |