X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Ftests%2Fapi%2Fvideos%2Fvideo-channels.ts;h=3493a723d41693a01e0b58f28a185eee31efaae5;hb=8eb07b01306429abe5c538ff7aa0a16e44fff26f;hp=f3a23bf17127aa967ced09cbd9c10c58a53a22c6;hpb=338eb9d33af690db716805fd2277bf68f473b58f;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/tests/api/videos/video-channels.ts b/server/tests/api/videos/video-channels.ts index f3a23bf17..3493a723d 100644 --- a/server/tests/api/videos/video-channels.ts +++ b/server/tests/api/videos/video-channels.ts @@ -1,8 +1,7 @@ /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ -import * as chai from 'chai' import 'mocha' -import { User, Video, VideoChannel, VideoDetails } from '../../../../shared/index' +import * as chai from 'chai' import { cleanupTests, createUser, @@ -14,7 +13,8 @@ import { updateVideo, updateVideoChannelAvatar, uploadVideo, - userLogin + userLogin, + wait } from '../../../../shared/extra-utils' import { addVideoChannel, @@ -25,9 +25,11 @@ import { getVideoChannelsList, ServerInfo, setAccessTokensToServers, - updateVideoChannel + updateVideoChannel, + viewVideo } from '../../../../shared/extra-utils/index' import { waitJobs } from '../../../../shared/extra-utils/server/jobs' +import { User, Video, VideoChannel, VideoDetails } from '../../../../shared/index' const expect = chai.expect @@ -363,6 +365,62 @@ describe('Test video channels', function () { } }) + it('Should report correct channel views per days', async function () { + this.timeout(10000) + + { + const res = await getAccountVideoChannelsList({ + url: servers[0].url, + accountName: userInfo.account.name + '@' + userInfo.account.host, + withStats: true + }) + + const channels: VideoChannel[] = res.body.data + + for (const channel of channels) { + expect(channel).to.haveOwnProperty('viewsPerDay') + expect(channel.viewsPerDay).to.have.length(30 + 1) // daysPrior + today + + for (const v of channel.viewsPerDay) { + expect(v.date).to.be.an('string') + expect(v.views).to.equal(0) + } + } + } + + { + // video has been posted on channel firstVideoChannelId since last update + await viewVideo(servers[0].url, videoUUID, 204, '0.0.0.1,127.0.0.1') + await viewVideo(servers[0].url, videoUUID, 204, '0.0.0.2,127.0.0.1') + + // Wait the repeatable job + await wait(8000) + + const res = await getAccountVideoChannelsList({ + url: servers[0].url, + accountName: userInfo.account.name + '@' + userInfo.account.host, + withStats: true + }) + const channelWithView = res.body.data.find((channel: VideoChannel) => channel.id === firstVideoChannelId) + expect(channelWithView.viewsPerDay.slice(-1)[0].views).to.equal(2) + } + }) + + it('Should report correct videos count', async function () { + const res = await getAccountVideoChannelsList({ + url: servers[0].url, + accountName: userInfo.account.name + '@' + userInfo.account.host, + withStats: true + }) + const channels: VideoChannel[] = res.body.data + + const totoChannel = channels.find(c => c.name === 'toto_channel') + const rootChannel = channels.find(c => c.name === 'root_channel') + + expect(rootChannel.videosCount).to.equal(1) + expect(totoChannel.videosCount).to.equal(0) + }) + after(async function () { await cleanupTests(servers) })