diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2016-09-19 21:33:46 +0200 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2016-09-19 21:33:46 +0200 |
commit | d3cd34be2fd03ea79145dfa8eb16e82d2e23191b (patch) | |
tree | 8db702444c4b72cec9de25efb2da5df0aa51cfce /server/tests | |
parent | 2e92c10b6cdb32e5170aab0b4c0ff3e4c27e30d5 (diff) | |
download | PeerTube-d3cd34be2fd03ea79145dfa8eb16e82d2e23191b.tar.gz PeerTube-d3cd34be2fd03ea79145dfa8eb16e82d2e23191b.tar.zst PeerTube-d3cd34be2fd03ea79145dfa8eb16e82d2e23191b.zip |
Server: add requests stats endpoint
Diffstat (limited to 'server/tests')
-rw-r--r-- | server/tests/api/check-params.js | 21 | ||||
-rw-r--r-- | server/tests/api/requests.js | 128 |
2 files changed, 148 insertions, 1 deletions
diff --git a/server/tests/api/check-params.js b/server/tests/api/check-params.js index f060b2ad4..a696bc171 100644 --- a/server/tests/api/check-params.js +++ b/server/tests/api/check-params.js | |||
@@ -13,6 +13,7 @@ const usersUtils = require('../utils/users') | |||
13 | 13 | ||
14 | describe('Test parameters validator', function () { | 14 | describe('Test parameters validator', function () { |
15 | let server = null | 15 | let server = null |
16 | let userAccessToken = null | ||
16 | 17 | ||
17 | // --------------------------------------------------------------- | 18 | // --------------------------------------------------------------- |
18 | 19 | ||
@@ -496,7 +497,6 @@ describe('Test parameters validator', function () { | |||
496 | describe('Of the users API', function () { | 497 | describe('Of the users API', function () { |
497 | const path = '/api/v1/users/' | 498 | const path = '/api/v1/users/' |
498 | let userId = null | 499 | let userId = null |
499 | let userAccessToken = null | ||
500 | 500 | ||
501 | describe('When listing users', function () { | 501 | describe('When listing users', function () { |
502 | it('Should fail with a bad start pagination', function (done) { | 502 | it('Should fail with a bad start pagination', function (done) { |
@@ -721,6 +721,25 @@ describe('Test parameters validator', function () { | |||
721 | }) | 721 | }) |
722 | }) | 722 | }) |
723 | 723 | ||
724 | describe('Of the requests API', function () { | ||
725 | const path = '/api/v1/requests/stats' | ||
726 | |||
727 | it('Should fail with an non authenticated user', function (done) { | ||
728 | request(server.url) | ||
729 | .get(path) | ||
730 | .set('Accept', 'application/json') | ||
731 | .expect(401, done) | ||
732 | }) | ||
733 | |||
734 | it('Should fail with a non admin user', function (done) { | ||
735 | request(server.url) | ||
736 | .get(path) | ||
737 | .set('Authorization', 'Bearer ' + userAccessToken) | ||
738 | .set('Accept', 'application/json') | ||
739 | .expect(403, done) | ||
740 | }) | ||
741 | }) | ||
742 | |||
724 | after(function (done) { | 743 | after(function (done) { |
725 | process.kill(-server.app.pid) | 744 | process.kill(-server.app.pid) |
726 | 745 | ||
diff --git a/server/tests/api/requests.js b/server/tests/api/requests.js new file mode 100644 index 000000000..af36f6e34 --- /dev/null +++ b/server/tests/api/requests.js | |||
@@ -0,0 +1,128 @@ | |||
1 | 'use strict' | ||
2 | |||
3 | const chai = require('chai') | ||
4 | const each = require('async/each') | ||
5 | const expect = chai.expect | ||
6 | const request = require('supertest') | ||
7 | |||
8 | const loginUtils = require('../utils/login') | ||
9 | const podsUtils = require('../utils/pods') | ||
10 | const serversUtils = require('../utils/servers') | ||
11 | const videosUtils = require('../utils/videos') | ||
12 | |||
13 | describe('Test requests stats', function () { | ||
14 | const path = '/api/v1/requests/stats' | ||
15 | let servers = [] | ||
16 | |||
17 | function uploadVideo (server, callback) { | ||
18 | const name = 'my super video' | ||
19 | const description = 'my super description' | ||
20 | const tags = [ 'tag1', 'tag2' ] | ||
21 | const fixture = 'video_short.webm' | ||
22 | |||
23 | videosUtils.uploadVideo(server.url, server.accessToken, name, description, tags, fixture, callback) | ||
24 | } | ||
25 | |||
26 | function getRequestsStats (server, callback) { | ||
27 | request(server.url) | ||
28 | .get(path) | ||
29 | .set('Accept', 'application/json') | ||
30 | .set('Authorization', 'Bearer ' + server.accessToken) | ||
31 | .expect(200) | ||
32 | .end(callback) | ||
33 | } | ||
34 | |||
35 | // --------------------------------------------------------------- | ||
36 | |||
37 | before(function (done) { | ||
38 | this.timeout(20000) | ||
39 | serversUtils.flushAndRunMultipleServers(2, function (serversRun, urlsRun) { | ||
40 | servers = serversRun | ||
41 | |||
42 | each(servers, function (server, callbackEach) { | ||
43 | loginUtils.loginAndGetAccessToken(server, function (err, accessToken) { | ||
44 | if (err) return callbackEach(err) | ||
45 | |||
46 | server.accessToken = accessToken | ||
47 | callbackEach() | ||
48 | }) | ||
49 | }, function (err) { | ||
50 | if (err) throw err | ||
51 | |||
52 | const server1 = servers[0] | ||
53 | podsUtils.makeFriends(server1.url, server1.accessToken, done) | ||
54 | }) | ||
55 | }) | ||
56 | }) | ||
57 | |||
58 | it('Should have a correct timer', function (done) { | ||
59 | const server = servers[0] | ||
60 | |||
61 | getRequestsStats(server, function (err, res) { | ||
62 | if (err) throw err | ||
63 | |||
64 | const body = res.body | ||
65 | expect(body.remainingMilliSeconds).to.be.at.least(0) | ||
66 | expect(body.remainingMilliSeconds).to.be.at.most(10000) | ||
67 | |||
68 | done() | ||
69 | }) | ||
70 | }) | ||
71 | |||
72 | it('Should have the correct request', function (done) { | ||
73 | this.timeout(15000) | ||
74 | |||
75 | const server = servers[0] | ||
76 | // Ensure the requests of pod 1 won't be made | ||
77 | servers[1].app.kill() | ||
78 | |||
79 | uploadVideo(server, function (err) { | ||
80 | if (err) throw err | ||
81 | |||
82 | getRequestsStats(server, function (err, res) { | ||
83 | if (err) throw err | ||
84 | |||
85 | const body = res.body | ||
86 | expect(body.requests).to.have.lengthOf(1) | ||
87 | |||
88 | const request = body.requests[0] | ||
89 | expect(request.to).to.have.lengthOf(1) | ||
90 | expect(request.request.type).to.equal('add') | ||
91 | |||
92 | // Wait one cycle | ||
93 | setTimeout(done, 10000) | ||
94 | }) | ||
95 | }) | ||
96 | }) | ||
97 | |||
98 | it('Should have the correct requests', function (done) { | ||
99 | const server = servers[0] | ||
100 | |||
101 | uploadVideo(server, function (err) { | ||
102 | if (err) throw err | ||
103 | |||
104 | getRequestsStats(server, function (err, res) { | ||
105 | if (err) throw err | ||
106 | |||
107 | const body = res.body | ||
108 | expect(body.requests).to.have.lengthOf(2) | ||
109 | |||
110 | const request = body.requests[1] | ||
111 | expect(request.to).to.have.lengthOf(1) | ||
112 | expect(request.request.type).to.equal('add') | ||
113 | |||
114 | done() | ||
115 | }) | ||
116 | }) | ||
117 | }) | ||
118 | |||
119 | after(function (done) { | ||
120 | process.kill(-servers[0].app.pid) | ||
121 | |||
122 | if (this.ok) { | ||
123 | serversUtils.flushTests(done) | ||
124 | } else { | ||
125 | done() | ||
126 | } | ||
127 | }) | ||
128 | }) | ||