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