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