]>
Commit | Line | Data |
---|---|---|
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ | |
2 | ||
3 | import 'mocha' | |
4 | import * as chai from 'chai' | |
5 | import { omit } from 'lodash' | |
6 | import { HttpStatusCode } from '@shared/core-utils' | |
7 | import { | |
8 | buildAbsoluteFixturePath, | |
9 | ChannelsCommand, | |
10 | checkBadCountPagination, | |
11 | checkBadSortPagination, | |
12 | checkBadStartPagination, | |
13 | cleanupTests, | |
14 | createUser, | |
15 | flushAndRunServer, | |
16 | makeGetRequest, | |
17 | makePostBodyRequest, | |
18 | makePutBodyRequest, | |
19 | makeUploadRequest, | |
20 | ServerInfo, | |
21 | setAccessTokensToServers | |
22 | } from '@shared/extra-utils' | |
23 | import { VideoChannelUpdate } from '@shared/models' | |
24 | ||
25 | const expect = chai.expect | |
26 | ||
27 | describe('Test video channels API validator', function () { | |
28 | const videoChannelPath = '/api/v1/video-channels' | |
29 | let server: ServerInfo | |
30 | let accessTokenUser: string | |
31 | let command: ChannelsCommand | |
32 | ||
33 | // --------------------------------------------------------------- | |
34 | ||
35 | before(async function () { | |
36 | this.timeout(30000) | |
37 | ||
38 | server = await flushAndRunServer(1) | |
39 | ||
40 | await setAccessTokensToServers([ server ]) | |
41 | ||
42 | const user = { | |
43 | username: 'fake', | |
44 | password: 'fake_password' | |
45 | } | |
46 | ||
47 | { | |
48 | await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) | |
49 | accessTokenUser = await server.loginCommand.getAccessToken(user) | |
50 | } | |
51 | ||
52 | command = server.channelsCommand | |
53 | }) | |
54 | ||
55 | describe('When listing a video channels', function () { | |
56 | it('Should fail with a bad start pagination', async function () { | |
57 | await checkBadStartPagination(server.url, videoChannelPath, server.accessToken) | |
58 | }) | |
59 | ||
60 | it('Should fail with a bad count pagination', async function () { | |
61 | await checkBadCountPagination(server.url, videoChannelPath, server.accessToken) | |
62 | }) | |
63 | ||
64 | it('Should fail with an incorrect sort', async function () { | |
65 | await checkBadSortPagination(server.url, videoChannelPath, server.accessToken) | |
66 | }) | |
67 | }) | |
68 | ||
69 | describe('When listing account video channels', function () { | |
70 | const accountChannelPath = '/api/v1/accounts/fake/video-channels' | |
71 | ||
72 | it('Should fail with a bad start pagination', async function () { | |
73 | await checkBadStartPagination(server.url, accountChannelPath, server.accessToken) | |
74 | }) | |
75 | ||
76 | it('Should fail with a bad count pagination', async function () { | |
77 | await checkBadCountPagination(server.url, accountChannelPath, server.accessToken) | |
78 | }) | |
79 | ||
80 | it('Should fail with an incorrect sort', async function () { | |
81 | await checkBadSortPagination(server.url, accountChannelPath, server.accessToken) | |
82 | }) | |
83 | ||
84 | it('Should fail with a unknown account', async function () { | |
85 | await server.channelsCommand.listByAccount({ accountName: 'unknown', expectedStatus: HttpStatusCode.NOT_FOUND_404 }) | |
86 | }) | |
87 | ||
88 | it('Should succeed with the correct parameters', async function () { | |
89 | await makeGetRequest({ | |
90 | url: server.url, | |
91 | path: accountChannelPath, | |
92 | statusCodeExpected: HttpStatusCode.OK_200 | |
93 | }) | |
94 | }) | |
95 | }) | |
96 | ||
97 | describe('When adding a video channel', function () { | |
98 | const baseCorrectParams = { | |
99 | name: 'super_channel', | |
100 | displayName: 'hello', | |
101 | description: 'super description', | |
102 | support: 'super support text' | |
103 | } | |
104 | ||
105 | it('Should fail with a non authenticated user', async function () { | |
106 | await makePostBodyRequest({ | |
107 | url: server.url, | |
108 | path: videoChannelPath, | |
109 | token: 'none', | |
110 | fields: baseCorrectParams, | |
111 | statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 | |
112 | }) | |
113 | }) | |
114 | ||
115 | it('Should fail with nothing', async function () { | |
116 | const fields = {} | |
117 | await makePostBodyRequest({ url: server.url, path: videoChannelPath, token: server.accessToken, fields }) | |
118 | }) | |
119 | ||
120 | it('Should fail without a name', async function () { | |
121 | const fields = omit(baseCorrectParams, 'name') | |
122 | await makePostBodyRequest({ url: server.url, path: videoChannelPath, token: server.accessToken, fields }) | |
123 | }) | |
124 | ||
125 | it('Should fail with a bad name', async function () { | |
126 | const fields = { ...baseCorrectParams, name: 'super name' } | |
127 | await makePostBodyRequest({ url: server.url, path: videoChannelPath, token: server.accessToken, fields }) | |
128 | }) | |
129 | ||
130 | it('Should fail without a name', async function () { | |
131 | const fields = omit(baseCorrectParams, 'displayName') | |
132 | await makePostBodyRequest({ url: server.url, path: videoChannelPath, token: server.accessToken, fields }) | |
133 | }) | |
134 | ||
135 | it('Should fail with a long name', async function () { | |
136 | const fields = { ...baseCorrectParams, displayName: 'super'.repeat(25) } | |
137 | await makePostBodyRequest({ url: server.url, path: videoChannelPath, token: server.accessToken, fields }) | |
138 | }) | |
139 | ||
140 | it('Should fail with a long description', async function () { | |
141 | const fields = { ...baseCorrectParams, description: 'super'.repeat(201) } | |
142 | await makePostBodyRequest({ url: server.url, path: videoChannelPath, token: server.accessToken, fields }) | |
143 | }) | |
144 | ||
145 | it('Should fail with a long support text', async function () { | |
146 | const fields = { ...baseCorrectParams, support: 'super'.repeat(201) } | |
147 | await makePostBodyRequest({ url: server.url, path: videoChannelPath, token: server.accessToken, fields }) | |
148 | }) | |
149 | ||
150 | it('Should succeed with the correct parameters', async function () { | |
151 | await makePostBodyRequest({ | |
152 | url: server.url, | |
153 | path: videoChannelPath, | |
154 | token: server.accessToken, | |
155 | fields: baseCorrectParams, | |
156 | statusCodeExpected: HttpStatusCode.OK_200 | |
157 | }) | |
158 | }) | |
159 | ||
160 | it('Should fail when adding a channel with the same username', async function () { | |
161 | await makePostBodyRequest({ | |
162 | url: server.url, | |
163 | path: videoChannelPath, | |
164 | token: server.accessToken, | |
165 | fields: baseCorrectParams, | |
166 | statusCodeExpected: HttpStatusCode.CONFLICT_409 | |
167 | }) | |
168 | }) | |
169 | }) | |
170 | ||
171 | describe('When updating a video channel', function () { | |
172 | const baseCorrectParams: VideoChannelUpdate = { | |
173 | displayName: 'hello', | |
174 | description: 'super description', | |
175 | support: 'toto', | |
176 | bulkVideosSupportUpdate: false | |
177 | } | |
178 | let path: string | |
179 | ||
180 | before(async function () { | |
181 | path = videoChannelPath + '/super_channel' | |
182 | }) | |
183 | ||
184 | it('Should fail with a non authenticated user', async function () { | |
185 | await makePutBodyRequest({ | |
186 | url: server.url, | |
187 | path, | |
188 | token: 'hi', | |
189 | fields: baseCorrectParams, | |
190 | statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 | |
191 | }) | |
192 | }) | |
193 | ||
194 | it('Should fail with another authenticated user', async function () { | |
195 | await makePutBodyRequest({ | |
196 | url: server.url, | |
197 | path, | |
198 | token: accessTokenUser, | |
199 | fields: baseCorrectParams, | |
200 | statusCodeExpected: HttpStatusCode.FORBIDDEN_403 | |
201 | }) | |
202 | }) | |
203 | ||
204 | it('Should fail with a long name', async function () { | |
205 | const fields = { ...baseCorrectParams, displayName: 'super'.repeat(25) } | |
206 | await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | |
207 | }) | |
208 | ||
209 | it('Should fail with a long description', async function () { | |
210 | const fields = { ...baseCorrectParams, description: 'super'.repeat(201) } | |
211 | await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | |
212 | }) | |
213 | ||
214 | it('Should fail with a long support text', async function () { | |
215 | const fields = { ...baseCorrectParams, support: 'super'.repeat(201) } | |
216 | await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | |
217 | }) | |
218 | ||
219 | it('Should fail with a bad bulkVideosSupportUpdate field', async function () { | |
220 | const fields = { ...baseCorrectParams, bulkVideosSupportUpdate: 'super' } | |
221 | await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | |
222 | }) | |
223 | ||
224 | it('Should succeed with the correct parameters', async function () { | |
225 | await makePutBodyRequest({ | |
226 | url: server.url, | |
227 | path, | |
228 | token: server.accessToken, | |
229 | fields: baseCorrectParams, | |
230 | statusCodeExpected: HttpStatusCode.NO_CONTENT_204 | |
231 | }) | |
232 | }) | |
233 | }) | |
234 | ||
235 | describe('When updating video channel avatar/banner', function () { | |
236 | const types = [ 'avatar', 'banner' ] | |
237 | let path: string | |
238 | ||
239 | before(async function () { | |
240 | path = videoChannelPath + '/super_channel' | |
241 | }) | |
242 | ||
243 | it('Should fail with an incorrect input file', async function () { | |
244 | for (const type of types) { | |
245 | const fields = {} | |
246 | const attaches = { | |
247 | [type + 'file']: buildAbsoluteFixturePath('video_short.mp4') | |
248 | } | |
249 | ||
250 | await makeUploadRequest({ url: server.url, path: `${path}/${type}/pick`, token: server.accessToken, fields, attaches }) | |
251 | } | |
252 | }) | |
253 | ||
254 | it('Should fail with a big file', async function () { | |
255 | for (const type of types) { | |
256 | const fields = {} | |
257 | const attaches = { | |
258 | [type + 'file']: buildAbsoluteFixturePath('avatar-big.png') | |
259 | } | |
260 | await makeUploadRequest({ url: server.url, path: `${path}/${type}/pick`, token: server.accessToken, fields, attaches }) | |
261 | } | |
262 | }) | |
263 | ||
264 | it('Should fail with an unauthenticated user', async function () { | |
265 | for (const type of types) { | |
266 | const fields = {} | |
267 | const attaches = { | |
268 | [type + 'file']: buildAbsoluteFixturePath('avatar.png') | |
269 | } | |
270 | await makeUploadRequest({ | |
271 | url: server.url, | |
272 | path: `${path}/${type}/pick`, | |
273 | fields, | |
274 | attaches, | |
275 | statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 | |
276 | }) | |
277 | } | |
278 | }) | |
279 | ||
280 | it('Should succeed with the correct params', async function () { | |
281 | for (const type of types) { | |
282 | const fields = {} | |
283 | const attaches = { | |
284 | [type + 'file']: buildAbsoluteFixturePath('avatar.png') | |
285 | } | |
286 | await makeUploadRequest({ | |
287 | url: server.url, | |
288 | path: `${path}/${type}/pick`, | |
289 | token: server.accessToken, | |
290 | fields, | |
291 | attaches, | |
292 | statusCodeExpected: HttpStatusCode.OK_200 | |
293 | }) | |
294 | } | |
295 | }) | |
296 | }) | |
297 | ||
298 | describe('When getting a video channel', function () { | |
299 | it('Should return the list of the video channels with nothing', async function () { | |
300 | const res = await makeGetRequest({ | |
301 | url: server.url, | |
302 | path: videoChannelPath, | |
303 | statusCodeExpected: HttpStatusCode.OK_200 | |
304 | }) | |
305 | ||
306 | expect(res.body.data).to.be.an('array') | |
307 | }) | |
308 | ||
309 | it('Should return 404 with an incorrect video channel', async function () { | |
310 | await makeGetRequest({ | |
311 | url: server.url, | |
312 | path: videoChannelPath + '/super_channel2', | |
313 | statusCodeExpected: HttpStatusCode.NOT_FOUND_404 | |
314 | }) | |
315 | }) | |
316 | ||
317 | it('Should succeed with the correct parameters', async function () { | |
318 | await makeGetRequest({ | |
319 | url: server.url, | |
320 | path: videoChannelPath + '/super_channel', | |
321 | statusCodeExpected: HttpStatusCode.OK_200 | |
322 | }) | |
323 | }) | |
324 | }) | |
325 | ||
326 | describe('When deleting a video channel', function () { | |
327 | it('Should fail with a non authenticated user', async function () { | |
328 | await command.delete({ token: 'coucou', channelName: 'super_channel', expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) | |
329 | }) | |
330 | ||
331 | it('Should fail with another authenticated user', async function () { | |
332 | await command.delete({ token: accessTokenUser, channelName: 'super_channel', expectedStatus: HttpStatusCode.FORBIDDEN_403 }) | |
333 | }) | |
334 | ||
335 | it('Should fail with an unknown video channel id', async function () { | |
336 | await command.delete({ channelName: 'super_channel2', expectedStatus: HttpStatusCode.NOT_FOUND_404 }) | |
337 | }) | |
338 | ||
339 | it('Should succeed with the correct parameters', async function () { | |
340 | await command.delete({ channelName: 'super_channel' }) | |
341 | }) | |
342 | ||
343 | it('Should fail to delete the last user video channel', async function () { | |
344 | await command.delete({ channelName: 'root_channel', expectedStatus: HttpStatusCode.CONFLICT_409 }) | |
345 | }) | |
346 | }) | |
347 | ||
348 | after(async function () { | |
349 | await cleanupTests([ server ]) | |
350 | }) | |
351 | }) |