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