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