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