aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api/check-params/live.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests/api/check-params/live.ts')
-rw-r--r--server/tests/api/check-params/live.ts72
1 files changed, 36 insertions, 36 deletions
diff --git a/server/tests/api/check-params/live.ts b/server/tests/api/check-params/live.ts
index 7a623c169..56116848f 100644
--- a/server/tests/api/check-params/live.ts
+++ b/server/tests/api/check-params/live.ts
@@ -2,27 +2,24 @@
2 2
3import 'mocha' 3import 'mocha'
4import { omit } from 'lodash' 4import { omit } from 'lodash'
5import { LiveVideo, VideoCreateResult, VideoPrivacy } from '@shared/models' 5import { VideoCreateResult, VideoPrivacy } from '@shared/models'
6import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' 6import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
7import { 7import {
8 buildAbsoluteFixturePath, 8 buildAbsoluteFixturePath,
9 cleanupTests, 9 cleanupTests,
10 createUser, 10 createUser,
11 flushAndRunServer, 11 flushAndRunServer,
12 getLive,
13 getMyUserInformation, 12 getMyUserInformation,
14 immutableAssign, 13 immutableAssign,
14 LiveCommand,
15 makePostBodyRequest, 15 makePostBodyRequest,
16 makeUploadRequest, 16 makeUploadRequest,
17 runAndTestFfmpegStreamError,
18 sendRTMPStream, 17 sendRTMPStream,
19 ServerInfo, 18 ServerInfo,
20 setAccessTokensToServers, 19 setAccessTokensToServers,
21 stopFfmpeg, 20 stopFfmpeg,
22 updateLive,
23 uploadVideoAndGetId, 21 uploadVideoAndGetId,
24 userLogin, 22 userLogin
25 waitUntilLivePublished
26} from '../../../../shared/extra-utils' 23} from '../../../../shared/extra-utils'
27 24
28describe('Test video lives API validator', function () { 25describe('Test video lives API validator', function () {
@@ -32,6 +29,7 @@ describe('Test video lives API validator', function () {
32 let channelId: number 29 let channelId: number
33 let video: VideoCreateResult 30 let video: VideoCreateResult
34 let videoIdNotLive: number 31 let videoIdNotLive: number
32 let command: LiveCommand
35 33
36 // --------------------------------------------------------------- 34 // ---------------------------------------------------------------
37 35
@@ -66,6 +64,8 @@ describe('Test video lives API validator', function () {
66 { 64 {
67 videoIdNotLive = (await uploadVideoAndGetId({ server, videoName: 'not live' })).id 65 videoIdNotLive = (await uploadVideoAndGetId({ server, videoName: 'not live' })).id
68 } 66 }
67
68 command = server.liveCommand
69 }) 69 })
70 70
71 describe('When creating a live', function () { 71 describe('When creating a live', function () {
@@ -337,70 +337,72 @@ describe('Test video lives API validator', function () {
337 describe('When getting live information', function () { 337 describe('When getting live information', function () {
338 338
339 it('Should fail without access token', async function () { 339 it('Should fail without access token', async function () {
340 await getLive(server.url, '', video.id, HttpStatusCode.UNAUTHORIZED_401) 340 await command.getLive({ token: '', videoId: video.id, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
341 }) 341 })
342 342
343 it('Should fail with a bad access token', async function () { 343 it('Should fail with a bad access token', async function () {
344 await getLive(server.url, 'toto', video.id, HttpStatusCode.UNAUTHORIZED_401) 344 await command.getLive({ token: 'toto', videoId: video.id, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
345 }) 345 })
346 346
347 it('Should fail with access token of another user', async function () { 347 it('Should fail with access token of another user', async function () {
348 await getLive(server.url, userAccessToken, video.id, HttpStatusCode.FORBIDDEN_403) 348 await command.getLive({ token: userAccessToken, videoId: video.id, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
349 }) 349 })
350 350
351 it('Should fail with a bad video id', async function () { 351 it('Should fail with a bad video id', async function () {
352 await getLive(server.url, server.accessToken, 'toto', HttpStatusCode.BAD_REQUEST_400) 352 await command.getLive({ videoId: 'toto', expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
353 }) 353 })
354 354
355 it('Should fail with an unknown video id', async function () { 355 it('Should fail with an unknown video id', async function () {
356 await getLive(server.url, server.accessToken, 454555, HttpStatusCode.NOT_FOUND_404) 356 await command.getLive({ videoId: 454555, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
357 }) 357 })
358 358
359 it('Should fail with a non live video', async function () { 359 it('Should fail with a non live video', async function () {
360 await getLive(server.url, server.accessToken, videoIdNotLive, HttpStatusCode.NOT_FOUND_404) 360 await command.getLive({ videoId: videoIdNotLive, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
361 }) 361 })
362 362
363 it('Should succeed with the correct params', async function () { 363 it('Should succeed with the correct params', async function () {
364 await getLive(server.url, server.accessToken, video.id) 364 await command.getLive({ videoId: video.id })
365 await getLive(server.url, server.accessToken, video.shortUUID) 365 await command.getLive({ videoId: video.uuid })
366 await command.getLive({ videoId: video.shortUUID })
366 }) 367 })
367 }) 368 })
368 369
369 describe('When updating live information', async function () { 370 describe('When updating live information', async function () {
370 371
371 it('Should fail without access token', async function () { 372 it('Should fail without access token', async function () {
372 await updateLive(server.url, '', video.id, {}, HttpStatusCode.UNAUTHORIZED_401) 373 await command.updateLive({ token: '', videoId: video.id, fields: {}, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
373 }) 374 })
374 375
375 it('Should fail with a bad access token', async function () { 376 it('Should fail with a bad access token', async function () {
376 await updateLive(server.url, 'toto', video.id, {}, HttpStatusCode.UNAUTHORIZED_401) 377 await command.updateLive({ token: 'toto', videoId: video.id, fields: {}, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
377 }) 378 })
378 379
379 it('Should fail with access token of another user', async function () { 380 it('Should fail with access token of another user', async function () {
380 await updateLive(server.url, userAccessToken, video.id, {}, HttpStatusCode.FORBIDDEN_403) 381 await command.updateLive({ token: userAccessToken, videoId: video.id, fields: {}, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
381 }) 382 })
382 383
383 it('Should fail with a bad video id', async function () { 384 it('Should fail with a bad video id', async function () {
384 await updateLive(server.url, server.accessToken, 'toto', {}, HttpStatusCode.BAD_REQUEST_400) 385 await command.updateLive({ videoId: 'toto', fields: {}, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
385 }) 386 })
386 387
387 it('Should fail with an unknown video id', async function () { 388 it('Should fail with an unknown video id', async function () {
388 await updateLive(server.url, server.accessToken, 454555, {}, HttpStatusCode.NOT_FOUND_404) 389 await command.updateLive({ videoId: 454555, fields: {}, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
389 }) 390 })
390 391
391 it('Should fail with a non live video', async function () { 392 it('Should fail with a non live video', async function () {
392 await updateLive(server.url, server.accessToken, videoIdNotLive, {}, HttpStatusCode.NOT_FOUND_404) 393 await command.updateLive({ videoId: videoIdNotLive, fields: {}, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
393 }) 394 })
394 395
395 it('Should fail with save replay and permanent live set to true', async function () { 396 it('Should fail with save replay and permanent live set to true', async function () {
396 const fields = { saveReplay: true, permanentLive: true } 397 const fields = { saveReplay: true, permanentLive: true }
397 398
398 await updateLive(server.url, server.accessToken, video.id, fields, HttpStatusCode.BAD_REQUEST_400) 399 await command.updateLive({ videoId: video.id, fields, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
399 }) 400 })
400 401
401 it('Should succeed with the correct params', async function () { 402 it('Should succeed with the correct params', async function () {
402 await updateLive(server.url, server.accessToken, video.id, { saveReplay: false }) 403 await command.updateLive({ videoId: video.id, fields: { saveReplay: false } })
403 await updateLive(server.url, server.accessToken, video.shortUUID, { saveReplay: false }) 404 await command.updateLive({ videoId: video.uuid, fields: { saveReplay: false } })
405 await command.updateLive({ videoId: video.shortUUID, fields: { saveReplay: false } })
404 }) 406 })
405 407
406 it('Should fail to update replay status if replay is not allowed on the instance', async function () { 408 it('Should fail to update replay status if replay is not allowed on the instance', async function () {
@@ -413,36 +415,34 @@ describe('Test video lives API validator', function () {
413 } 415 }
414 }) 416 })
415 417
416 await updateLive(server.url, server.accessToken, video.id, { saveReplay: true }, HttpStatusCode.FORBIDDEN_403) 418 await command.updateLive({ videoId: video.id, fields: { saveReplay: true }, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
417 }) 419 })
418 420
419 it('Should fail to update a live if it has already started', async function () { 421 it('Should fail to update a live if it has already started', async function () {
420 this.timeout(40000) 422 this.timeout(40000)
421 423
422 const resLive = await getLive(server.url, server.accessToken, video.id) 424 const live = await command.getLive({ videoId: video.id })
423 const live: LiveVideo = resLive.body
424 425
425 const command = sendRTMPStream(live.rtmpUrl, live.streamKey) 426 const ffmpegCommand = sendRTMPStream(live.rtmpUrl, live.streamKey)
426 427
427 await waitUntilLivePublished(server.url, server.accessToken, video.id) 428 await command.waitUntilLivePublished({ videoId: video.id })
428 await updateLive(server.url, server.accessToken, video.id, {}, HttpStatusCode.BAD_REQUEST_400) 429 await command.updateLive({ videoId: video.id, fields: {}, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
429 430
430 await stopFfmpeg(command) 431 await stopFfmpeg(ffmpegCommand)
431 }) 432 })
432 433
433 it('Should fail to stream twice in the save live', async function () { 434 it('Should fail to stream twice in the save live', async function () {
434 this.timeout(40000) 435 this.timeout(40000)
435 436
436 const resLive = await getLive(server.url, server.accessToken, video.id) 437 const live = await command.getLive({ videoId: video.id })
437 const live: LiveVideo = resLive.body
438 438
439 const command = sendRTMPStream(live.rtmpUrl, live.streamKey) 439 const ffmpegCommand = sendRTMPStream(live.rtmpUrl, live.streamKey)
440 440
441 await waitUntilLivePublished(server.url, server.accessToken, video.id) 441 await command.waitUntilLivePublished({ videoId: video.id })
442 442
443 await runAndTestFfmpegStreamError(server.url, server.accessToken, video.id, true) 443 await command.runAndTestFfmpegStreamError({ videoId: video.id, shouldHaveError: true })
444 444
445 await stopFfmpeg(command) 445 await stopFfmpeg(ffmpegCommand)
446 }) 446 })
447 }) 447 })
448 448