]>
Commit | Line | Data |
---|---|---|
9f10b292 | 1 | 'use strict' |
34ca3b52 | 2 | |
f0f5567b C |
3 | const async = require('async') |
4 | const chai = require('chai') | |
5 | const expect = chai.expect | |
6 | const pathUtils = require('path') | |
7 | const request = require('supertest') | |
34ca3b52 | 8 | |
f0f5567b | 9 | const utils = require('./utils') |
34ca3b52 | 10 | |
9f10b292 | 11 | describe('Test parameters validator', function () { |
0c1cbbfe | 12 | let server = null |
34ca3b52 | 13 | |
0c1cbbfe | 14 | function makePostRequest (path, token, fields, attach, done, fail) { |
bc503c2a C |
15 | let statusCode = 400 |
16 | if (fail !== undefined && fail === false) statusCode = 200 | |
34ca3b52 | 17 | |
0c1cbbfe | 18 | const req = request(server.url) |
9f10b292 C |
19 | .post(path) |
20 | .set('Accept', 'application/json') | |
34ca3b52 | 21 | |
0c1cbbfe C |
22 | if (token) req.set('Authorization', 'Bearer ' + token) |
23 | ||
9f10b292 | 24 | Object.keys(fields).forEach(function (field) { |
f0f5567b | 25 | const value = fields[field] |
9f10b292 | 26 | req.field(field, value) |
ee66c593 C |
27 | }) |
28 | ||
bc503c2a | 29 | req.expect(statusCode, done) |
9f10b292 C |
30 | } |
31 | ||
32 | function makePostBodyRequest (path, fields, done, fail) { | |
bc503c2a C |
33 | let statusCode = 400 |
34 | if (fail !== undefined && fail === false) statusCode = 200 | |
9f10b292 | 35 | |
0c1cbbfe | 36 | request(server.url) |
9f10b292 C |
37 | .post(path) |
38 | .set('Accept', 'application/json') | |
39 | .send(fields) | |
bc503c2a | 40 | .expect(statusCode, done) |
9f10b292 C |
41 | } |
42 | ||
43 | // --------------------------------------------------------------- | |
44 | ||
45 | before(function (done) { | |
46 | this.timeout(20000) | |
47 | ||
48 | async.series([ | |
49 | function (next) { | |
50 | utils.flushTests(next) | |
51 | }, | |
52 | function (next) { | |
0c1cbbfe C |
53 | utils.runServer(1, function (server1) { |
54 | server = server1 | |
55 | ||
56 | next() | |
57 | }) | |
58 | }, | |
59 | function (next) { | |
60 | utils.loginAndGetAccessToken(server, function (err, token) { | |
61 | if (err) throw err | |
62 | server.access_token = token | |
63 | ||
9f10b292 | 64 | next() |
34ca3b52 | 65 | }) |
9f10b292 C |
66 | } |
67 | ], done) | |
68 | }) | |
69 | ||
70 | describe('Of the pods API', function () { | |
f0f5567b | 71 | const path = '/api/v1/pods/' |
9f10b292 C |
72 | |
73 | describe('When adding a pod', function () { | |
74 | it('Should fail with nothing', function (done) { | |
f0f5567b | 75 | const data = {} |
9f10b292 C |
76 | makePostBodyRequest(path, data, done) |
77 | }) | |
34ca3b52 | 78 | |
9f10b292 | 79 | it('Should fail without public key', function (done) { |
f0f5567b | 80 | const data = { |
9f10b292 C |
81 | data: { |
82 | url: 'http://coucou.com' | |
34ca3b52 | 83 | } |
9f10b292 C |
84 | } |
85 | makePostBodyRequest(path, data, done) | |
86 | }) | |
34ca3b52 | 87 | |
9f10b292 | 88 | it('Should fail without an url', function (done) { |
f0f5567b | 89 | const data = { |
9f10b292 C |
90 | data: { |
91 | publicKey: 'mysuperpublickey' | |
34ca3b52 | 92 | } |
9f10b292 C |
93 | } |
94 | makePostBodyRequest(path, data, done) | |
95 | }) | |
34ca3b52 | 96 | |
9f10b292 | 97 | it('Should fail with an incorrect url', function (done) { |
f0f5567b | 98 | const data = { |
9f10b292 C |
99 | data: { |
100 | url: 'coucou.com', | |
101 | publicKey: 'mysuperpublickey' | |
34ca3b52 | 102 | } |
9f10b292 C |
103 | } |
104 | makePostBodyRequest(path, data, function () { | |
105 | data.data.url = 'http://coucou' | |
34ca3b52 | 106 | makePostBodyRequest(path, data, function () { |
9f10b292 C |
107 | data.data.url = 'coucou' |
108 | makePostBodyRequest(path, data, done) | |
34ca3b52 C |
109 | }) |
110 | }) | |
9f10b292 | 111 | }) |
34ca3b52 | 112 | |
9f10b292 | 113 | it('Should succeed with the correct parameters', function (done) { |
f0f5567b | 114 | const data = { |
9f10b292 C |
115 | data: { |
116 | url: 'http://coucou.com', | |
117 | publicKey: 'mysuperpublickey' | |
34ca3b52 | 118 | } |
9f10b292 C |
119 | } |
120 | makePostBodyRequest(path, data, done, false) | |
34ca3b52 C |
121 | }) |
122 | }) | |
9f10b292 | 123 | }) |
34ca3b52 | 124 | |
9f10b292 | 125 | describe('Of the videos API', function () { |
f0f5567b | 126 | const path = '/api/v1/videos/' |
34ca3b52 | 127 | |
9f10b292 C |
128 | describe('When searching a video', function () { |
129 | it('Should fail with nothing', function (done) { | |
0c1cbbfe | 130 | request(server.url) |
9f10b292 C |
131 | .get(pathUtils.join(path, 'search')) |
132 | .set('Accept', 'application/json') | |
133 | .expect(400, done) | |
34ca3b52 | 134 | }) |
9f10b292 | 135 | }) |
34ca3b52 | 136 | |
9f10b292 C |
137 | describe('When adding a video', function () { |
138 | it('Should fail with nothing', function (done) { | |
f0f5567b C |
139 | const data = {} |
140 | const attach = {} | |
0c1cbbfe | 141 | makePostRequest(path, server.access_token, data, attach, done) |
9f10b292 | 142 | }) |
34ca3b52 | 143 | |
9f10b292 | 144 | it('Should fail without name', function (done) { |
f0f5567b | 145 | const data = { |
9f10b292 C |
146 | description: 'my super description' |
147 | } | |
f0f5567b | 148 | const attach = { |
8c9c1942 | 149 | 'videofile': pathUtils.join(__dirname, 'fixtures', 'video_short.webm') |
9f10b292 | 150 | } |
0c1cbbfe | 151 | makePostRequest(path, server.access_token, data, attach, done) |
9f10b292 | 152 | }) |
34ca3b52 | 153 | |
9f10b292 | 154 | it('Should fail with a long name', function (done) { |
f0f5567b | 155 | const data = { |
9f10b292 C |
156 | name: 'My very very very very very very very very very very very very very very very very long name', |
157 | description: 'my super description' | |
158 | } | |
f0f5567b | 159 | const attach = { |
8c9c1942 | 160 | 'videofile': pathUtils.join(__dirname, 'fixtures', 'video_short.webm') |
9f10b292 | 161 | } |
0c1cbbfe | 162 | makePostRequest(path, server.access_token, data, attach, done) |
9f10b292 | 163 | }) |
34ca3b52 | 164 | |
9f10b292 | 165 | it('Should fail without description', function (done) { |
f0f5567b | 166 | const data = { |
9f10b292 C |
167 | name: 'my super name' |
168 | } | |
f0f5567b | 169 | const attach = { |
8c9c1942 | 170 | 'videofile': pathUtils.join(__dirname, 'fixtures', 'video_short.webm') |
9f10b292 | 171 | } |
0c1cbbfe | 172 | makePostRequest(path, server.access_token, data, attach, done) |
9f10b292 | 173 | }) |
34ca3b52 | 174 | |
9f10b292 | 175 | it('Should fail with a long description', function (done) { |
f0f5567b | 176 | const data = { |
9f10b292 C |
177 | name: 'my super name', |
178 | description: 'my super description which is very very very very very very very very very very very very very very' + | |
179 | 'very very very very very very very very very very very very very very very very very very very very very' + | |
180 | 'very very very very very very very very very very very very very very very long' | |
181 | } | |
f0f5567b | 182 | const attach = { |
8c9c1942 | 183 | 'videofile': pathUtils.join(__dirname, 'fixtures', 'video_short.webm') |
9f10b292 | 184 | } |
0c1cbbfe | 185 | makePostRequest(path, server.access_token, data, attach, done) |
9f10b292 | 186 | }) |
34ca3b52 | 187 | |
9f10b292 | 188 | it('Should fail without an input file', function (done) { |
f0f5567b | 189 | const data = { |
9f10b292 C |
190 | name: 'my super name', |
191 | description: 'my super description' | |
192 | } | |
f0f5567b | 193 | const attach = {} |
0c1cbbfe | 194 | makePostRequest(path, server.access_token, data, attach, done) |
9f10b292 | 195 | }) |
34ca3b52 | 196 | |
9f10b292 | 197 | it('Should fail without an incorrect input file', function (done) { |
f0f5567b | 198 | const data = { |
9f10b292 C |
199 | name: 'my super name', |
200 | description: 'my super description' | |
201 | } | |
f0f5567b | 202 | const attach = { |
8c9c1942 | 203 | 'videofile': pathUtils.join(__dirname, '..', 'fixtures', 'video_short_fake.webm') |
9f10b292 | 204 | } |
0c1cbbfe | 205 | makePostRequest(path, server.access_token, data, attach, done) |
9f10b292 | 206 | }) |
34ca3b52 | 207 | |
9f10b292 | 208 | it('Should succeed with the correct parameters', function (done) { |
f0f5567b | 209 | const data = { |
9f10b292 C |
210 | name: 'my super name', |
211 | description: 'my super description' | |
212 | } | |
f0f5567b | 213 | const attach = { |
8c9c1942 | 214 | 'videofile': pathUtils.join(__dirname, 'fixtures', 'video_short.webm') |
9f10b292 | 215 | } |
0c1cbbfe | 216 | makePostRequest(path, server.access_token, data, attach, function () { |
8c9c1942 | 217 | attach.videofile = pathUtils.join(__dirname, 'fixtures', 'video_short.mp4') |
0c1cbbfe | 218 | makePostRequest(path, server.access_token, data, attach, function () { |
8c9c1942 | 219 | attach.videofile = pathUtils.join(__dirname, 'fixtures', 'video_short.ogv') |
0c1cbbfe | 220 | makePostRequest(path, server.access_token, data, attach, done, true) |
34ca3b52 | 221 | }, true) |
9f10b292 | 222 | }, true) |
34ca3b52 | 223 | }) |
9f10b292 | 224 | }) |
34ca3b52 | 225 | |
9f10b292 C |
226 | describe('When getting a video', function () { |
227 | it('Should return the list of the videos with nothing', function (done) { | |
0c1cbbfe | 228 | request(server.url) |
9f10b292 C |
229 | .get(path) |
230 | .set('Accept', 'application/json') | |
231 | .expect(200) | |
232 | .expect('Content-Type', /json/) | |
233 | .end(function (err, res) { | |
234 | if (err) throw err | |
34ca3b52 | 235 | |
9f10b292 C |
236 | expect(res.body).to.be.an('array') |
237 | expect(res.body.length).to.equal(0) | |
34ca3b52 | 238 | |
9f10b292 C |
239 | done() |
240 | }) | |
241 | }) | |
34ca3b52 | 242 | |
9f10b292 | 243 | it('Should fail without a mongodb id', function (done) { |
0c1cbbfe | 244 | request(server.url) |
9f10b292 C |
245 | .get(path + 'coucou') |
246 | .set('Accept', 'application/json') | |
247 | .expect(400, done) | |
34ca3b52 C |
248 | }) |
249 | ||
9f10b292 | 250 | it('Should return 404 with an incorrect video', function (done) { |
0c1cbbfe | 251 | request(server.url) |
9f10b292 C |
252 | .get(path + '123456789012345678901234') |
253 | .set('Accept', 'application/json') | |
34ca3b52 | 254 | .expect(404, done) |
34ca3b52 | 255 | }) |
9f10b292 C |
256 | |
257 | it('Should succeed with the correct parameters') | |
34ca3b52 C |
258 | }) |
259 | ||
9f10b292 C |
260 | describe('When removing a video', function () { |
261 | it('Should have 404 with nothing', function (done) { | |
0c1cbbfe C |
262 | request(server.url) |
263 | .delete(path) | |
264 | .set('Authorization', 'Bearer ' + server.access_token) | |
265 | .expect(400, done) | |
34ca3b52 C |
266 | }) |
267 | ||
9f10b292 | 268 | it('Should fail without a mongodb id', function (done) { |
0c1cbbfe | 269 | request(server.url) |
9f10b292 | 270 | .delete(path + 'hello') |
0c1cbbfe | 271 | .set('Authorization', 'Bearer ' + server.access_token) |
9f10b292 | 272 | .expect(400, done) |
34ca3b52 C |
273 | }) |
274 | ||
9f10b292 | 275 | it('Should fail with a video which does not exist', function (done) { |
0c1cbbfe | 276 | request(server.url) |
9f10b292 | 277 | .delete(path + '123456789012345678901234') |
0c1cbbfe | 278 | .set('Authorization', 'Bearer ' + server.access_token) |
9f10b292 | 279 | .expect(404, done) |
34ca3b52 | 280 | }) |
9f10b292 C |
281 | |
282 | it('Should fail with a video of another pod') | |
283 | ||
284 | it('Should succeed with the correct parameters') | |
34ca3b52 | 285 | }) |
9f10b292 | 286 | }) |
34ca3b52 | 287 | |
9f10b292 C |
288 | describe('Of the remote videos API', function () { |
289 | describe('When making a secure request', function () { | |
290 | it('Should check a secure request') | |
291 | }) | |
34ca3b52 | 292 | |
9f10b292 C |
293 | describe('When adding a video', function () { |
294 | it('Should check when adding a video') | |
34ca3b52 | 295 | }) |
9f10b292 C |
296 | |
297 | describe('When removing a video', function () { | |
298 | it('Should check when removing a video') | |
299 | }) | |
300 | }) | |
301 | ||
302 | after(function (done) { | |
0c1cbbfe | 303 | process.kill(-server.app.pid) |
9f10b292 C |
304 | |
305 | // Keep the logs if the test failed | |
306 | if (this.ok) { | |
307 | utils.flushTests(done) | |
308 | } else { | |
309 | done() | |
310 | } | |
34ca3b52 | 311 | }) |
9f10b292 | 312 | }) |