]>
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 { HttpStatusCode } from '@shared/core-utils' | |
7 | import { | |
8 | buildAbsoluteFixturePath, | |
9 | ChannelsCommand, | |
10 | checkBadCountPagination, | |
11 | checkBadSortPagination, | |
12 | checkBadStartPagination, | |
13 | cleanupTests, | |
14 | createSingleServer, | |
15 | makeGetRequest, | |
16 | makePostBodyRequest, | |
17 | makePutBodyRequest, | |
18 | makeUploadRequest, | |
19 | PeerTubeServer, | |
20 | setAccessTokensToServers | |
21 | } from '@shared/extra-utils' | |
22 | import { VideoChannelUpdate } from '@shared/models' | |
23 | ||
24 | const expect = chai.expect | |
25 | ||
26 | describe('Test video channels API validator', function () { | |
27 | const videoChannelPath = '/api/v1/video-channels' | |
28 | let server: PeerTubeServer | |
29 | let accessTokenUser: string | |
30 | let command: ChannelsCommand | |
31 | ||
32 | // --------------------------------------------------------------- | |
33 | ||
34 | before(async function () { | |
35 | this.timeout(30000) | |
36 | ||
37 | server = await createSingleServer(1) | |
38 | ||
39 | await setAccessTokensToServers([ server ]) | |
40 | ||
41 | const user = { | |
42 | username: 'fake', | |
43 | password: 'fake_password' | |
44 | } | |
45 | ||
46 | { | |
47 | await server.users.create({ username: user.username, password: user.password }) | |
48 | accessTokenUser = await server.login.getAccessToken(user) | |
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 | statusCodeExpected: 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 | statusCodeExpected: 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 | statusCodeExpected: 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 | statusCodeExpected: 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 | statusCodeExpected: 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: accessTokenUser, | |
198 | fields: baseCorrectParams, | |
199 | statusCodeExpected: 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 | statusCodeExpected: HttpStatusCode.NO_CONTENT_204 | |
230 | }) | |
231 | }) | |
232 | }) | |
233 | ||
234 | describe('When updating video channel avatar/banner', 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 | statusCodeExpected: 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 | statusCodeExpected: 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 | statusCodeExpected: 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 | statusCodeExpected: 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 | statusCodeExpected: HttpStatusCode.OK_200 | |
321 | }) | |
322 | }) | |
323 | }) | |
324 | ||
325 | describe('When deleting a video channel', function () { | |
326 | it('Should fail with a non authenticated user', async function () { | |
327 | await command.delete({ token: 'coucou', channelName: 'super_channel', expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) | |
328 | }) | |
329 | ||
330 | it('Should fail with another authenticated user', async function () { | |
331 | await command.delete({ token: accessTokenUser, channelName: 'super_channel', expectedStatus: HttpStatusCode.FORBIDDEN_403 }) | |
332 | }) | |
333 | ||
334 | it('Should fail with an unknown video channel id', async function () { | |
335 | await command.delete({ channelName: 'super_channel2', expectedStatus: HttpStatusCode.NOT_FOUND_404 }) | |
336 | }) | |
337 | ||
338 | it('Should succeed with the correct parameters', async function () { | |
339 | await command.delete({ channelName: 'super_channel' }) | |
340 | }) | |
341 | ||
342 | it('Should fail to delete the last user video channel', async function () { | |
343 | await command.delete({ channelName: 'root_channel', expectedStatus: HttpStatusCode.CONFLICT_409 }) | |
344 | }) | |
345 | }) | |
346 | ||
347 | after(async function () { | |
348 | await cleanupTests([ server ]) | |
349 | }) | |
350 | }) |