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