aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api/check-params/video-playlists.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests/api/check-params/video-playlists.ts')
-rw-r--r--server/tests/api/check-params/video-playlists.ts114
1 files changed, 65 insertions, 49 deletions
diff --git a/server/tests/api/check-params/video-playlists.ts b/server/tests/api/check-params/video-playlists.ts
index 179ae9201..418af05d1 100644
--- a/server/tests/api/check-params/video-playlists.ts
+++ b/server/tests/api/check-params/video-playlists.ts
@@ -28,6 +28,7 @@ import {
28} from '../../../../shared/extra-utils/requests/check-api-params' 28} from '../../../../shared/extra-utils/requests/check-api-params'
29import { VideoPlaylistPrivacy } from '../../../../shared/models/videos/playlist/video-playlist-privacy.model' 29import { VideoPlaylistPrivacy } from '../../../../shared/models/videos/playlist/video-playlist-privacy.model'
30import { VideoPlaylistType } from '../../../../shared/models/videos/playlist/video-playlist-type.model' 30import { VideoPlaylistType } from '../../../../shared/models/videos/playlist/video-playlist-type.model'
31import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
31 32
32describe('Test video playlists API validator', function () { 33describe('Test video playlists API validator', function () {
33 let server: ServerInfo 34 let server: ServerInfo
@@ -114,19 +115,34 @@ describe('Test video playlists API validator', function () {
114 it('Should fail with a bad account parameter', async function () { 115 it('Should fail with a bad account parameter', async function () {
115 const accountPath = '/api/v1/accounts/root2/video-playlists' 116 const accountPath = '/api/v1/accounts/root2/video-playlists'
116 117
117 await makeGetRequest({ url: server.url, path: accountPath, statusCodeExpected: 404, token: server.accessToken }) 118 await makeGetRequest({
119 url: server.url,
120 path: accountPath,
121 statusCodeExpected: HttpStatusCode.NOT_FOUND_404,
122 token: server.accessToken
123 })
118 }) 124 })
119 125
120 it('Should fail with a bad video channel parameter', async function () { 126 it('Should fail with a bad video channel parameter', async function () {
121 const accountPath = '/api/v1/video-channels/bad_channel/video-playlists' 127 const accountPath = '/api/v1/video-channels/bad_channel/video-playlists'
122 128
123 await makeGetRequest({ url: server.url, path: accountPath, statusCodeExpected: 404, token: server.accessToken }) 129 await makeGetRequest({
130 url: server.url,
131 path: accountPath,
132 statusCodeExpected: HttpStatusCode.NOT_FOUND_404,
133 token: server.accessToken
134 })
124 }) 135 })
125 136
126 it('Should success with the correct parameters', async function () { 137 it('Should success with the correct parameters', async function () {
127 await makeGetRequest({ url: server.url, path: globalPath, statusCodeExpected: 200, token: server.accessToken }) 138 await makeGetRequest({ url: server.url, path: globalPath, statusCodeExpected: HttpStatusCode.OK_200, token: server.accessToken })
128 await makeGetRequest({ url: server.url, path: accountPath, statusCodeExpected: 200, token: server.accessToken }) 139 await makeGetRequest({ url: server.url, path: accountPath, statusCodeExpected: HttpStatusCode.OK_200, token: server.accessToken })
129 await makeGetRequest({ url: server.url, path: videoChannelPath, statusCodeExpected: 200, token: server.accessToken }) 140 await makeGetRequest({
141 url: server.url,
142 path: videoChannelPath,
143 statusCodeExpected: HttpStatusCode.OK_200,
144 token: server.accessToken
145 })
130 }) 146 })
131 }) 147 })
132 148
@@ -142,17 +158,17 @@ describe('Test video playlists API validator', function () {
142 }) 158 })
143 159
144 it('Should success with the correct parameters', async function () { 160 it('Should success with the correct parameters', async function () {
145 await makeGetRequest({ url: server.url, path: path + playlistUUID + '/videos', statusCodeExpected: 200 }) 161 await makeGetRequest({ url: server.url, path: path + playlistUUID + '/videos', statusCodeExpected: HttpStatusCode.OK_200 })
146 }) 162 })
147 }) 163 })
148 164
149 describe('When getting a video playlist', function () { 165 describe('When getting a video playlist', function () {
150 it('Should fail with a bad id or uuid', async function () { 166 it('Should fail with a bad id or uuid', async function () {
151 await getVideoPlaylist(server.url, 'toto', 400) 167 await getVideoPlaylist(server.url, 'toto', HttpStatusCode.BAD_REQUEST_400)
152 }) 168 })
153 169
154 it('Should fail with an unknown playlist', async function () { 170 it('Should fail with an unknown playlist', async function () {
155 await getVideoPlaylist(server.url, 42, 404) 171 await getVideoPlaylist(server.url, 42, HttpStatusCode.NOT_FOUND_404)
156 }) 172 })
157 173
158 it('Should fail to get an unlisted playlist with the number id', async function () { 174 it('Should fail to get an unlisted playlist with the number id', async function () {
@@ -166,19 +182,19 @@ describe('Test video playlists API validator', function () {
166 }) 182 })
167 const playlist = res.body.videoPlaylist 183 const playlist = res.body.videoPlaylist
168 184
169 await getVideoPlaylist(server.url, playlist.id, 404) 185 await getVideoPlaylist(server.url, playlist.id, HttpStatusCode.NOT_FOUND_404)
170 await getVideoPlaylist(server.url, playlist.uuid, 200) 186 await getVideoPlaylist(server.url, playlist.uuid, HttpStatusCode.OK_200)
171 }) 187 })
172 188
173 it('Should succeed with the correct params', async function () { 189 it('Should succeed with the correct params', async function () {
174 await getVideoPlaylist(server.url, playlistUUID, 200) 190 await getVideoPlaylist(server.url, playlistUUID, HttpStatusCode.OK_200)
175 }) 191 })
176 }) 192 })
177 193
178 describe('When creating/updating a video playlist', function () { 194 describe('When creating/updating a video playlist', function () {
179 const getBase = (playlistAttrs: any = {}, wrapper: any = {}) => { 195 const getBase = (playlistAttrs: any = {}, wrapper: any = {}) => {
180 return Object.assign({ 196 return Object.assign({
181 expectedStatus: 400, 197 expectedStatus: HttpStatusCode.BAD_REQUEST_400,
182 url: server.url, 198 url: server.url,
183 token: server.accessToken, 199 token: server.accessToken,
184 playlistAttrs: Object.assign({ 200 playlistAttrs: Object.assign({
@@ -194,7 +210,7 @@ describe('Test video playlists API validator', function () {
194 } 210 }
195 211
196 it('Should fail with an unauthenticated user', async function () { 212 it('Should fail with an unauthenticated user', async function () {
197 const params = getBase({}, { token: null, expectedStatus: 401 }) 213 const params = getBase({}, { token: null, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
198 214
199 await createVideoPlaylist(params) 215 await createVideoPlaylist(params)
200 await updateVideoPlaylist(getUpdate(params, playlistUUID)) 216 await updateVideoPlaylist(getUpdate(params, playlistUUID))
@@ -228,7 +244,7 @@ describe('Test video playlists API validator', function () {
228 }) 244 })
229 245
230 it('Should fail with an unknown video channel id', async function () { 246 it('Should fail with an unknown video channel id', async function () {
231 const params = getBase({ videoChannelId: 42 }, { expectedStatus: 404 }) 247 const params = getBase({ videoChannelId: 42 }, { expectedStatus: HttpStatusCode.NOT_FOUND_404 })
232 248
233 await createVideoPlaylist(params) 249 await createVideoPlaylist(params)
234 await updateVideoPlaylist(getUpdate(params, playlistUUID)) 250 await updateVideoPlaylist(getUpdate(params, playlistUUID))
@@ -255,33 +271,33 @@ describe('Test video playlists API validator', function () {
255 271
256 it('Should fail with an unknown playlist to update', async function () { 272 it('Should fail with an unknown playlist to update', async function () {
257 await updateVideoPlaylist(getUpdate( 273 await updateVideoPlaylist(getUpdate(
258 getBase({}, { expectedStatus: 404 }), 274 getBase({}, { expectedStatus: HttpStatusCode.NOT_FOUND_404 }),
259 42 275 42
260 )) 276 ))
261 }) 277 })
262 278
263 it('Should fail to update a playlist of another user', async function () { 279 it('Should fail to update a playlist of another user', async function () {
264 await updateVideoPlaylist(getUpdate( 280 await updateVideoPlaylist(getUpdate(
265 getBase({}, { token: userAccessToken, expectedStatus: 403 }), 281 getBase({}, { token: userAccessToken, expectedStatus: HttpStatusCode.FORBIDDEN_403 }),
266 playlistUUID 282 playlistUUID
267 )) 283 ))
268 }) 284 })
269 285
270 it('Should fail to update the watch later playlist', async function () { 286 it('Should fail to update the watch later playlist', async function () {
271 await updateVideoPlaylist(getUpdate( 287 await updateVideoPlaylist(getUpdate(
272 getBase({}, { expectedStatus: 400 }), 288 getBase({}, { expectedStatus: HttpStatusCode.BAD_REQUEST_400 }),
273 watchLaterPlaylistId 289 watchLaterPlaylistId
274 )) 290 ))
275 }) 291 })
276 292
277 it('Should succeed with the correct params', async function () { 293 it('Should succeed with the correct params', async function () {
278 { 294 {
279 const params = getBase({}, { expectedStatus: 200 }) 295 const params = getBase({}, { expectedStatus: HttpStatusCode.OK_200 })
280 await createVideoPlaylist(params) 296 await createVideoPlaylist(params)
281 } 297 }
282 298
283 { 299 {
284 const params = getBase({}, { expectedStatus: 204 }) 300 const params = getBase({}, { expectedStatus: HttpStatusCode.NO_CONTENT_204 })
285 await updateVideoPlaylist(getUpdate(params, playlistUUID)) 301 await updateVideoPlaylist(getUpdate(params, playlistUUID))
286 } 302 }
287 }) 303 })
@@ -290,7 +306,7 @@ describe('Test video playlists API validator', function () {
290 describe('When adding an element in a playlist', function () { 306 describe('When adding an element in a playlist', function () {
291 const getBase = (elementAttrs: any = {}, wrapper: any = {}) => { 307 const getBase = (elementAttrs: any = {}, wrapper: any = {}) => {
292 return Object.assign({ 308 return Object.assign({
293 expectedStatus: 400, 309 expectedStatus: HttpStatusCode.BAD_REQUEST_400,
294 url: server.url, 310 url: server.url,
295 token: server.accessToken, 311 token: server.accessToken,
296 playlistId: playlistUUID, 312 playlistId: playlistUUID,
@@ -303,12 +319,12 @@ describe('Test video playlists API validator', function () {
303 } 319 }
304 320
305 it('Should fail with an unauthenticated user', async function () { 321 it('Should fail with an unauthenticated user', async function () {
306 const params = getBase({}, { token: null, expectedStatus: 401 }) 322 const params = getBase({}, { token: null, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
307 await addVideoInPlaylist(params) 323 await addVideoInPlaylist(params)
308 }) 324 })
309 325
310 it('Should fail with the playlist of another user', async function () { 326 it('Should fail with the playlist of another user', async function () {
311 const params = getBase({}, { token: userAccessToken, expectedStatus: 403 }) 327 const params = getBase({}, { token: userAccessToken, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
312 await addVideoInPlaylist(params) 328 await addVideoInPlaylist(params)
313 }) 329 })
314 330
@@ -319,13 +335,13 @@ describe('Test video playlists API validator', function () {
319 } 335 }
320 336
321 { 337 {
322 const params = getBase({}, { playlistId: 42, expectedStatus: 404 }) 338 const params = getBase({}, { playlistId: 42, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
323 await addVideoInPlaylist(params) 339 await addVideoInPlaylist(params)
324 } 340 }
325 }) 341 })
326 342
327 it('Should fail with an unknown or incorrect video id', async function () { 343 it('Should fail with an unknown or incorrect video id', async function () {
328 const params = getBase({ videoId: 42 }, { expectedStatus: 404 }) 344 const params = getBase({ videoId: 42 }, { expectedStatus: HttpStatusCode.NOT_FOUND_404 })
329 await addVideoInPlaylist(params) 345 await addVideoInPlaylist(params)
330 }) 346 })
331 347
@@ -342,7 +358,7 @@ describe('Test video playlists API validator', function () {
342 }) 358 })
343 359
344 it('Succeed with the correct params', async function () { 360 it('Succeed with the correct params', async function () {
345 const params = getBase({}, { expectedStatus: 200 }) 361 const params = getBase({}, { expectedStatus: HttpStatusCode.OK_200 })
346 const res = await addVideoInPlaylist(params) 362 const res = await addVideoInPlaylist(params)
347 playlistElementId = res.body.videoPlaylistElement.id 363 playlistElementId = res.body.videoPlaylistElement.id
348 }) 364 })
@@ -359,17 +375,17 @@ describe('Test video playlists API validator', function () {
359 }, elementAttrs), 375 }, elementAttrs),
360 playlistElementId, 376 playlistElementId,
361 playlistId: playlistUUID, 377 playlistId: playlistUUID,
362 expectedStatus: 400 378 expectedStatus: HttpStatusCode.BAD_REQUEST_400
363 }, wrapper) 379 }, wrapper)
364 } 380 }
365 381
366 it('Should fail with an unauthenticated user', async function () { 382 it('Should fail with an unauthenticated user', async function () {
367 const params = getBase({}, { token: null, expectedStatus: 401 }) 383 const params = getBase({}, { token: null, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
368 await updateVideoPlaylistElement(params) 384 await updateVideoPlaylistElement(params)
369 }) 385 })
370 386
371 it('Should fail with the playlist of another user', async function () { 387 it('Should fail with the playlist of another user', async function () {
372 const params = getBase({}, { token: userAccessToken, expectedStatus: 403 }) 388 const params = getBase({}, { token: userAccessToken, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
373 await updateVideoPlaylistElement(params) 389 await updateVideoPlaylistElement(params)
374 }) 390 })
375 391
@@ -380,7 +396,7 @@ describe('Test video playlists API validator', function () {
380 } 396 }
381 397
382 { 398 {
383 const params = getBase({}, { playlistId: 42, expectedStatus: 404 }) 399 const params = getBase({}, { playlistId: 42, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
384 await updateVideoPlaylistElement(params) 400 await updateVideoPlaylistElement(params)
385 } 401 }
386 }) 402 })
@@ -392,7 +408,7 @@ describe('Test video playlists API validator', function () {
392 } 408 }
393 409
394 { 410 {
395 const params = getBase({}, { playlistElementId: 42, expectedStatus: 404 }) 411 const params = getBase({}, { playlistElementId: 42, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
396 await updateVideoPlaylistElement(params) 412 await updateVideoPlaylistElement(params)
397 } 413 }
398 }) 414 })
@@ -410,12 +426,12 @@ describe('Test video playlists API validator', function () {
410 }) 426 })
411 427
412 it('Should fail with an unknown element', async function () { 428 it('Should fail with an unknown element', async function () {
413 const params = getBase({}, { playlistElementId: 888, expectedStatus: 404 }) 429 const params = getBase({}, { playlistElementId: 888, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
414 await updateVideoPlaylistElement(params) 430 await updateVideoPlaylistElement(params)
415 }) 431 })
416 432
417 it('Succeed with the correct params', async function () { 433 it('Succeed with the correct params', async function () {
418 const params = getBase({}, { expectedStatus: 204 }) 434 const params = getBase({}, { expectedStatus: HttpStatusCode.NO_CONTENT_204 })
419 await updateVideoPlaylistElement(params) 435 await updateVideoPlaylistElement(params)
420 }) 436 })
421 }) 437 })
@@ -434,7 +450,7 @@ describe('Test video playlists API validator', function () {
434 insertAfterPosition: 2, 450 insertAfterPosition: 2,
435 reorderLength: 3 451 reorderLength: 3
436 }, elementAttrs), 452 }, elementAttrs),
437 expectedStatus: 400 453 expectedStatus: HttpStatusCode.BAD_REQUEST_400
438 }, wrapper) 454 }, wrapper)
439 } 455 }
440 456
@@ -453,12 +469,12 @@ describe('Test video playlists API validator', function () {
453 }) 469 })
454 470
455 it('Should fail with an unauthenticated user', async function () { 471 it('Should fail with an unauthenticated user', async function () {
456 const params = getBase({}, { token: null, expectedStatus: 401 }) 472 const params = getBase({}, { token: null, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
457 await reorderVideosPlaylist(params) 473 await reorderVideosPlaylist(params)
458 }) 474 })
459 475
460 it('Should fail with the playlist of another user', async function () { 476 it('Should fail with the playlist of another user', async function () {
461 const params = getBase({}, { token: userAccessToken, expectedStatus: 403 }) 477 const params = getBase({}, { token: userAccessToken, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
462 await reorderVideosPlaylist(params) 478 await reorderVideosPlaylist(params)
463 }) 479 })
464 480
@@ -469,7 +485,7 @@ describe('Test video playlists API validator', function () {
469 } 485 }
470 486
471 { 487 {
472 const params = getBase({}, { playlistId: 42, expectedStatus: 404 }) 488 const params = getBase({}, { playlistId: 42, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
473 await reorderVideosPlaylist(params) 489 await reorderVideosPlaylist(params)
474 } 490 }
475 }) 491 })
@@ -526,7 +542,7 @@ describe('Test video playlists API validator', function () {
526 }) 542 })
527 543
528 it('Succeed with the correct params', async function () { 544 it('Succeed with the correct params', async function () {
529 const params = getBase({}, { expectedStatus: 204 }) 545 const params = getBase({}, { expectedStatus: HttpStatusCode.NO_CONTENT_204 })
530 await reorderVideosPlaylist(params) 546 await reorderVideosPlaylist(params)
531 }) 547 })
532 }) 548 })
@@ -539,7 +555,7 @@ describe('Test video playlists API validator', function () {
539 url: server.url, 555 url: server.url,
540 path, 556 path,
541 query: { videoIds: [ 1, 2 ] }, 557 query: { videoIds: [ 1, 2 ] },
542 statusCodeExpected: 401 558 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
543 }) 559 })
544 }) 560 })
545 561
@@ -572,7 +588,7 @@ describe('Test video playlists API validator', function () {
572 token: server.accessToken, 588 token: server.accessToken,
573 path, 589 path,
574 query: { videoIds: [ 1, 2 ] }, 590 query: { videoIds: [ 1, 2 ] },
575 statusCodeExpected: 200 591 statusCodeExpected: HttpStatusCode.OK_200
576 }) 592 })
577 }) 593 })
578 }) 594 })
@@ -584,17 +600,17 @@ describe('Test video playlists API validator', function () {
584 token: server.accessToken, 600 token: server.accessToken,
585 playlistElementId, 601 playlistElementId,
586 playlistId: playlistUUID, 602 playlistId: playlistUUID,
587 expectedStatus: 400 603 expectedStatus: HttpStatusCode.BAD_REQUEST_400
588 }, wrapper) 604 }, wrapper)
589 } 605 }
590 606
591 it('Should fail with an unauthenticated user', async function () { 607 it('Should fail with an unauthenticated user', async function () {
592 const params = getBase({ token: null, expectedStatus: 401 }) 608 const params = getBase({ token: null, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
593 await removeVideoFromPlaylist(params) 609 await removeVideoFromPlaylist(params)
594 }) 610 })
595 611
596 it('Should fail with the playlist of another user', async function () { 612 it('Should fail with the playlist of another user', async function () {
597 const params = getBase({ token: userAccessToken, expectedStatus: 403 }) 613 const params = getBase({ token: userAccessToken, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
598 await removeVideoFromPlaylist(params) 614 await removeVideoFromPlaylist(params)
599 }) 615 })
600 616
@@ -605,7 +621,7 @@ describe('Test video playlists API validator', function () {
605 } 621 }
606 622
607 { 623 {
608 const params = getBase({ playlistId: 42, expectedStatus: 404 }) 624 const params = getBase({ playlistId: 42, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
609 await removeVideoFromPlaylist(params) 625 await removeVideoFromPlaylist(params)
610 } 626 }
611 }) 627 })
@@ -617,33 +633,33 @@ describe('Test video playlists API validator', function () {
617 } 633 }
618 634
619 { 635 {
620 const params = getBase({ playlistElementId: 42, expectedStatus: 404 }) 636 const params = getBase({ playlistElementId: 42, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
621 await removeVideoFromPlaylist(params) 637 await removeVideoFromPlaylist(params)
622 } 638 }
623 }) 639 })
624 640
625 it('Should fail with an unknown element', async function () { 641 it('Should fail with an unknown element', async function () {
626 const params = getBase({ playlistElementId: 888, expectedStatus: 404 }) 642 const params = getBase({ playlistElementId: 888, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
627 await removeVideoFromPlaylist(params) 643 await removeVideoFromPlaylist(params)
628 }) 644 })
629 645
630 it('Succeed with the correct params', async function () { 646 it('Succeed with the correct params', async function () {
631 const params = getBase({ expectedStatus: 204 }) 647 const params = getBase({ expectedStatus: HttpStatusCode.NO_CONTENT_204 })
632 await removeVideoFromPlaylist(params) 648 await removeVideoFromPlaylist(params)
633 }) 649 })
634 }) 650 })
635 651
636 describe('When deleting a playlist', function () { 652 describe('When deleting a playlist', function () {
637 it('Should fail with an unknown playlist', async function () { 653 it('Should fail with an unknown playlist', async function () {
638 await deleteVideoPlaylist(server.url, server.accessToken, 42, 404) 654 await deleteVideoPlaylist(server.url, server.accessToken, 42, HttpStatusCode.NOT_FOUND_404)
639 }) 655 })
640 656
641 it('Should fail with a playlist of another user', async function () { 657 it('Should fail with a playlist of another user', async function () {
642 await deleteVideoPlaylist(server.url, userAccessToken, playlistUUID, 403) 658 await deleteVideoPlaylist(server.url, userAccessToken, playlistUUID, HttpStatusCode.FORBIDDEN_403)
643 }) 659 })
644 660
645 it('Should fail with the watch later playlist', async function () { 661 it('Should fail with the watch later playlist', async function () {
646 await deleteVideoPlaylist(server.url, server.accessToken, watchLaterPlaylistId, 400) 662 await deleteVideoPlaylist(server.url, server.accessToken, watchLaterPlaylistId, HttpStatusCode.BAD_REQUEST_400)
647 }) 663 })
648 664
649 it('Should succeed with the correct params', async function () { 665 it('Should succeed with the correct params', async function () {