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