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