1 /* tslint:disable:no-unused-expression */
10 generateUserAccessToken,
11 getAccountPlaylistsListWithToken,
15 removeVideoFromPlaylist,
16 reorderVideosPlaylist,
18 setAccessTokensToServers,
19 setDefaultVideoChannel,
21 updateVideoPlaylistElement,
23 } from '../../../../shared/extra-utils'
25 checkBadCountPagination,
26 checkBadSortPagination,
27 checkBadStartPagination
28 } from '../../../../shared/extra-utils/requests/check-api-params'
29 import { VideoPlaylistPrivacy } from '../../../../shared/models/videos/playlist/video-playlist-privacy.model'
30 import { VideoPlaylistType } from '../../../../shared/models/videos/playlist/video-playlist-type.model'
32 describe('Test video playlists API validator', function () {
33 let server: ServerInfo
34 let userAccessToken: string
35 let playlistUUID: string
36 let privatePlaylistUUID: string
37 let watchLaterPlaylistId: number
41 // ---------------------------------------------------------------
43 before(async function () {
46 server = await flushAndRunServer(1)
48 await setAccessTokensToServers([ server ])
49 await setDefaultVideoChannel([ server ])
51 userAccessToken = await generateUserAccessToken(server, 'user1')
52 videoId = (await uploadVideoAndGetId({ server, videoName: 'video 1' })).id
53 videoId2 = (await uploadVideoAndGetId({ server, videoName: 'video 2' })).id
56 const res = await getAccountPlaylistsListWithToken(server.url, server.accessToken, 'root',0, 5, VideoPlaylistType.WATCH_LATER)
57 watchLaterPlaylistId = res.body.data[0].id
61 const res = await createVideoPlaylist({
63 token: server.accessToken,
65 displayName: 'super playlist',
66 privacy: VideoPlaylistPrivacy.PUBLIC,
67 videoChannelId: server.videoChannel.id
70 playlistUUID = res.body.videoPlaylist.uuid
74 const res = await createVideoPlaylist({
76 token: server.accessToken,
78 displayName: 'private',
79 privacy: VideoPlaylistPrivacy.PRIVATE
82 privatePlaylistUUID = res.body.videoPlaylist.uuid
86 describe('When listing playlists', function () {
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'
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)
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)
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)
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 } })
115 it('Should fail with a bad account parameter', async function () {
116 const accountPath = '/api/v1/accounts/root2/video-playlists'
118 await makeGetRequest({ url: server.url, path: accountPath, statusCodeExpected: 404, token: server.accessToken })
121 it('Should fail with a bad video channel parameter', async function () {
122 const accountPath = '/api/v1/video-channels/bad_channel/video-playlists'
124 await makeGetRequest({ url: server.url, path: accountPath, statusCodeExpected: 404, token: server.accessToken })
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 })
134 describe('When listing videos of a playlist', function () {
135 const path = '/api/v1/video-playlists'
137 it('Should fail with a bad start pagination', async function () {
138 await checkBadStartPagination(server.url, path, server.accessToken)
141 it('Should fail with a bad count pagination', async function () {
142 await checkBadCountPagination(server.url, path, server.accessToken)
145 it('Should fail with a bad filter', async function () {
146 await checkBadSortPagination(server.url, path, server.accessToken)
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)
155 it('Should fail with an unknown playlist', async function () {
156 await getVideoPlaylist(server.url, 42, 404)
159 it('Should fail to get an unlisted playlist with the number id', async function () {
160 const res = await createVideoPlaylist({
162 token: server.accessToken,
164 displayName: 'super playlist',
165 privacy: VideoPlaylistPrivacy.UNLISTED
168 const playlist = res.body.videoPlaylist
170 await getVideoPlaylist(server.url, playlist.id, 404)
171 await getVideoPlaylist(server.url, playlist.uuid, 200)
174 it('Should succeed with the correct params', async function () {
175 await getVideoPlaylist(server.url, playlistUUID, 200)
179 describe('When creating/updating a video playlist', function () {
180 const getBase = (playlistAttrs: any = {}, wrapper: any = {}) => {
181 return Object.assign({
184 token: server.accessToken,
185 playlistAttrs: Object.assign({
186 displayName: 'display name',
187 privacy: VideoPlaylistPrivacy.UNLISTED,
188 thumbnailfile: 'thumbnail.jpg',
189 videoChannelId: server.videoChannel.id
193 const getUpdate = (params: any, playlistId: number | string) => {
194 return immutableAssign(params, { playlistId: playlistId })
197 it('Should fail with an unauthenticated user', async function () {
198 const params = getBase({}, { token: null, expectedStatus: 401 })
200 await createVideoPlaylist(params)
201 await updateVideoPlaylist(getUpdate(params, playlistUUID))
204 it('Should fail without displayName', async function () {
205 const params = getBase({ displayName: undefined })
207 await createVideoPlaylist(params)
210 it('Should fail with an incorrect display name', async function () {
211 const params = getBase({ displayName: 's'.repeat(300) })
213 await createVideoPlaylist(params)
214 await updateVideoPlaylist(getUpdate(params, playlistUUID))
217 it('Should fail with an incorrect description', async function () {
218 const params = getBase({ description: 't' })
220 await createVideoPlaylist(params)
221 await updateVideoPlaylist(getUpdate(params, playlistUUID))
224 it('Should fail with an incorrect privacy', async function () {
225 const params = getBase({ privacy: 45 })
227 await createVideoPlaylist(params)
228 await updateVideoPlaylist(getUpdate(params, playlistUUID))
231 it('Should fail with an unknown video channel id', async function () {
232 const params = getBase({ videoChannelId: 42 }, { expectedStatus: 404 })
234 await createVideoPlaylist(params)
235 await updateVideoPlaylist(getUpdate(params, playlistUUID))
238 it('Should fail with an incorrect thumbnail file', async function () {
239 const params = getBase({ thumbnailfile: 'avatar.png' })
241 await createVideoPlaylist(params)
242 await updateVideoPlaylist(getUpdate(params, playlistUUID))
245 it('Should fail to set "public" a playlist not assigned to a channel', async function () {
246 const params = getBase({ privacy: VideoPlaylistPrivacy.PUBLIC, videoChannelId: undefined })
247 const params2 = getBase({ privacy: VideoPlaylistPrivacy.PUBLIC, videoChannelId: 'null' })
248 const params3 = getBase({ privacy: undefined, videoChannelId: 'null' })
250 await createVideoPlaylist(params)
251 await createVideoPlaylist(params2)
252 await updateVideoPlaylist(getUpdate(params, privatePlaylistUUID))
253 await updateVideoPlaylist(getUpdate(params2, playlistUUID))
254 await updateVideoPlaylist(getUpdate(params3, playlistUUID))
257 it('Should fail with an unknown playlist to update', async function () {
258 await updateVideoPlaylist(getUpdate(
259 getBase({}, { expectedStatus: 404 }),
264 it('Should fail to update a playlist of another user', async function () {
265 await updateVideoPlaylist(getUpdate(
266 getBase({}, { token: userAccessToken, expectedStatus: 403 }),
271 it('Should fail to update the watch later playlist', async function () {
272 await updateVideoPlaylist(getUpdate(
273 getBase({}, { expectedStatus: 400 }),
278 it('Should succeed with the correct params', async function () {
280 const params = getBase({}, { expectedStatus: 200 })
281 await createVideoPlaylist(params)
285 const params = getBase({}, { expectedStatus: 204 })
286 await updateVideoPlaylist(getUpdate(params, playlistUUID))
291 describe('When adding an element in a playlist', function () {
292 const getBase = (elementAttrs: any = {}, wrapper: any = {}) => {
293 return Object.assign({
296 token: server.accessToken,
297 playlistId: playlistUUID,
298 elementAttrs: Object.assign({
306 it('Should fail with an unauthenticated user', async function () {
307 const params = getBase({}, { token: null, expectedStatus: 401 })
308 await addVideoInPlaylist(params)
311 it('Should fail with the playlist of another user', async function () {
312 const params = getBase({}, { token: userAccessToken, expectedStatus: 403 })
313 await addVideoInPlaylist(params)
316 it('Should fail with an unknown or incorrect playlist id', async function () {
318 const params = getBase({}, { playlistId: 'toto' })
319 await addVideoInPlaylist(params)
323 const params = getBase({}, { playlistId: 42, expectedStatus: 404 })
324 await addVideoInPlaylist(params)
328 it('Should fail with an unknown or incorrect video id', async function () {
329 const params = getBase({ videoId: 42 }, { expectedStatus: 404 })
330 await addVideoInPlaylist(params)
333 it('Should fail with a bad start/stop timestamp', async function () {
335 const params = getBase({ startTimestamp: -42 })
336 await addVideoInPlaylist(params)
340 const params = getBase({ stopTimestamp: 'toto' as any })
341 await addVideoInPlaylist(params)
345 it('Succeed with the correct params', async function () {
346 const params = getBase({}, { expectedStatus: 200 })
347 await addVideoInPlaylist(params)
350 it('Should fail if the video was already added in the playlist', async function () {
351 const params = getBase({}, { expectedStatus: 409 })
352 await addVideoInPlaylist(params)
356 describe('When updating an element in a playlist', function () {
357 const getBase = (elementAttrs: any = {}, wrapper: any = {}) => {
358 return Object.assign({
360 token: server.accessToken,
361 elementAttrs: Object.assign({
366 playlistId: playlistUUID,
371 it('Should fail with an unauthenticated user', async function () {
372 const params = getBase({}, { token: null, expectedStatus: 401 })
373 await updateVideoPlaylistElement(params)
376 it('Should fail with the playlist of another user', async function () {
377 const params = getBase({}, { token: userAccessToken, expectedStatus: 403 })
378 await updateVideoPlaylistElement(params)
381 it('Should fail with an unknown or incorrect playlist id', async function () {
383 const params = getBase({}, { playlistId: 'toto' })
384 await updateVideoPlaylistElement(params)
388 const params = getBase({}, { playlistId: 42, expectedStatus: 404 })
389 await updateVideoPlaylistElement(params)
393 it('Should fail with an unknown or incorrect video id', async function () {
395 const params = getBase({}, { videoId: 'toto' })
396 await updateVideoPlaylistElement(params)
400 const params = getBase({}, { videoId: 42, expectedStatus: 404 })
401 await updateVideoPlaylistElement(params)
405 it('Should fail with a bad start/stop timestamp', async function () {
407 const params = getBase({ startTimestamp: 'toto' as any })
408 await updateVideoPlaylistElement(params)
412 const params = getBase({ stopTimestamp: -42 })
413 await updateVideoPlaylistElement(params)
417 it('Should fail with an unknown element', async function () {
418 const params = getBase({}, { videoId: videoId2, expectedStatus: 404 })
419 await updateVideoPlaylistElement(params)
422 it('Succeed with the correct params', async function () {
423 const params = getBase({}, { expectedStatus: 204 })
424 await updateVideoPlaylistElement(params)
428 describe('When reordering elements of a playlist', function () {
432 const getBase = (elementAttrs: any = {}, wrapper: any = {}) => {
433 return Object.assign({
435 token: server.accessToken,
436 playlistId: playlistUUID,
437 elementAttrs: Object.assign({
439 insertAfterPosition: 2,
446 before(async function () {
447 videoId3 = (await uploadVideoAndGetId({ server, videoName: 'video 3' })).id
448 videoId4 = (await uploadVideoAndGetId({ server, videoName: 'video 4' })).id
450 for (let id of [ videoId3, videoId4 ]) {
451 await addVideoInPlaylist({
453 token: server.accessToken,
454 playlistId: playlistUUID,
455 elementAttrs: { videoId: id }
460 it('Should fail with an unauthenticated user', async function () {
461 const params = getBase({}, { token: null, expectedStatus: 401 })
462 await reorderVideosPlaylist(params)
465 it('Should fail with the playlist of another user', async function () {
466 const params = getBase({}, { token: userAccessToken, expectedStatus: 403 })
467 await reorderVideosPlaylist(params)
470 it('Should fail with an invalid playlist', async function () {
472 const params = getBase({}, { playlistId: 'toto' })
473 await reorderVideosPlaylist(params)
477 const params = getBase({}, { playlistId: 42, expectedStatus: 404 })
478 await reorderVideosPlaylist(params)
482 it('Should fail with an invalid start position', async function () {
484 const params = getBase({ startPosition: -1 })
485 await reorderVideosPlaylist(params)
489 const params = getBase({ startPosition: 'toto' as any })
490 await reorderVideosPlaylist(params)
494 const params = getBase({ startPosition: 42 })
495 await reorderVideosPlaylist(params)
499 it('Should fail with an invalid insert after position', async function () {
501 const params = getBase({ insertAfterPosition: 'toto' as any })
502 await reorderVideosPlaylist(params)
506 const params = getBase({ insertAfterPosition: -2 })
507 await reorderVideosPlaylist(params)
511 const params = getBase({ insertAfterPosition: 42 })
512 await reorderVideosPlaylist(params)
516 it('Should fail with an invalid reorder length', async function () {
518 const params = getBase({ reorderLength: 'toto' as any })
519 await reorderVideosPlaylist(params)
523 const params = getBase({ reorderLength: -2 })
524 await reorderVideosPlaylist(params)
528 const params = getBase({ reorderLength: 42 })
529 await reorderVideosPlaylist(params)
533 it('Succeed with the correct params', async function () {
534 const params = getBase({}, { expectedStatus: 204 })
535 await reorderVideosPlaylist(params)
539 describe('When checking exists in playlist endpoint', function () {
540 const path = '/api/v1/users/me/video-playlists/videos-exist'
542 it('Should fail with an unauthenticated user', async function () {
543 await makeGetRequest({
546 query: { videoIds: [ 1, 2 ] },
547 statusCodeExpected: 401
551 it('Should fail with invalid video ids', async function () {
552 await makeGetRequest({
554 token: server.accessToken,
556 query: { videoIds: 'toto' }
559 await makeGetRequest({
561 token: server.accessToken,
563 query: { videoIds: [ 'toto' ] }
566 await makeGetRequest({
568 token: server.accessToken,
570 query: { videoIds: [ 1, 'toto' ] }
574 it('Should succeed with the correct params', async function () {
575 await makeGetRequest({
577 token: server.accessToken,
579 query: { videoIds: [ 1, 2 ] },
580 statusCodeExpected: 200
585 describe('When deleting an element in a playlist', function () {
586 const getBase = (wrapper: any = {}) => {
587 return Object.assign({
589 token: server.accessToken,
591 playlistId: playlistUUID,
596 it('Should fail with an unauthenticated user', async function () {
597 const params = getBase({ token: null, expectedStatus: 401 })
598 await removeVideoFromPlaylist(params)
601 it('Should fail with the playlist of another user', async function () {
602 const params = getBase({ token: userAccessToken, expectedStatus: 403 })
603 await removeVideoFromPlaylist(params)
606 it('Should fail with an unknown or incorrect playlist id', async function () {
608 const params = getBase({ playlistId: 'toto' })
609 await removeVideoFromPlaylist(params)
613 const params = getBase({ playlistId: 42, expectedStatus: 404 })
614 await removeVideoFromPlaylist(params)
618 it('Should fail with an unknown or incorrect video id', async function () {
620 const params = getBase({ videoId: 'toto' })
621 await removeVideoFromPlaylist(params)
625 const params = getBase({ videoId: 42, expectedStatus: 404 })
626 await removeVideoFromPlaylist(params)
630 it('Should fail with an unknown element', async function () {
631 const params = getBase({ videoId: videoId2, expectedStatus: 404 })
632 await removeVideoFromPlaylist(params)
635 it('Succeed with the correct params', async function () {
636 const params = getBase({ expectedStatus: 204 })
637 await removeVideoFromPlaylist(params)
641 describe('When deleting a playlist', function () {
642 it('Should fail with an unknown playlist', async function () {
643 await deleteVideoPlaylist(server.url, server.accessToken, 42, 404)
646 it('Should fail with a playlist of another user', async function () {
647 await deleteVideoPlaylist(server.url, userAccessToken, playlistUUID, 403)
650 it('Should fail with the watch later playlist', async function () {
651 await deleteVideoPlaylist(server.url, server.accessToken, watchLaterPlaylistId, 400)
654 it('Should succeed with the correct params', async function () {
655 await deleteVideoPlaylist(server.url, server.accessToken, playlistUUID)
659 after(async function () {
660 await cleanupTests([ server ])