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