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