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