]>
Commit | Line | Data |
---|---|---|
d8755eed C |
1 | /* tslint:disable:no-unused-expression */ |
2 | ||
d8755eed C |
3 | import 'mocha' |
4 | ||
331128ed | 5 | import { flushTests, killallServers, makeGetRequest, runServer, ServerInfo, setAccessTokensToServers, uploadVideo } from '../../utils' |
d8755eed C |
6 | |
7 | describe('Test services API validators', function () { | |
331128ed | 8 | let server: ServerInfo |
d8755eed C |
9 | |
10 | // --------------------------------------------------------------- | |
11 | ||
12 | before(async function () { | |
13 | this.timeout(60000) | |
14 | ||
15 | await flushTests() | |
16 | ||
17 | server = await runServer(1) | |
18 | await setAccessTokensToServers([ server ]) | |
19 | ||
331128ed C |
20 | const res = await uploadVideo(server.url, server.accessToken, { name: 'my super name' }) |
21 | server.video = res.body.video | |
d8755eed C |
22 | }) |
23 | ||
24 | describe('Test oEmbed API validators', function () { | |
d8755eed C |
25 | |
26 | it('Should fail with an invalid url', async function () { | |
27 | const embedUrl = 'hello.com' | |
331128ed | 28 | await checkParamEmbed(server, embedUrl) |
d8755eed C |
29 | }) |
30 | ||
31 | it('Should fail with an invalid host', async function () { | |
32 | const embedUrl = 'http://hello.com/videos/watch/' + server.video.uuid | |
331128ed | 33 | await checkParamEmbed(server, embedUrl) |
d8755eed C |
34 | }) |
35 | ||
36 | it('Should fail with an invalid video id', async function () { | |
37 | const embedUrl = 'http://localhost:9001/videos/watch/blabla' | |
331128ed | 38 | await checkParamEmbed(server, embedUrl) |
d8755eed C |
39 | }) |
40 | ||
41 | it('Should fail with an unknown video', async function () { | |
42 | const embedUrl = 'http://localhost:9001/videos/watch/88fc0165-d1f0-4a35-a51a-3b47f668689c' | |
331128ed | 43 | await checkParamEmbed(server, embedUrl, 404) |
d8755eed C |
44 | }) |
45 | ||
46 | it('Should fail with an invalid path', async function () { | |
47 | const embedUrl = 'http://localhost:9001/videos/watchs/' + server.video.uuid | |
48 | ||
331128ed | 49 | await checkParamEmbed(server, embedUrl) |
d8755eed C |
50 | }) |
51 | ||
52 | it('Should fail with an invalid max height', async function () { | |
53 | const embedUrl = 'http://localhost:9001/videos/watch/' + server.video.uuid | |
54 | ||
331128ed | 55 | await checkParamEmbed(server, embedUrl, 400, { maxheight: 'hello' }) |
d8755eed C |
56 | }) |
57 | ||
58 | it('Should fail with an invalid max width', async function () { | |
59 | const embedUrl = 'http://localhost:9001/videos/watch/' + server.video.uuid | |
60 | ||
331128ed | 61 | await checkParamEmbed(server, embedUrl, 400, { maxwidth: 'hello' }) |
d8755eed C |
62 | }) |
63 | ||
64 | it('Should fail with an invalid format', async function () { | |
65 | const embedUrl = 'http://localhost:9001/videos/watch/' + server.video.uuid | |
66 | ||
331128ed | 67 | await checkParamEmbed(server, embedUrl, 400, { format: 'blabla' }) |
d8755eed C |
68 | }) |
69 | ||
70 | it('Should fail with a non supported format', async function () { | |
71 | const embedUrl = 'http://localhost:9001/videos/watch/' + server.video.uuid | |
72 | ||
331128ed C |
73 | await checkParamEmbed(server, embedUrl, 501, { format: 'xml' }) |
74 | }) | |
75 | ||
76 | it('Should succeed with the correct params', async function () { | |
77 | const embedUrl = 'http://localhost:9001/videos/watch/' + server.video.uuid | |
78 | const query = { | |
79 | format: 'json', | |
80 | maxheight: 400, | |
81 | maxwidth: 400 | |
82 | } | |
83 | ||
84 | await checkParamEmbed(server, embedUrl, 200, query) | |
d8755eed C |
85 | }) |
86 | }) | |
87 | ||
88 | after(async function () { | |
89 | killallServers([ server ]) | |
90 | ||
91 | // Keep the logs if the test failed | |
92 | if (this['ok']) { | |
93 | await flushTests() | |
94 | } | |
95 | }) | |
96 | }) | |
331128ed C |
97 | |
98 | function checkParamEmbed (server: ServerInfo, embedUrl: string, statusCodeExpected = 400, query = {}) { | |
99 | const path = '/services/oembed' | |
100 | ||
101 | return makeGetRequest({ | |
102 | url: server.url, | |
103 | path, | |
104 | query: Object.assign(query, { url: embedUrl }), | |
331128ed C |
105 | statusCodeExpected |
106 | }) | |
107 | } |