diff options
author | Chocobozzz <me@florianbigard.com> | 2018-02-28 18:04:46 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2018-02-28 18:04:55 +0100 |
commit | 09cababd79f9d445aa027c93cdfe823745fa041a (patch) | |
tree | f781d6ba78b5c4ce7220dea55f13b21230f203d6 /server/tests | |
parent | 22b59e8099947605085cf65a440f07f37fce6b65 (diff) | |
download | PeerTube-09cababd79f9d445aa027c93cdfe823745fa041a.tar.gz PeerTube-09cababd79f9d445aa027c93cdfe823745fa041a.tar.zst PeerTube-09cababd79f9d445aa027c93cdfe823745fa041a.zip |
Add stats route
Diffstat (limited to 'server/tests')
-rw-r--r-- | server/tests/api/check-params/config.ts | 2 | ||||
-rw-r--r-- | server/tests/api/index-fast.ts | 3 | ||||
-rw-r--r-- | server/tests/api/index-slow.ts | 1 | ||||
-rw-r--r-- | server/tests/api/server/config.ts | 4 | ||||
-rw-r--r-- | server/tests/api/server/stats.ts | 102 | ||||
-rw-r--r-- | server/tests/utils/server/config.ts | 2 | ||||
-rw-r--r-- | server/tests/utils/server/stats.ts | 17 |
7 files changed, 125 insertions, 6 deletions
diff --git a/server/tests/api/check-params/config.ts b/server/tests/api/check-params/config.ts index c1c0a3f59..a66e51a6a 100644 --- a/server/tests/api/check-params/config.ts +++ b/server/tests/api/check-params/config.ts | |||
@@ -2,7 +2,7 @@ | |||
2 | 2 | ||
3 | import { omit } from 'lodash' | 3 | import { omit } from 'lodash' |
4 | import 'mocha' | 4 | import 'mocha' |
5 | import { CustomConfig } from '../../../../shared/models/config/custom-config.model' | 5 | import { CustomConfig } from '../../../../shared/models/server/custom-config.model' |
6 | 6 | ||
7 | import { | 7 | import { |
8 | createUser, flushTests, killallServers, makeDeleteRequest, makeGetRequest, makePutBodyRequest, runServer, ServerInfo, | 8 | createUser, flushTests, killallServers, makeDeleteRequest, makeGetRequest, makePutBodyRequest, runServer, ServerInfo, |
diff --git a/server/tests/api/index-fast.ts b/server/tests/api/index-fast.ts index 9f52310dd..464dcb5e0 100644 --- a/server/tests/api/index-fast.ts +++ b/server/tests/api/index-fast.ts | |||
@@ -1,5 +1,5 @@ | |||
1 | // Order of the tests we want to execute | 1 | // Order of the tests we want to execute |
2 | import './server/config' | 2 | import './server/stats' |
3 | import './check-params' | 3 | import './check-params' |
4 | import './users/users' | 4 | import './users/users' |
5 | import './videos/single-server' | 5 | import './videos/single-server' |
@@ -10,3 +10,4 @@ import './videos/video-description' | |||
10 | import './videos/video-privacy' | 10 | import './videos/video-privacy' |
11 | import './videos/services' | 11 | import './videos/services' |
12 | import './server/email' | 12 | import './server/email' |
13 | import './server/config' | ||
diff --git a/server/tests/api/index-slow.ts b/server/tests/api/index-slow.ts index 0082bcb56..cde546856 100644 --- a/server/tests/api/index-slow.ts +++ b/server/tests/api/index-slow.ts | |||
@@ -1,5 +1,4 @@ | |||
1 | // Order of the tests we want to execute | 1 | // Order of the tests we want to execute |
2 | // import './multiple-servers' | ||
3 | import './videos/video-transcoder' | 2 | import './videos/video-transcoder' |
4 | import './videos/multiple-servers' | 3 | import './videos/multiple-servers' |
5 | import './server/follows' | 4 | import './server/follows' |
diff --git a/server/tests/api/server/config.ts b/server/tests/api/server/config.ts index 048135a34..3d90580d8 100644 --- a/server/tests/api/server/config.ts +++ b/server/tests/api/server/config.ts | |||
@@ -2,8 +2,8 @@ | |||
2 | 2 | ||
3 | import 'mocha' | 3 | import 'mocha' |
4 | import * as chai from 'chai' | 4 | import * as chai from 'chai' |
5 | import { About } from '../../../../shared/models/config/about.model' | 5 | import { About } from '../../../../shared/models/server/about.model' |
6 | import { CustomConfig } from '../../../../shared/models/config/custom-config.model' | 6 | import { CustomConfig } from '../../../../shared/models/server/custom-config.model' |
7 | import { deleteCustomConfig, getAbout, killallServers, reRunServer } from '../../utils' | 7 | import { deleteCustomConfig, getAbout, killallServers, reRunServer } from '../../utils' |
8 | const expect = chai.expect | 8 | const expect = chai.expect |
9 | 9 | ||
diff --git a/server/tests/api/server/stats.ts b/server/tests/api/server/stats.ts new file mode 100644 index 000000000..71d54c0ab --- /dev/null +++ b/server/tests/api/server/stats.ts | |||
@@ -0,0 +1,102 @@ | |||
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 | |||
21 | const expect = chai.expect | ||
22 | |||
23 | describe('Test stats', function () { | ||
24 | let servers: ServerInfo[] = [] | ||
25 | |||
26 | before(async function () { | ||
27 | this.timeout(60000) | ||
28 | |||
29 | await flushTests() | ||
30 | servers = await flushAndRunMultipleServers(3) | ||
31 | await setAccessTokensToServers(servers) | ||
32 | |||
33 | await doubleFollow(servers[0], servers[1]) | ||
34 | |||
35 | const user = { | ||
36 | username: 'user1', | ||
37 | password: 'super_password' | ||
38 | } | ||
39 | await createUser(servers[0].url, servers[0].accessToken, user.username, user.password) | ||
40 | |||
41 | const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, {}) | ||
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 | await follow(servers[2].url, [ servers[0].url ], servers[2].accessToken) | ||
49 | await wait(5000) | ||
50 | }) | ||
51 | |||
52 | it('Should have the correct stats on instance 1', async function () { | ||
53 | const res = await getStats(servers[0].url) | ||
54 | const data: ServerStats = res.body | ||
55 | |||
56 | expect(data.totalLocalVideoComments).to.equal(1) | ||
57 | expect(data.totalLocalVideos).to.equal(1) | ||
58 | expect(data.totalLocalVideoViews).to.equal(1) | ||
59 | expect(data.totalUsers).to.equal(2) | ||
60 | expect(data.totalVideoComments).to.equal(1) | ||
61 | expect(data.totalVideos).to.equal(1) | ||
62 | expect(data.totalInstanceFollowers).to.equal(2) | ||
63 | expect(data.totalInstanceFollowing).to.equal(1) | ||
64 | }) | ||
65 | |||
66 | it('Should have the correct stats on instance 2', async function () { | ||
67 | const res = await getStats(servers[1].url) | ||
68 | const data: ServerStats = res.body | ||
69 | |||
70 | expect(data.totalLocalVideoComments).to.equal(0) | ||
71 | expect(data.totalLocalVideos).to.equal(0) | ||
72 | expect(data.totalLocalVideoViews).to.equal(0) | ||
73 | expect(data.totalUsers).to.equal(1) | ||
74 | expect(data.totalVideoComments).to.equal(1) | ||
75 | expect(data.totalVideos).to.equal(1) | ||
76 | expect(data.totalInstanceFollowers).to.equal(1) | ||
77 | expect(data.totalInstanceFollowing).to.equal(1) | ||
78 | }) | ||
79 | |||
80 | it('Should have the correct stats on instance 3', async function () { | ||
81 | const res = await getStats(servers[2].url) | ||
82 | const data: ServerStats = res.body | ||
83 | |||
84 | expect(data.totalLocalVideoComments).to.equal(0) | ||
85 | expect(data.totalLocalVideos).to.equal(0) | ||
86 | expect(data.totalLocalVideoViews).to.equal(0) | ||
87 | expect(data.totalUsers).to.equal(1) | ||
88 | expect(data.totalVideoComments).to.equal(1) | ||
89 | expect(data.totalVideos).to.equal(1) | ||
90 | expect(data.totalInstanceFollowing).to.equal(1) | ||
91 | expect(data.totalInstanceFollowers).to.equal(0) | ||
92 | }) | ||
93 | |||
94 | after(async function () { | ||
95 | killallServers(servers) | ||
96 | |||
97 | // Keep the logs if the test failed | ||
98 | if (this['ok']) { | ||
99 | await flushTests() | ||
100 | } | ||
101 | }) | ||
102 | }) | ||
diff --git a/server/tests/utils/server/config.ts b/server/tests/utils/server/config.ts index e5411117a..57f95a603 100644 --- a/server/tests/utils/server/config.ts +++ b/server/tests/utils/server/config.ts | |||
@@ -1,5 +1,5 @@ | |||
1 | import { makeDeleteRequest, makeGetRequest, makePutBodyRequest } from '../' | 1 | import { makeDeleteRequest, makeGetRequest, makePutBodyRequest } from '../' |
2 | import { CustomConfig } from '../../../../shared/models/config/custom-config.model' | 2 | import { CustomConfig } from '../../../../shared/models/server/custom-config.model' |
3 | 3 | ||
4 | function getConfig (url: string) { | 4 | function getConfig (url: string) { |
5 | const path = '/api/v1/config' | 5 | const path = '/api/v1/config' |
diff --git a/server/tests/utils/server/stats.ts b/server/tests/utils/server/stats.ts new file mode 100644 index 000000000..9cdec6cff --- /dev/null +++ b/server/tests/utils/server/stats.ts | |||
@@ -0,0 +1,17 @@ | |||
1 | import { makeGetRequest } from '../' | ||
2 | |||
3 | function getStats (url: string) { | ||
4 | const path = '/api/v1/server/stats' | ||
5 | |||
6 | return makeGetRequest({ | ||
7 | url, | ||
8 | path, | ||
9 | statusCodeExpected: 200 | ||
10 | }) | ||
11 | } | ||
12 | |||
13 | // --------------------------------------------------------------------------- | ||
14 | |||
15 | export { | ||
16 | getStats | ||
17 | } | ||