]>
Commit | Line | Data |
---|---|---|
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ | |
2 | ||
3 | import * as chai from 'chai' | |
4 | import 'mocha' | |
5 | import { ServerStats } from '../../../../shared/models/server/server-stats.model' | |
6 | import { | |
7 | cleanupTests, | |
8 | createUser, | |
9 | doubleFollow, | |
10 | flushAndRunMultipleServers, | |
11 | follow, | |
12 | ServerInfo, unfollow, | |
13 | uploadVideo, | |
14 | viewVideo, | |
15 | wait, | |
16 | userLogin | |
17 | } from '../../../../shared/extra-utils' | |
18 | import { setAccessTokensToServers } from '../../../../shared/extra-utils/index' | |
19 | import { getStats } from '../../../../shared/extra-utils/server/stats' | |
20 | import { addVideoCommentThread } from '../../../../shared/extra-utils/videos/video-comments' | |
21 | import { waitJobs } from '../../../../shared/extra-utils/server/jobs' | |
22 | ||
23 | const expect = chai.expect | |
24 | ||
25 | describe('Test stats (excluding redundancy)', function () { | |
26 | let servers: ServerInfo[] = [] | |
27 | const user = { | |
28 | username: 'user1', | |
29 | password: 'super_password' | |
30 | } | |
31 | ||
32 | before(async function () { | |
33 | this.timeout(60000) | |
34 | servers = await flushAndRunMultipleServers(3) | |
35 | await setAccessTokensToServers(servers) | |
36 | ||
37 | await doubleFollow(servers[0], servers[1]) | |
38 | ||
39 | await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: user.username, password: user.password }) | |
40 | ||
41 | const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { fixture: 'video_short.webm' }) | |
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 | ||
48 | // Wait the video views repeatable job | |
49 | await wait(8000) | |
50 | ||
51 | await follow(servers[2].url, [ servers[0].url ], servers[2].accessToken) | |
52 | await waitJobs(servers) | |
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) | |
62 | expect(data.totalLocalVideoFilesSize).to.equal(218910) | |
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) | |
77 | expect(data.totalLocalVideoFilesSize).to.equal(0) | |
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 | ||
99 | it('Should have the correct total videos stats after an unfollow', async function () { | |
100 | this.timeout(15000) | |
101 | ||
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 | ||
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 | ||
133 | after(async function () { | |
134 | await cleanupTests(servers) | |
135 | }) | |
136 | }) |