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