Fix images size limit
[oweals/peertube.git] / server / tests / api / server / stats.ts
1 /* tslint:disable:no-unused-expression */
2
3 import * as chai from 'chai'
4 import 'mocha'
5 import { ServerStats } from '../../../../shared/models/server/server-stats.model'
6 import {
7   createUser,
8   doubleFollow,
9   flushAndRunMultipleServers,
10   follow,
11   killallServers,
12   ServerInfo,
13   uploadVideo,
14   viewVideo,
15   wait
16 } from '../../utils'
17 import { flushTests, setAccessTokensToServers } from '../../utils/index'
18 import { getStats } from '../../utils/server/stats'
19 import { addVideoCommentThread } from '../../utils/videos/video-comments'
20 import { waitJobs } from '../../utils/server/jobs'
21
22 const expect = chai.expect
23
24 describe('Test stats', function () {
25   let servers: ServerInfo[] = []
26
27   before(async function () {
28     this.timeout(60000)
29
30     await flushTests()
31     servers = await flushAndRunMultipleServers(3)
32     await setAccessTokensToServers(servers)
33
34     await doubleFollow(servers[0], servers[1])
35
36     const user = {
37       username: 'user1',
38       password: 'super_password'
39     }
40     await createUser(servers[0].url, servers[0].accessToken, user.username, user.password)
41
42     const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, {})
43     const videoUUID = resVideo.body.video.uuid
44
45     await addVideoCommentThread(servers[0].url, servers[0].accessToken, videoUUID, 'comment')
46
47     await viewVideo(servers[0].url, videoUUID)
48
49     await follow(servers[2].url, [ servers[0].url ], servers[2].accessToken)
50     await waitJobs(servers)
51   })
52
53   it('Should have the correct stats on instance 1', async function () {
54     const res = await getStats(servers[0].url)
55     const data: ServerStats = res.body
56
57     expect(data.totalLocalVideoComments).to.equal(1)
58     expect(data.totalLocalVideos).to.equal(1)
59     expect(data.totalLocalVideoViews).to.equal(1)
60     expect(data.totalUsers).to.equal(2)
61     expect(data.totalVideoComments).to.equal(1)
62     expect(data.totalVideos).to.equal(1)
63     expect(data.totalInstanceFollowers).to.equal(2)
64     expect(data.totalInstanceFollowing).to.equal(1)
65   })
66
67   it('Should have the correct stats on instance 2', async function () {
68     const res = await getStats(servers[1].url)
69     const data: ServerStats = res.body
70
71     expect(data.totalLocalVideoComments).to.equal(0)
72     expect(data.totalLocalVideos).to.equal(0)
73     expect(data.totalLocalVideoViews).to.equal(0)
74     expect(data.totalUsers).to.equal(1)
75     expect(data.totalVideoComments).to.equal(1)
76     expect(data.totalVideos).to.equal(1)
77     expect(data.totalInstanceFollowers).to.equal(1)
78     expect(data.totalInstanceFollowing).to.equal(1)
79   })
80
81   it('Should have the correct stats on instance 3', async function () {
82     const res = await getStats(servers[2].url)
83     const data: ServerStats = res.body
84
85     expect(data.totalLocalVideoComments).to.equal(0)
86     expect(data.totalLocalVideos).to.equal(0)
87     expect(data.totalLocalVideoViews).to.equal(0)
88     expect(data.totalUsers).to.equal(1)
89     expect(data.totalVideoComments).to.equal(1)
90     expect(data.totalVideos).to.equal(1)
91     expect(data.totalInstanceFollowing).to.equal(1)
92     expect(data.totalInstanceFollowers).to.equal(0)
93   })
94
95   after(async function () {
96     killallServers(servers)
97   })
98 })