]>
Commit | Line | Data |
---|---|---|
a1587156 | 1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ |
d8755eed | 2 | |
d8755eed C |
3 | import 'mocha' |
4 | ||
9639bd17 | 5 | import { |
7c3b7976 | 6 | cleanupTests, |
210feb6c | 7 | flushAndRunServer, |
7c3b7976 | 8 | makeGetRequest, |
9639bd17 | 9 | ServerInfo, |
10 | setAccessTokensToServers, | |
6fad8e51 C |
11 | uploadVideo, |
12 | createVideoPlaylist, | |
13 | setDefaultVideoChannel | |
94565d52 | 14 | } from '../../../../shared/extra-utils' |
6fad8e51 | 15 | import { VideoPlaylistPrivacy } from '@shared/models' |
d8755eed C |
16 | |
17 | describe('Test services API validators', function () { | |
331128ed | 18 | let server: ServerInfo |
6fad8e51 | 19 | let playlistUUID: string |
d8755eed C |
20 | |
21 | // --------------------------------------------------------------- | |
22 | ||
23 | before(async function () { | |
24 | this.timeout(60000) | |
25 | ||
210feb6c | 26 | server = await flushAndRunServer(1) |
d8755eed | 27 | await setAccessTokensToServers([ server ]) |
6fad8e51 C |
28 | await setDefaultVideoChannel([ server ]) |
29 | ||
30 | { | |
31 | const res = await uploadVideo(server.url, server.accessToken, { name: 'my super name' }) | |
32 | server.video = res.body.video | |
33 | } | |
34 | ||
35 | { | |
36 | const res = await createVideoPlaylist({ | |
37 | url: server.url, | |
38 | token: server.accessToken, | |
39 | playlistAttrs: { | |
40 | displayName: 'super playlist', | |
41 | privacy: VideoPlaylistPrivacy.PUBLIC, | |
42 | videoChannelId: server.videoChannel.id | |
43 | } | |
44 | }) | |
45 | ||
46 | playlistUUID = res.body.videoPlaylist.uuid | |
47 | } | |
d8755eed C |
48 | }) |
49 | ||
50 | describe('Test oEmbed API validators', function () { | |
d8755eed C |
51 | |
52 | it('Should fail with an invalid url', async function () { | |
53 | const embedUrl = 'hello.com' | |
331128ed | 54 | await checkParamEmbed(server, embedUrl) |
d8755eed C |
55 | }) |
56 | ||
57 | it('Should fail with an invalid host', async function () { | |
58 | const embedUrl = 'http://hello.com/videos/watch/' + server.video.uuid | |
331128ed | 59 | await checkParamEmbed(server, embedUrl) |
d8755eed C |
60 | }) |
61 | ||
6fad8e51 | 62 | it('Should fail with an invalid element id', async function () { |
7c3b7976 | 63 | const embedUrl = `http://localhost:${server.port}/videos/watch/blabla` |
331128ed | 64 | await checkParamEmbed(server, embedUrl) |
d8755eed C |
65 | }) |
66 | ||
6fad8e51 | 67 | it('Should fail with an unknown element', async function () { |
7c3b7976 | 68 | const embedUrl = `http://localhost:${server.port}/videos/watch/88fc0165-d1f0-4a35-a51a-3b47f668689c` |
331128ed | 69 | await checkParamEmbed(server, embedUrl, 404) |
d8755eed C |
70 | }) |
71 | ||
72 | it('Should fail with an invalid path', async function () { | |
7c3b7976 | 73 | const embedUrl = `http://localhost:${server.port}/videos/watchs/${server.video.uuid}` |
d8755eed | 74 | |
331128ed | 75 | await checkParamEmbed(server, embedUrl) |
d8755eed C |
76 | }) |
77 | ||
78 | it('Should fail with an invalid max height', async function () { | |
7c3b7976 | 79 | const embedUrl = `http://localhost:${server.port}/videos/watch/${server.video.uuid}` |
d8755eed | 80 | |
331128ed | 81 | await checkParamEmbed(server, embedUrl, 400, { maxheight: 'hello' }) |
d8755eed C |
82 | }) |
83 | ||
84 | it('Should fail with an invalid max width', async function () { | |
7c3b7976 | 85 | const embedUrl = `http://localhost:${server.port}/videos/watch/${server.video.uuid}` |
d8755eed | 86 | |
331128ed | 87 | await checkParamEmbed(server, embedUrl, 400, { maxwidth: 'hello' }) |
d8755eed C |
88 | }) |
89 | ||
90 | it('Should fail with an invalid format', async function () { | |
7c3b7976 | 91 | const embedUrl = `http://localhost:${server.port}/videos/watch/${server.video.uuid}` |
d8755eed | 92 | |
331128ed | 93 | await checkParamEmbed(server, embedUrl, 400, { format: 'blabla' }) |
d8755eed C |
94 | }) |
95 | ||
96 | it('Should fail with a non supported format', async function () { | |
7c3b7976 | 97 | const embedUrl = `http://localhost:${server.port}/videos/watch/${server.video.uuid}` |
d8755eed | 98 | |
331128ed C |
99 | await checkParamEmbed(server, embedUrl, 501, { format: 'xml' }) |
100 | }) | |
101 | ||
6fad8e51 | 102 | it('Should succeed with the correct params with a video', async function () { |
7c3b7976 | 103 | const embedUrl = `http://localhost:${server.port}/videos/watch/${server.video.uuid}` |
331128ed C |
104 | const query = { |
105 | format: 'json', | |
106 | maxheight: 400, | |
107 | maxwidth: 400 | |
108 | } | |
109 | ||
110 | await checkParamEmbed(server, embedUrl, 200, query) | |
d8755eed | 111 | }) |
6fad8e51 C |
112 | |
113 | it('Should succeed with the correct params with a playlist', async function () { | |
114 | const embedUrl = `http://localhost:${server.port}/videos/watch/playlist/${playlistUUID}` | |
115 | const query = { | |
116 | format: 'json', | |
117 | maxheight: 400, | |
118 | maxwidth: 400 | |
119 | } | |
120 | ||
121 | await checkParamEmbed(server, embedUrl, 200, query) | |
122 | }) | |
d8755eed C |
123 | }) |
124 | ||
7c3b7976 C |
125 | after(async function () { |
126 | await cleanupTests([ server ]) | |
d8755eed C |
127 | }) |
128 | }) | |
331128ed C |
129 | |
130 | function checkParamEmbed (server: ServerInfo, embedUrl: string, statusCodeExpected = 400, query = {}) { | |
131 | const path = '/services/oembed' | |
132 | ||
133 | return makeGetRequest({ | |
134 | url: server.url, | |
135 | path, | |
136 | query: Object.assign(query, { url: embedUrl }), | |
331128ed C |
137 | statusCodeExpected |
138 | }) | |
139 | } |