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