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