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