From e4bf78561763cd84d22ebceb6f371cccf9a356d8 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 6 Nov 2020 16:42:23 +0100 Subject: Handle views for live videos --- server/tests/api/live/live.ts | 77 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) (limited to 'server/tests/api') diff --git a/server/tests/api/live/live.ts b/server/tests/api/live/live.ts index b41b5fc2e..2198114b4 100644 --- a/server/tests/api/live/live.ts +++ b/server/tests/api/live/live.ts @@ -28,9 +28,12 @@ import { testImage, updateCustomSubConfig, updateLive, + viewVideo, + wait, waitJobs, waitUntilLiveStarts } from '../../../../shared/extra-utils' +import { FfmpegCommand } from 'fluent-ffmpeg' const expect = chai.expect @@ -419,6 +422,80 @@ describe('Test live', function () { }) }) + describe('Live views', function () { + let liveVideoId: string + let command: FfmpegCommand + + async function countViews (expected: number) { + for (const server of servers) { + const res = await getVideo(server.url, liveVideoId) + const video: VideoDetails = res.body + + expect(video.views).to.equal(expected) + } + } + + before(async function () { + this.timeout(30000) + + const liveAttributes = { + name: 'live video', + channelId: servers[0].videoChannel.id, + privacy: VideoPrivacy.PUBLIC + } + + const res = await createLive(servers[0].url, servers[0].accessToken, liveAttributes) + liveVideoId = res.body.video.uuid + + command = await sendRTMPStreamInVideo(servers[0].url, servers[0].accessToken, liveVideoId) + await waitUntilLiveStarts(servers[0].url, servers[0].accessToken, liveVideoId) + await waitJobs(servers) + }) + + it('Should display no views for a live', async function () { + await countViews(0) + }) + + it('Should view a live twice and display 1 view', async function () { + this.timeout(30000) + + await viewVideo(servers[0].url, liveVideoId) + await viewVideo(servers[0].url, liveVideoId) + + await wait(5000) + + await waitJobs(servers) + + await countViews(1) + }) + + it('Should wait 5 seconds and display 0 views', async function () { + this.timeout(30000) + + await wait(5000) + await waitJobs(servers) + + await countViews(0) + }) + + it('Should view a live on a remote and on local and display 2 views', async function () { + this.timeout(30000) + + await viewVideo(servers[0].url, liveVideoId) + await viewVideo(servers[1].url, liveVideoId) + await viewVideo(servers[1].url, liveVideoId) + + await wait(5000) + await waitJobs(servers) + + await countViews(2) + }) + + after(async function () { + await stopFfmpeg(command) + }) + }) + describe('Live socket messages', function () { async function createLiveWrapper () { -- cgit v1.2.3