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