]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/api/server/stats.ts
Fix auto follow index URL
[github/Chocobozzz/PeerTube.git] / server / tests / api / server / stats.ts
CommitLineData
a1587156 1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
09cababd
C
2
3import * as chai from 'chai'
4import 'mocha'
5import { ServerStats } from '../../../../shared/models/server/server-stats.model'
6import {
7c3b7976 7 cleanupTests,
09cababd
C
8 createUser,
9 doubleFollow,
10 flushAndRunMultipleServers,
11 follow,
baab47ca 12 ServerInfo, unfollow,
09cababd
C
13 uploadVideo,
14 viewVideo,
3cc665f4
C
15 wait,
16 userLogin
94565d52 17} from '../../../../shared/extra-utils'
a1587156 18import { setAccessTokensToServers } from '../../../../shared/extra-utils/index'
94565d52
C
19import { getStats } from '../../../../shared/extra-utils/server/stats'
20import { addVideoCommentThread } from '../../../../shared/extra-utils/videos/video-comments'
21import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
09cababd
C
22
23const expect = chai.expect
24
4b5384f6 25describe('Test stats (excluding redundancy)', function () {
09cababd 26 let servers: ServerInfo[] = []
3cc665f4
C
27 const user = {
28 username: 'user1',
29 password: 'super_password'
30 }
09cababd
C
31
32 before(async function () {
33 this.timeout(60000)
09cababd
C
34 servers = await flushAndRunMultipleServers(3)
35 await setAccessTokensToServers(servers)
36
37 await doubleFollow(servers[0], servers[1])
38
a1587156 39 await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: user.username, password: user.password })
09cababd 40
44b9c0ba 41 const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { fixture: 'video_short.webm' })
09cababd
C
42 const videoUUID = resVideo.body.video.uuid
43
44 await addVideoCommentThread(servers[0].url, servers[0].accessToken, videoUUID, 'comment')
45
46 await viewVideo(servers[0].url, videoUUID)
47
6b616860
C
48 // Wait the video views repeatable job
49 await wait(8000)
50
09cababd 51 await follow(servers[2].url, [ servers[0].url ], servers[2].accessToken)
3cd0734f 52 await waitJobs(servers)
09cababd
C
53 })
54
55 it('Should have the correct stats on instance 1', async function () {
56 const res = await getStats(servers[0].url)
57 const data: ServerStats = res.body
58
59 expect(data.totalLocalVideoComments).to.equal(1)
60 expect(data.totalLocalVideos).to.equal(1)
61 expect(data.totalLocalVideoViews).to.equal(1)
44b9c0ba 62 expect(data.totalLocalVideoFilesSize).to.equal(218910)
09cababd
C
63 expect(data.totalUsers).to.equal(2)
64 expect(data.totalVideoComments).to.equal(1)
65 expect(data.totalVideos).to.equal(1)
66 expect(data.totalInstanceFollowers).to.equal(2)
67 expect(data.totalInstanceFollowing).to.equal(1)
68 })
69
70 it('Should have the correct stats on instance 2', async function () {
71 const res = await getStats(servers[1].url)
72 const data: ServerStats = res.body
73
74 expect(data.totalLocalVideoComments).to.equal(0)
75 expect(data.totalLocalVideos).to.equal(0)
76 expect(data.totalLocalVideoViews).to.equal(0)
848f499d 77 expect(data.totalLocalVideoFilesSize).to.equal(0)
09cababd
C
78 expect(data.totalUsers).to.equal(1)
79 expect(data.totalVideoComments).to.equal(1)
80 expect(data.totalVideos).to.equal(1)
81 expect(data.totalInstanceFollowers).to.equal(1)
82 expect(data.totalInstanceFollowing).to.equal(1)
83 })
84
85 it('Should have the correct stats on instance 3', async function () {
86 const res = await getStats(servers[2].url)
87 const data: ServerStats = res.body
88
89 expect(data.totalLocalVideoComments).to.equal(0)
90 expect(data.totalLocalVideos).to.equal(0)
91 expect(data.totalLocalVideoViews).to.equal(0)
92 expect(data.totalUsers).to.equal(1)
93 expect(data.totalVideoComments).to.equal(1)
94 expect(data.totalVideos).to.equal(1)
95 expect(data.totalInstanceFollowing).to.equal(1)
96 expect(data.totalInstanceFollowers).to.equal(0)
97 })
98
baab47ca 99 it('Should have the correct total videos stats after an unfollow', async function () {
3cc665f4
C
100 this.timeout(15000)
101
baab47ca
C
102 await unfollow(servers[2].url, servers[2].accessToken, servers[0])
103 await waitJobs(servers)
104
105 const res = await getStats(servers[2].url)
106 const data: ServerStats = res.body
107
108 expect(data.totalVideos).to.equal(0)
109 })
110
3cc665f4
C
111 it('Should have the correct active users stats', async function () {
112 const server = servers[0]
113
114 {
115 const res = await getStats(server.url)
116 const data: ServerStats = res.body
117 expect(data.totalDailyActiveUsers).to.equal(1)
118 expect(data.totalWeeklyActiveUsers).to.equal(1)
119 expect(data.totalMonthlyActiveUsers).to.equal(1)
120 }
121
122 {
123 await userLogin(server, user)
124
125 const res = await getStats(server.url)
126 const data: ServerStats = res.body
127 expect(data.totalDailyActiveUsers).to.equal(2)
128 expect(data.totalWeeklyActiveUsers).to.equal(2)
129 expect(data.totalMonthlyActiveUsers).to.equal(2)
130 }
131 })
132
7c3b7976
C
133 after(async function () {
134 await cleanupTests(servers)
09cababd
C
135 })
136})