]>
Commit | Line | Data |
---|---|---|
418d092a C |
1 | /* tslint:disable:no-unused-expression */ |
2 | ||
418d092a | 3 | import 'mocha' |
418d092a | 4 | import { |
df0b219d | 5 | addVideoInPlaylist, |
7c3b7976 | 6 | cleanupTests, |
07b1a18a C |
7 | createVideoPlaylist, |
8 | deleteVideoPlaylist, | |
7c3b7976 | 9 | flushAndRunServer, |
df0b219d C |
10 | generateUserAccessToken, |
11 | getAccountPlaylistsListWithToken, | |
07b1a18a | 12 | getVideoPlaylist, |
418d092a | 13 | immutableAssign, |
418d092a | 14 | makeGetRequest, |
df0b219d C |
15 | removeVideoFromPlaylist, |
16 | reorderVideosPlaylist, | |
418d092a | 17 | ServerInfo, |
7c3b7976 C |
18 | setAccessTokensToServers, |
19 | setDefaultVideoChannel, | |
07b1a18a | 20 | updateVideoPlaylist, |
df0b219d C |
21 | updateVideoPlaylistElement, |
22 | uploadVideoAndGetId | |
94565d52 | 23 | } from '../../../../shared/extra-utils' |
418d092a C |
24 | import { |
25 | checkBadCountPagination, | |
26 | checkBadSortPagination, | |
27 | checkBadStartPagination | |
94565d52 | 28 | } from '../../../../shared/extra-utils/requests/check-api-params' |
07b1a18a | 29 | import { VideoPlaylistPrivacy } from '../../../../shared/models/videos/playlist/video-playlist-privacy.model' |
df0b219d | 30 | import { VideoPlaylistType } from '../../../../shared/models/videos/playlist/video-playlist-type.model' |
418d092a C |
31 | |
32 | describe('Test video playlists API validator', function () { | |
418d092a | 33 | let server: ServerInfo |
df0b219d | 34 | let userAccessToken: string |
07b1a18a | 35 | let playlistUUID: string |
c5e4e36d | 36 | let privatePlaylistUUID: string |
df0b219d | 37 | let watchLaterPlaylistId: number |
07b1a18a C |
38 | let videoId: number |
39 | let videoId2: number | |
418d092a C |
40 | |
41 | // --------------------------------------------------------------- | |
42 | ||
43 | before(async function () { | |
44 | this.timeout(30000) | |
45 | ||
210feb6c | 46 | server = await flushAndRunServer(1) |
418d092a C |
47 | |
48 | await setAccessTokensToServers([ server ]) | |
c5e4e36d | 49 | await setDefaultVideoChannel([ server ]) |
418d092a | 50 | |
df0b219d C |
51 | userAccessToken = await generateUserAccessToken(server, 'user1') |
52 | videoId = (await uploadVideoAndGetId({ server, videoName: 'video 1' })).id | |
53 | videoId2 = (await uploadVideoAndGetId({ server, videoName: 'video 2' })).id | |
07b1a18a C |
54 | |
55 | { | |
df0b219d C |
56 | const res = await getAccountPlaylistsListWithToken(server.url, server.accessToken, 'root',0, 5, VideoPlaylistType.WATCH_LATER) |
57 | watchLaterPlaylistId = res.body.data[0].id | |
07b1a18a C |
58 | } |
59 | ||
60 | { | |
61 | const res = await createVideoPlaylist({ | |
62 | url: server.url, | |
63 | token: server.accessToken, | |
64 | playlistAttrs: { | |
65 | displayName: 'super playlist', | |
c5e4e36d C |
66 | privacy: VideoPlaylistPrivacy.PUBLIC, |
67 | videoChannelId: server.videoChannel.id | |
07b1a18a C |
68 | } |
69 | }) | |
70 | playlistUUID = res.body.videoPlaylist.uuid | |
71 | } | |
c5e4e36d C |
72 | |
73 | { | |
74 | const res = await createVideoPlaylist({ | |
75 | url: server.url, | |
76 | token: server.accessToken, | |
77 | playlistAttrs: { | |
78 | displayName: 'private', | |
79 | privacy: VideoPlaylistPrivacy.PRIVATE | |
80 | } | |
81 | }) | |
82 | privatePlaylistUUID = res.body.videoPlaylist.uuid | |
83 | } | |
418d092a C |
84 | }) |
85 | ||
07b1a18a | 86 | describe('When listing playlists', function () { |
418d092a C |
87 | const globalPath = '/api/v1/video-playlists' |
88 | const accountPath = '/api/v1/accounts/root/video-playlists' | |
89 | const videoChannelPath = '/api/v1/video-channels/root_channel/video-playlists' | |
90 | ||
91 | it('Should fail with a bad start pagination', async function () { | |
92 | await checkBadStartPagination(server.url, globalPath, server.accessToken) | |
93 | await checkBadStartPagination(server.url, accountPath, server.accessToken) | |
94 | await checkBadStartPagination(server.url, videoChannelPath, server.accessToken) | |
95 | }) | |
96 | ||
97 | it('Should fail with a bad count pagination', async function () { | |
98 | await checkBadCountPagination(server.url, globalPath, server.accessToken) | |
99 | await checkBadCountPagination(server.url, accountPath, server.accessToken) | |
100 | await checkBadCountPagination(server.url, videoChannelPath, server.accessToken) | |
101 | }) | |
102 | ||
103 | it('Should fail with an incorrect sort', async function () { | |
104 | await checkBadSortPagination(server.url, globalPath, server.accessToken) | |
105 | await checkBadSortPagination(server.url, accountPath, server.accessToken) | |
106 | await checkBadSortPagination(server.url, videoChannelPath, server.accessToken) | |
107 | }) | |
108 | ||
df0b219d C |
109 | it('Should fail with a bad playlist type', async function () { |
110 | await makeGetRequest({ url: server.url, path: globalPath, query: { playlistType: 3 } }) | |
111 | await makeGetRequest({ url: server.url, path: accountPath, query: { playlistType: 3 } }) | |
112 | await makeGetRequest({ url: server.url, path: videoChannelPath, query: { playlistType: 3 } }) | |
113 | }) | |
114 | ||
418d092a C |
115 | it('Should fail with a bad account parameter', async function () { |
116 | const accountPath = '/api/v1/accounts/root2/video-playlists' | |
117 | ||
118 | await makeGetRequest({ url: server.url, path: accountPath, statusCodeExpected: 404, token: server.accessToken }) | |
119 | }) | |
120 | ||
121 | it('Should fail with a bad video channel parameter', async function () { | |
122 | const accountPath = '/api/v1/video-channels/bad_channel/video-playlists' | |
123 | ||
124 | await makeGetRequest({ url: server.url, path: accountPath, statusCodeExpected: 404, token: server.accessToken }) | |
125 | }) | |
126 | ||
127 | it('Should success with the correct parameters', async function () { | |
128 | await makeGetRequest({ url: server.url, path: globalPath, statusCodeExpected: 200, token: server.accessToken }) | |
129 | await makeGetRequest({ url: server.url, path: accountPath, statusCodeExpected: 200, token: server.accessToken }) | |
130 | await makeGetRequest({ url: server.url, path: videoChannelPath, statusCodeExpected: 200, token: server.accessToken }) | |
131 | }) | |
132 | }) | |
133 | ||
07b1a18a | 134 | describe('When listing videos of a playlist', function () { |
418d092a C |
135 | const path = '/api/v1/video-playlists' |
136 | ||
137 | it('Should fail with a bad start pagination', async function () { | |
138 | await checkBadStartPagination(server.url, path, server.accessToken) | |
139 | }) | |
140 | ||
141 | it('Should fail with a bad count pagination', async function () { | |
142 | await checkBadCountPagination(server.url, path, server.accessToken) | |
143 | }) | |
144 | ||
07b1a18a | 145 | it('Should fail with a bad filter', async function () { |
418d092a C |
146 | await checkBadSortPagination(server.url, path, server.accessToken) |
147 | }) | |
148 | }) | |
149 | ||
07b1a18a C |
150 | describe('When getting a video playlist', function () { |
151 | it('Should fail with a bad id or uuid', async function () { | |
152 | await getVideoPlaylist(server.url, 'toto', 400) | |
153 | }) | |
154 | ||
155 | it('Should fail with an unknown playlist', async function () { | |
156 | await getVideoPlaylist(server.url, 42, 404) | |
157 | }) | |
158 | ||
159 | it('Should fail to get an unlisted playlist with the number id', async function () { | |
160 | const res = await createVideoPlaylist({ | |
161 | url: server.url, | |
162 | token: server.accessToken, | |
163 | playlistAttrs: { | |
164 | displayName: 'super playlist', | |
165 | privacy: VideoPlaylistPrivacy.UNLISTED | |
166 | } | |
167 | }) | |
168 | const playlist = res.body.videoPlaylist | |
169 | ||
170 | await getVideoPlaylist(server.url, playlist.id, 404) | |
171 | await getVideoPlaylist(server.url, playlist.uuid, 200) | |
172 | }) | |
173 | ||
174 | it('Should succeed with the correct params', async function () { | |
175 | await getVideoPlaylist(server.url, playlistUUID, 200) | |
176 | }) | |
177 | }) | |
178 | ||
179 | describe('When creating/updating a video playlist', function () { | |
df0b219d C |
180 | const getBase = (playlistAttrs: any = {}, wrapper: any = {}) => { |
181 | return Object.assign({ | |
182 | expectedStatus: 400, | |
183 | url: server.url, | |
184 | token: server.accessToken, | |
185 | playlistAttrs: Object.assign({ | |
186 | displayName: 'display name', | |
187 | privacy: VideoPlaylistPrivacy.UNLISTED, | |
c5e4e36d C |
188 | thumbnailfile: 'thumbnail.jpg', |
189 | videoChannelId: server.videoChannel.id | |
df0b219d C |
190 | }, playlistAttrs) |
191 | }, wrapper) | |
192 | } | |
193 | const getUpdate = (params: any, playlistId: number | string) => { | |
194 | return immutableAssign(params, { playlistId: playlistId }) | |
195 | } | |
07b1a18a C |
196 | |
197 | it('Should fail with an unauthenticated user', async function () { | |
df0b219d | 198 | const params = getBase({}, { token: null, expectedStatus: 401 }) |
07b1a18a | 199 | |
df0b219d C |
200 | await createVideoPlaylist(params) |
201 | await updateVideoPlaylist(getUpdate(params, playlistUUID)) | |
07b1a18a C |
202 | }) |
203 | ||
204 | it('Should fail without displayName', async function () { | |
df0b219d | 205 | const params = getBase({ displayName: undefined }) |
07b1a18a | 206 | |
df0b219d C |
207 | await createVideoPlaylist(params) |
208 | await updateVideoPlaylist(getUpdate(params, playlistUUID)) | |
07b1a18a C |
209 | }) |
210 | ||
211 | it('Should fail with an incorrect display name', async function () { | |
df0b219d | 212 | const params = getBase({ displayName: 's'.repeat(300) }) |
07b1a18a | 213 | |
df0b219d C |
214 | await createVideoPlaylist(params) |
215 | await updateVideoPlaylist(getUpdate(params, playlistUUID)) | |
07b1a18a C |
216 | }) |
217 | ||
218 | it('Should fail with an incorrect description', async function () { | |
df0b219d | 219 | const params = getBase({ description: 't' }) |
07b1a18a | 220 | |
df0b219d C |
221 | await createVideoPlaylist(params) |
222 | await updateVideoPlaylist(getUpdate(params, playlistUUID)) | |
07b1a18a C |
223 | }) |
224 | ||
225 | it('Should fail with an incorrect privacy', async function () { | |
df0b219d | 226 | const params = getBase({ privacy: 45 }) |
07b1a18a | 227 | |
df0b219d C |
228 | await createVideoPlaylist(params) |
229 | await updateVideoPlaylist(getUpdate(params, playlistUUID)) | |
07b1a18a C |
230 | }) |
231 | ||
232 | it('Should fail with an unknown video channel id', async function () { | |
df0b219d | 233 | const params = getBase({ videoChannelId: 42 }, { expectedStatus: 404 }) |
07b1a18a | 234 | |
df0b219d C |
235 | await createVideoPlaylist(params) |
236 | await updateVideoPlaylist(getUpdate(params, playlistUUID)) | |
07b1a18a C |
237 | }) |
238 | ||
239 | it('Should fail with an incorrect thumbnail file', async function () { | |
df0b219d | 240 | const params = getBase({ thumbnailfile: 'avatar.png' }) |
07b1a18a | 241 | |
df0b219d C |
242 | await createVideoPlaylist(params) |
243 | await updateVideoPlaylist(getUpdate(params, playlistUUID)) | |
07b1a18a C |
244 | }) |
245 | ||
c5e4e36d C |
246 | it('Should fail to set "public" a playlist not assigned to a channel', async function () { |
247 | const params = getBase({ privacy: VideoPlaylistPrivacy.PUBLIC, videoChannelId: undefined }) | |
248 | const params2 = getBase({ privacy: VideoPlaylistPrivacy.PUBLIC, videoChannelId: 'null' }) | |
249 | const params3 = getBase({ privacy: undefined, videoChannelId: 'null' }) | |
250 | ||
251 | await createVideoPlaylist(params) | |
252 | await createVideoPlaylist(params2) | |
253 | await updateVideoPlaylist(getUpdate(params, privatePlaylistUUID)) | |
254 | await updateVideoPlaylist(getUpdate(params2, playlistUUID)) | |
255 | await updateVideoPlaylist(getUpdate(params3, playlistUUID)) | |
256 | }) | |
257 | ||
07b1a18a | 258 | it('Should fail with an unknown playlist to update', async function () { |
df0b219d C |
259 | await updateVideoPlaylist(getUpdate( |
260 | getBase({}, { expectedStatus: 404 }), | |
261 | 42 | |
262 | )) | |
07b1a18a C |
263 | }) |
264 | ||
265 | it('Should fail to update a playlist of another user', async function () { | |
df0b219d C |
266 | await updateVideoPlaylist(getUpdate( |
267 | getBase({}, { token: userAccessToken, expectedStatus: 403 }), | |
268 | playlistUUID | |
269 | )) | |
07b1a18a C |
270 | }) |
271 | ||
272 | it('Should fail to update to private a public/unlisted playlist', async function () { | |
df0b219d C |
273 | const params = getBase({ privacy: VideoPlaylistPrivacy.PUBLIC }, { expectedStatus: 200 }) |
274 | ||
275 | const res = await createVideoPlaylist(params) | |
07b1a18a C |
276 | const playlist = res.body.videoPlaylist |
277 | ||
c5e4e36d | 278 | const paramsUpdate = getBase({ privacy: VideoPlaylistPrivacy.PRIVATE }, { expectedStatus: 400 }) |
df0b219d C |
279 | |
280 | await updateVideoPlaylist(getUpdate(paramsUpdate, playlist.id)) | |
281 | }) | |
282 | ||
283 | it('Should fail to update the watch later playlist', async function () { | |
284 | await updateVideoPlaylist(getUpdate( | |
c5e4e36d | 285 | getBase({}, { expectedStatus: 400 }), |
df0b219d C |
286 | watchLaterPlaylistId |
287 | )) | |
07b1a18a C |
288 | }) |
289 | ||
290 | it('Should succeed with the correct params', async function () { | |
df0b219d C |
291 | { |
292 | const params = getBase({}, { expectedStatus: 200 }) | |
293 | await createVideoPlaylist(params) | |
07b1a18a C |
294 | } |
295 | ||
df0b219d C |
296 | { |
297 | const params = getBase({}, { expectedStatus: 204 }) | |
298 | await updateVideoPlaylist(getUpdate(params, playlistUUID)) | |
299 | } | |
07b1a18a C |
300 | }) |
301 | }) | |
302 | ||
303 | describe('When adding an element in a playlist', function () { | |
df0b219d C |
304 | const getBase = (elementAttrs: any = {}, wrapper: any = {}) => { |
305 | return Object.assign({ | |
306 | expectedStatus: 400, | |
07b1a18a | 307 | url: server.url, |
df0b219d | 308 | token: server.accessToken, |
07b1a18a | 309 | playlistId: playlistUUID, |
df0b219d C |
310 | elementAttrs: Object.assign({ |
311 | videoId: videoId, | |
312 | startTimestamp: 2, | |
313 | stopTimestamp: 3 | |
314 | }, elementAttrs) | |
315 | }, wrapper) | |
316 | } | |
317 | ||
318 | it('Should fail with an unauthenticated user', async function () { | |
319 | const params = getBase({}, { token: null, expectedStatus: 401 }) | |
320 | await addVideoInPlaylist(params) | |
07b1a18a C |
321 | }) |
322 | ||
323 | it('Should fail with the playlist of another user', async function () { | |
df0b219d C |
324 | const params = getBase({}, { token: userAccessToken, expectedStatus: 403 }) |
325 | await addVideoInPlaylist(params) | |
07b1a18a C |
326 | }) |
327 | ||
328 | it('Should fail with an unknown or incorrect playlist id', async function () { | |
df0b219d C |
329 | { |
330 | const params = getBase({}, { playlistId: 'toto' }) | |
331 | await addVideoInPlaylist(params) | |
332 | } | |
07b1a18a | 333 | |
df0b219d C |
334 | { |
335 | const params = getBase({}, { playlistId: 42, expectedStatus: 404 }) | |
336 | await addVideoInPlaylist(params) | |
337 | } | |
07b1a18a C |
338 | }) |
339 | ||
340 | it('Should fail with an unknown or incorrect video id', async function () { | |
df0b219d C |
341 | const params = getBase({ videoId: 42 }, { expectedStatus: 404 }) |
342 | await addVideoInPlaylist(params) | |
07b1a18a C |
343 | }) |
344 | ||
345 | it('Should fail with a bad start/stop timestamp', async function () { | |
df0b219d C |
346 | { |
347 | const params = getBase({ startTimestamp: -42 }) | |
348 | await addVideoInPlaylist(params) | |
349 | } | |
07b1a18a | 350 | |
df0b219d C |
351 | { |
352 | const params = getBase({ stopTimestamp: 'toto' as any }) | |
353 | await addVideoInPlaylist(params) | |
354 | } | |
07b1a18a C |
355 | }) |
356 | ||
357 | it('Succeed with the correct params', async function () { | |
df0b219d C |
358 | const params = getBase({}, { expectedStatus: 200 }) |
359 | await addVideoInPlaylist(params) | |
07b1a18a C |
360 | }) |
361 | ||
362 | it('Should fail if the video was already added in the playlist', async function () { | |
df0b219d C |
363 | const params = getBase({}, { expectedStatus: 409 }) |
364 | await addVideoInPlaylist(params) | |
07b1a18a C |
365 | }) |
366 | }) | |
367 | ||
368 | describe('When updating an element in a playlist', function () { | |
df0b219d C |
369 | const getBase = (elementAttrs: any = {}, wrapper: any = {}) => { |
370 | return Object.assign({ | |
07b1a18a | 371 | url: server.url, |
df0b219d C |
372 | token: server.accessToken, |
373 | elementAttrs: Object.assign({ | |
374 | startTimestamp: 1, | |
375 | stopTimestamp: 2 | |
376 | }, elementAttrs), | |
07b1a18a C |
377 | videoId: videoId, |
378 | playlistId: playlistUUID, | |
df0b219d C |
379 | expectedStatus: 400 |
380 | }, wrapper) | |
381 | } | |
382 | ||
383 | it('Should fail with an unauthenticated user', async function () { | |
384 | const params = getBase({}, { token: null, expectedStatus: 401 }) | |
385 | await updateVideoPlaylistElement(params) | |
07b1a18a C |
386 | }) |
387 | ||
388 | it('Should fail with the playlist of another user', async function () { | |
df0b219d C |
389 | const params = getBase({}, { token: userAccessToken, expectedStatus: 403 }) |
390 | await updateVideoPlaylistElement(params) | |
07b1a18a C |
391 | }) |
392 | ||
393 | it('Should fail with an unknown or incorrect playlist id', async function () { | |
df0b219d C |
394 | { |
395 | const params = getBase({}, { playlistId: 'toto' }) | |
396 | await updateVideoPlaylistElement(params) | |
397 | } | |
07b1a18a | 398 | |
df0b219d C |
399 | { |
400 | const params = getBase({}, { playlistId: 42, expectedStatus: 404 }) | |
401 | await updateVideoPlaylistElement(params) | |
402 | } | |
07b1a18a C |
403 | }) |
404 | ||
405 | it('Should fail with an unknown or incorrect video id', async function () { | |
df0b219d C |
406 | { |
407 | const params = getBase({}, { videoId: 'toto' }) | |
408 | await updateVideoPlaylistElement(params) | |
409 | } | |
07b1a18a | 410 | |
df0b219d C |
411 | { |
412 | const params = getBase({}, { videoId: 42, expectedStatus: 404 }) | |
413 | await updateVideoPlaylistElement(params) | |
414 | } | |
07b1a18a C |
415 | }) |
416 | ||
417 | it('Should fail with a bad start/stop timestamp', async function () { | |
df0b219d C |
418 | { |
419 | const params = getBase({ startTimestamp: 'toto' as any }) | |
420 | await updateVideoPlaylistElement(params) | |
421 | } | |
07b1a18a | 422 | |
df0b219d C |
423 | { |
424 | const params = getBase({ stopTimestamp: -42 }) | |
425 | await updateVideoPlaylistElement(params) | |
426 | } | |
07b1a18a C |
427 | }) |
428 | ||
429 | it('Should fail with an unknown element', async function () { | |
df0b219d C |
430 | const params = getBase({}, { videoId: videoId2, expectedStatus: 404 }) |
431 | await updateVideoPlaylistElement(params) | |
07b1a18a C |
432 | }) |
433 | ||
434 | it('Succeed with the correct params', async function () { | |
df0b219d C |
435 | const params = getBase({}, { expectedStatus: 204 }) |
436 | await updateVideoPlaylistElement(params) | |
07b1a18a C |
437 | }) |
438 | }) | |
439 | ||
440 | describe('When reordering elements of a playlist', function () { | |
441 | let videoId3: number | |
442 | let videoId4: number | |
443 | ||
df0b219d C |
444 | const getBase = (elementAttrs: any = {}, wrapper: any = {}) => { |
445 | return Object.assign({ | |
07b1a18a C |
446 | url: server.url, |
447 | token: server.accessToken, | |
448 | playlistId: playlistUUID, | |
df0b219d C |
449 | elementAttrs: Object.assign({ |
450 | startPosition: 1, | |
451 | insertAfterPosition: 2, | |
452 | reorderLength: 3 | |
453 | }, elementAttrs), | |
454 | expectedStatus: 400 | |
455 | }, wrapper) | |
456 | } | |
07b1a18a | 457 | |
df0b219d C |
458 | before(async function () { |
459 | videoId3 = (await uploadVideoAndGetId({ server, videoName: 'video 3' })).id | |
460 | videoId4 = (await uploadVideoAndGetId({ server, videoName: 'video 4' })).id | |
461 | ||
462 | for (let id of [ videoId3, videoId4 ]) { | |
463 | await addVideoInPlaylist({ | |
464 | url: server.url, | |
465 | token: server.accessToken, | |
466 | playlistId: playlistUUID, | |
467 | elementAttrs: { videoId: id } | |
468 | }) | |
469 | } | |
07b1a18a C |
470 | }) |
471 | ||
472 | it('Should fail with an unauthenticated user', async function () { | |
df0b219d C |
473 | const params = getBase({}, { token: null, expectedStatus: 401 }) |
474 | await reorderVideosPlaylist(params) | |
07b1a18a C |
475 | }) |
476 | ||
477 | it('Should fail with the playlist of another user', async function () { | |
df0b219d C |
478 | const params = getBase({}, { token: userAccessToken, expectedStatus: 403 }) |
479 | await reorderVideosPlaylist(params) | |
07b1a18a C |
480 | }) |
481 | ||
482 | it('Should fail with an invalid playlist', async function () { | |
df0b219d C |
483 | { |
484 | const params = getBase({}, { playlistId: 'toto' }) | |
485 | await reorderVideosPlaylist(params) | |
486 | } | |
07b1a18a | 487 | |
df0b219d C |
488 | { |
489 | const params = getBase({}, { playlistId: 42, expectedStatus: 404 }) | |
490 | await reorderVideosPlaylist(params) | |
491 | } | |
07b1a18a C |
492 | }) |
493 | ||
494 | it('Should fail with an invalid start position', async function () { | |
df0b219d C |
495 | { |
496 | const params = getBase({ startPosition: -1 }) | |
497 | await reorderVideosPlaylist(params) | |
498 | } | |
07b1a18a | 499 | |
df0b219d C |
500 | { |
501 | const params = getBase({ startPosition: 'toto' as any }) | |
502 | await reorderVideosPlaylist(params) | |
503 | } | |
07b1a18a | 504 | |
df0b219d C |
505 | { |
506 | const params = getBase({ startPosition: 42 }) | |
507 | await reorderVideosPlaylist(params) | |
508 | } | |
07b1a18a C |
509 | }) |
510 | ||
511 | it('Should fail with an invalid insert after position', async function () { | |
df0b219d C |
512 | { |
513 | const params = getBase({ insertAfterPosition: 'toto' as any }) | |
514 | await reorderVideosPlaylist(params) | |
515 | } | |
07b1a18a | 516 | |
df0b219d C |
517 | { |
518 | const params = getBase({ insertAfterPosition: -2 }) | |
519 | await reorderVideosPlaylist(params) | |
520 | } | |
07b1a18a | 521 | |
df0b219d C |
522 | { |
523 | const params = getBase({ insertAfterPosition: 42 }) | |
524 | await reorderVideosPlaylist(params) | |
525 | } | |
07b1a18a C |
526 | }) |
527 | ||
528 | it('Should fail with an invalid reorder length', async function () { | |
df0b219d C |
529 | { |
530 | const params = getBase({ reorderLength: 'toto' as any }) | |
531 | await reorderVideosPlaylist(params) | |
532 | } | |
07b1a18a | 533 | |
df0b219d C |
534 | { |
535 | const params = getBase({ reorderLength: -2 }) | |
536 | await reorderVideosPlaylist(params) | |
537 | } | |
07b1a18a | 538 | |
df0b219d C |
539 | { |
540 | const params = getBase({ reorderLength: 42 }) | |
541 | await reorderVideosPlaylist(params) | |
542 | } | |
07b1a18a C |
543 | }) |
544 | ||
545 | it('Succeed with the correct params', async function () { | |
df0b219d C |
546 | const params = getBase({}, { expectedStatus: 204 }) |
547 | await reorderVideosPlaylist(params) | |
07b1a18a C |
548 | }) |
549 | }) | |
550 | ||
0b16f5f2 C |
551 | describe('When checking exists in playlist endpoint', function () { |
552 | const path = '/api/v1/users/me/video-playlists/videos-exist' | |
553 | ||
554 | it('Should fail with an unauthenticated user', async function () { | |
555 | await makeGetRequest({ | |
556 | url: server.url, | |
557 | path, | |
558 | query: { videoIds: [ 1, 2 ] }, | |
559 | statusCodeExpected: 401 | |
560 | }) | |
561 | }) | |
562 | ||
563 | it('Should fail with invalid video ids', async function () { | |
564 | await makeGetRequest({ | |
565 | url: server.url, | |
566 | token: server.accessToken, | |
567 | path, | |
568 | query: { videoIds: 'toto' } | |
569 | }) | |
570 | ||
571 | await makeGetRequest({ | |
572 | url: server.url, | |
573 | token: server.accessToken, | |
574 | path, | |
575 | query: { videoIds: [ 'toto' ] } | |
576 | }) | |
577 | ||
578 | await makeGetRequest({ | |
579 | url: server.url, | |
580 | token: server.accessToken, | |
581 | path, | |
582 | query: { videoIds: [ 1, 'toto' ] } | |
583 | }) | |
584 | }) | |
585 | ||
586 | it('Should succeed with the correct params', async function () { | |
587 | await makeGetRequest({ | |
588 | url: server.url, | |
589 | token: server.accessToken, | |
590 | path, | |
591 | query: { videoIds: [ 1, 2 ] }, | |
592 | statusCodeExpected: 200 | |
593 | }) | |
594 | }) | |
595 | }) | |
596 | ||
07b1a18a | 597 | describe('When deleting an element in a playlist', function () { |
df0b219d C |
598 | const getBase = (wrapper: any = {}) => { |
599 | return Object.assign({ | |
07b1a18a | 600 | url: server.url, |
df0b219d C |
601 | token: server.accessToken, |
602 | videoId: videoId, | |
07b1a18a | 603 | playlistId: playlistUUID, |
df0b219d C |
604 | expectedStatus: 400 |
605 | }, wrapper) | |
606 | } | |
607 | ||
608 | it('Should fail with an unauthenticated user', async function () { | |
609 | const params = getBase({ token: null, expectedStatus: 401 }) | |
610 | await removeVideoFromPlaylist(params) | |
07b1a18a C |
611 | }) |
612 | ||
613 | it('Should fail with the playlist of another user', async function () { | |
df0b219d C |
614 | const params = getBase({ token: userAccessToken, expectedStatus: 403 }) |
615 | await removeVideoFromPlaylist(params) | |
07b1a18a C |
616 | }) |
617 | ||
618 | it('Should fail with an unknown or incorrect playlist id', async function () { | |
df0b219d C |
619 | { |
620 | const params = getBase({ playlistId: 'toto' }) | |
621 | await removeVideoFromPlaylist(params) | |
622 | } | |
07b1a18a | 623 | |
df0b219d C |
624 | { |
625 | const params = getBase({ playlistId: 42, expectedStatus: 404 }) | |
626 | await removeVideoFromPlaylist(params) | |
627 | } | |
07b1a18a C |
628 | }) |
629 | ||
630 | it('Should fail with an unknown or incorrect video id', async function () { | |
df0b219d C |
631 | { |
632 | const params = getBase({ videoId: 'toto' }) | |
633 | await removeVideoFromPlaylist(params) | |
634 | } | |
07b1a18a | 635 | |
df0b219d C |
636 | { |
637 | const params = getBase({ videoId: 42, expectedStatus: 404 }) | |
638 | await removeVideoFromPlaylist(params) | |
639 | } | |
07b1a18a C |
640 | }) |
641 | ||
642 | it('Should fail with an unknown element', async function () { | |
df0b219d C |
643 | const params = getBase({ videoId: videoId2, expectedStatus: 404 }) |
644 | await removeVideoFromPlaylist(params) | |
07b1a18a C |
645 | }) |
646 | ||
647 | it('Succeed with the correct params', async function () { | |
df0b219d C |
648 | const params = getBase({ expectedStatus: 204 }) |
649 | await removeVideoFromPlaylist(params) | |
07b1a18a C |
650 | }) |
651 | }) | |
652 | ||
653 | describe('When deleting a playlist', function () { | |
654 | it('Should fail with an unknown playlist', async function () { | |
655 | await deleteVideoPlaylist(server.url, server.accessToken, 42, 404) | |
656 | }) | |
657 | ||
658 | it('Should fail with a playlist of another user', async function () { | |
659 | await deleteVideoPlaylist(server.url, userAccessToken, playlistUUID, 403) | |
660 | }) | |
661 | ||
df0b219d | 662 | it('Should fail with the watch later playlist', async function () { |
c5e4e36d | 663 | await deleteVideoPlaylist(server.url, server.accessToken, watchLaterPlaylistId, 400) |
df0b219d C |
664 | }) |
665 | ||
07b1a18a C |
666 | it('Should succeed with the correct params', async function () { |
667 | await deleteVideoPlaylist(server.url, server.accessToken, playlistUUID) | |
668 | }) | |
669 | }) | |
670 | ||
7c3b7976 C |
671 | after(async function () { |
672 | await cleanupTests([ server ]) | |
418d092a C |
673 | }) |
674 | }) |