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