Tests for viewsPerDay
This commit is contained in:
parent
747c562837
commit
714bfcc556
|
@ -191,7 +191,7 @@ export type SummaryOptions = {
|
||||||
'SELECT days.day AS day, ' +
|
'SELECT days.day AS day, ' +
|
||||||
'COALESCE(SUM(views.views), 0) AS views ' +
|
'COALESCE(SUM(views.views), 0) AS views ' +
|
||||||
'FROM days ' +
|
'FROM days ' +
|
||||||
`LEFT JOIN views ON date_trunc('day', "views"."createdAt") = days.day ` +
|
`LEFT JOIN views ON date_trunc('day', "views"."startDate") = date_trunc('day', days.day) ` +
|
||||||
'GROUP BY 1 ' +
|
'GROUP BY 1 ' +
|
||||||
'ORDER BY day ' +
|
'ORDER BY day ' +
|
||||||
') t' +
|
') t' +
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
import * as chai from 'chai'
|
import * as chai from 'chai'
|
||||||
import 'mocha'
|
import 'mocha'
|
||||||
import { User, Video, VideoChannel, VideoDetails } from '../../../../shared/index'
|
import { User, Video, VideoChannel, viewsPerTime, VideoDetails } from '../../../../shared/index'
|
||||||
import {
|
import {
|
||||||
cleanupTests,
|
cleanupTests,
|
||||||
createUser,
|
createUser,
|
||||||
|
@ -14,7 +14,8 @@ import {
|
||||||
updateVideo,
|
updateVideo,
|
||||||
updateVideoChannelAvatar,
|
updateVideoChannelAvatar,
|
||||||
uploadVideo,
|
uploadVideo,
|
||||||
userLogin
|
userLogin,
|
||||||
|
wait
|
||||||
} from '../../../../shared/extra-utils'
|
} from '../../../../shared/extra-utils'
|
||||||
import {
|
import {
|
||||||
addVideoChannel,
|
addVideoChannel,
|
||||||
|
@ -25,7 +26,8 @@ import {
|
||||||
getVideoChannelsList,
|
getVideoChannelsList,
|
||||||
ServerInfo,
|
ServerInfo,
|
||||||
setAccessTokensToServers,
|
setAccessTokensToServers,
|
||||||
updateVideoChannel
|
updateVideoChannel,
|
||||||
|
viewVideo
|
||||||
} from '../../../../shared/extra-utils/index'
|
} from '../../../../shared/extra-utils/index'
|
||||||
import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
|
import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
|
||||||
|
|
||||||
|
@ -363,6 +365,42 @@ describe('Test video channels', function () {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
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 () {
|
after(async function () {
|
||||||
await cleanupTests(servers)
|
await cleanupTests(servers)
|
||||||
})
|
})
|
||||||
|
|
|
@ -8,7 +8,7 @@ import { ServerInfo } from '../server/servers'
|
||||||
import { User } from '../../models/users/user.model'
|
import { User } from '../../models/users/user.model'
|
||||||
import { getMyUserInformation } from '../users/users'
|
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 path = '/api/v1/video-channels'
|
||||||
|
|
||||||
const req = request(url)
|
const req = request(url)
|
||||||
|
@ -17,6 +17,7 @@ function getVideoChannelsList (url: string, start: number, count: number, sort?:
|
||||||
.query({ count: count })
|
.query({ count: count })
|
||||||
|
|
||||||
if (sort) req.query({ sort })
|
if (sort) req.query({ sort })
|
||||||
|
if (withStats) req.query({ withStats })
|
||||||
|
|
||||||
return req.set('Accept', 'application/json')
|
return req.set('Accept', 'application/json')
|
||||||
.expect(200)
|
.expect(200)
|
||||||
|
@ -30,8 +31,9 @@ function getAccountVideoChannelsList (parameters: {
|
||||||
count?: number
|
count?: number
|
||||||
sort?: string
|
sort?: string
|
||||||
specialStatus?: number
|
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'
|
const path = '/api/v1/accounts/' + accountName + '/video-channels'
|
||||||
|
|
||||||
|
@ -41,7 +43,8 @@ function getAccountVideoChannelsList (parameters: {
|
||||||
query: {
|
query: {
|
||||||
start,
|
start,
|
||||||
count,
|
count,
|
||||||
sort
|
sort,
|
||||||
|
withStats
|
||||||
},
|
},
|
||||||
statusCodeExpected: specialStatus
|
statusCodeExpected: specialStatus
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue