aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api/requests.js
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests/api/requests.js')
-rw-r--r--server/tests/api/requests.js128
1 files changed, 128 insertions, 0 deletions
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
3const chai = require('chai')
4const each = require('async/each')
5const expect = chai.expect
6const request = require('supertest')
7
8const loginUtils = require('../utils/login')
9const podsUtils = require('../utils/pods')
10const serversUtils = require('../utils/servers')
11const videosUtils = require('../utils/videos')
12
13describe('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})