import * as chai from 'chai'
import 'mocha'
-import { User, Video, VideoChannel, VideoDetails } from '../../../../shared/index'
+import { User, Video, VideoChannel, viewsPerTime, VideoDetails } from '../../../../shared/index'
import {
cleanupTests,
createUser,
updateVideo,
updateVideoChannelAvatar,
uploadVideo,
- userLogin
+ userLogin,
+ wait
} from '../../../../shared/extra-utils'
import {
addVideoChannel,
getVideoChannelsList,
ServerInfo,
setAccessTokensToServers,
- updateVideoChannel
+ updateVideoChannel,
+ viewVideo
} from '../../../../shared/extra-utils/index'
import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
}
})
+ it('Should report correct channel statistics', async function () {
+
+ {
+ const res = await getAccountVideoChannelsList({
+ url: servers[0].url,
+ accountName: userInfo.account.name + '@' + userInfo.account.host,
+ withStats: true
+ })
+ res.body.data.forEach((channel: VideoChannel) => {
+ expect(channel).to.haveOwnProperty('viewsPerDay')
+ expect(channel.viewsPerDay).to.have.length(30 + 1) // daysPrior + today
+ channel.viewsPerDay.forEach((v: viewsPerTime) => {
+ 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)
+ }
+ })
+
after(async function () {
await cleanupTests(servers)
})
import { User } from '../../models/users/user.model'
import { getMyUserInformation } from '../users/users'
-function getVideoChannelsList (url: string, start: number, count: number, sort?: string) {
+function getVideoChannelsList (url: string, start: number, count: number, sort?: string, withStats?: boolean) {
const path = '/api/v1/video-channels'
const req = request(url)
.query({ count: count })
if (sort) req.query({ sort })
+ if (withStats) req.query({ withStats })
return req.set('Accept', 'application/json')
.expect(200)
count?: number
sort?: string
specialStatus?: number
+ withStats?: boolean
}) {
- const { url, accountName, start, count, sort = 'createdAt', specialStatus = 200 } = parameters
+ const { url, accountName, start, count, sort = 'createdAt', specialStatus = 200, withStats = false } = parameters
const path = '/api/v1/accounts/' + accountName + '/video-channels'
query: {
start,
count,
- sort
+ sort,
+ withStats
},
statusCodeExpected: specialStatus
})