]>
Commit | Line | Data |
---|---|---|
9f10b292 | 1 | 'use strict' |
34ca3b52 | 2 | |
f0f5567b C |
3 | const chai = require('chai') |
4 | const expect = chai.expect | |
5 | const pathUtils = require('path') | |
6 | const request = require('supertest') | |
1a42c9e2 | 7 | const series = require('async/series') |
34ca3b52 | 8 | |
8d309058 | 9 | const loginUtils = require('../utils/login') |
25ed57f3 | 10 | const requestsUtils = require('../utils/requests') |
8d309058 C |
11 | const serversUtils = require('../utils/servers') |
12 | const usersUtils = require('../utils/users') | |
34ca3b52 | 13 | |
9f10b292 | 14 | describe('Test parameters validator', function () { |
0c1cbbfe | 15 | let server = null |
d3cd34be | 16 | let userAccessToken = null |
34ca3b52 | 17 | |
9f10b292 C |
18 | // --------------------------------------------------------------- |
19 | ||
20 | before(function (done) { | |
21 | this.timeout(20000) | |
22 | ||
1a42c9e2 | 23 | series([ |
9f10b292 | 24 | function (next) { |
8d309058 | 25 | serversUtils.flushTests(next) |
9f10b292 C |
26 | }, |
27 | function (next) { | |
8d309058 | 28 | serversUtils.runServer(1, function (server1) { |
0c1cbbfe C |
29 | server = server1 |
30 | ||
31 | next() | |
32 | }) | |
33 | }, | |
34 | function (next) { | |
8d309058 | 35 | loginUtils.loginAndGetAccessToken(server, function (err, token) { |
0c1cbbfe | 36 | if (err) throw err |
b6c6f935 | 37 | server.accessToken = token |
0c1cbbfe | 38 | |
9f10b292 | 39 | next() |
34ca3b52 | 40 | }) |
9f10b292 C |
41 | } |
42 | ], done) | |
43 | }) | |
44 | ||
45 | describe('Of the pods API', function () { | |
f0f5567b | 46 | const path = '/api/v1/pods/' |
9f10b292 | 47 | |
d57d6f26 | 48 | describe('When making friends', function () { |
9bd26629 C |
49 | let userAccessToken = null |
50 | ||
51 | before(function (done) { | |
8d309058 | 52 | usersUtils.createUser(server.url, server.accessToken, 'user1', 'password', function () { |
9bd26629 C |
53 | server.user = { |
54 | username: 'user1', | |
55 | password: 'password' | |
56 | } | |
57 | ||
8d309058 | 58 | loginUtils.loginAndGetAccessToken(server, function (err, accessToken) { |
9bd26629 C |
59 | if (err) throw err |
60 | ||
61 | userAccessToken = accessToken | |
62 | ||
63 | done() | |
64 | }) | |
65 | }) | |
66 | }) | |
67 | ||
68 | describe('When making friends', function () { | |
1e2564d3 | 69 | const body = { |
a4254ea1 | 70 | hosts: [ 'localhost:9002' ] |
1e2564d3 C |
71 | } |
72 | ||
a4254ea1 | 73 | it('Should fail without hosts', function (done) { |
1e2564d3 C |
74 | request(server.url) |
75 | .post(path + '/makefriends') | |
d57d6f26 | 76 | .set('Authorization', 'Bearer ' + server.accessToken) |
1e2564d3 | 77 | .set('Accept', 'application/json') |
d57d6f26 | 78 | .expect(400, done) |
1e2564d3 C |
79 | }) |
80 | ||
a4254ea1 | 81 | it('Should fail if hosts is not an array', function (done) { |
1e2564d3 C |
82 | request(server.url) |
83 | .post(path + '/makefriends') | |
a4254ea1 | 84 | .send({ hosts: 'localhost:9002' }) |
d57d6f26 | 85 | .set('Authorization', 'Bearer ' + server.accessToken) |
1e2564d3 | 86 | .set('Accept', 'application/json') |
d57d6f26 | 87 | .expect(400, done) |
1e2564d3 C |
88 | }) |
89 | ||
a4254ea1 | 90 | it('Should fail if the array is not composed by hosts', function (done) { |
1e2564d3 C |
91 | request(server.url) |
92 | .post(path + '/makefriends') | |
a4254ea1 | 93 | .send({ hosts: [ 'localhost:9002', 'localhost:coucou' ] }) |
d57d6f26 | 94 | .set('Authorization', 'Bearer ' + server.accessToken) |
1e2564d3 | 95 | .set('Accept', 'application/json') |
d57d6f26 C |
96 | .expect(400, done) |
97 | }) | |
98 | ||
a4254ea1 | 99 | it('Should fail if the array is composed with http schemes', function (done) { |
d57d6f26 C |
100 | request(server.url) |
101 | .post(path + '/makefriends') | |
a4254ea1 C |
102 | .send({ hosts: [ 'localhost:9002', 'http://localhost:9003' ] }) |
103 | .set('Authorization', 'Bearer ' + server.accessToken) | |
104 | .set('Accept', 'application/json') | |
105 | .expect(400, done) | |
106 | }) | |
107 | ||
108 | it('Should fail if hosts are not unique', function (done) { | |
109 | request(server.url) | |
110 | .post(path + '/makefriends') | |
111 | .send({ urls: [ 'localhost:9002', 'localhost:9002' ] }) | |
d57d6f26 C |
112 | .set('Authorization', 'Bearer ' + server.accessToken) |
113 | .set('Accept', 'application/json') | |
114 | .expect(400, done) | |
1e2564d3 C |
115 | }) |
116 | ||
9bd26629 C |
117 | it('Should fail with a invalid token', function (done) { |
118 | request(server.url) | |
1e2564d3 C |
119 | .post(path + '/makefriends') |
120 | .send(body) | |
9bd26629 C |
121 | .set('Authorization', 'Bearer faketoken') |
122 | .set('Accept', 'application/json') | |
123 | .expect(401, done) | |
124 | }) | |
125 | ||
126 | it('Should fail if the user is not an administrator', function (done) { | |
127 | request(server.url) | |
1e2564d3 C |
128 | .post(path + '/makefriends') |
129 | .send(body) | |
9bd26629 C |
130 | .set('Authorization', 'Bearer ' + userAccessToken) |
131 | .set('Accept', 'application/json') | |
132 | .expect(403, done) | |
133 | }) | |
134 | }) | |
135 | ||
136 | describe('When quitting friends', function () { | |
137 | it('Should fail with a invalid token', function (done) { | |
138 | request(server.url) | |
139 | .get(path + '/quitfriends') | |
140 | .query({ start: 'hello' }) | |
141 | .set('Authorization', 'Bearer faketoken') | |
142 | .set('Accept', 'application/json') | |
143 | .expect(401, done) | |
144 | }) | |
145 | ||
146 | it('Should fail if the user is not an administrator', function (done) { | |
147 | request(server.url) | |
148 | .get(path + '/quitfriends') | |
149 | .query({ start: 'hello' }) | |
150 | .set('Authorization', 'Bearer ' + userAccessToken) | |
151 | .set('Accept', 'application/json') | |
152 | .expect(403, done) | |
153 | }) | |
34ca3b52 C |
154 | }) |
155 | }) | |
d57d6f26 C |
156 | |
157 | describe('When adding a pod', function () { | |
158 | it('Should fail with nothing', function (done) { | |
159 | const data = {} | |
160 | requestsUtils.makePostBodyRequest(server.url, path, null, data, done) | |
161 | }) | |
162 | ||
163 | it('Should fail without public key', function (done) { | |
164 | const data = { | |
a4254ea1 | 165 | host: 'coucou.com' |
d57d6f26 C |
166 | } |
167 | requestsUtils.makePostBodyRequest(server.url, path, null, data, done) | |
168 | }) | |
169 | ||
a4254ea1 | 170 | it('Should fail without an host', function (done) { |
d57d6f26 C |
171 | const data = { |
172 | publicKey: 'mysuperpublickey' | |
173 | } | |
174 | requestsUtils.makePostBodyRequest(server.url, path, null, data, done) | |
175 | }) | |
176 | ||
a4254ea1 | 177 | it('Should fail with an incorrect host', function (done) { |
d57d6f26 | 178 | const data = { |
a4254ea1 | 179 | host: 'http://coucou.com', |
d57d6f26 C |
180 | publicKey: 'mysuperpublickey' |
181 | } | |
182 | requestsUtils.makePostBodyRequest(server.url, path, null, data, function () { | |
a4254ea1 | 183 | data.host = 'http://coucou' |
d57d6f26 | 184 | requestsUtils.makePostBodyRequest(server.url, path, null, data, function () { |
a4254ea1 | 185 | data.host = 'coucou' |
d57d6f26 C |
186 | requestsUtils.makePostBodyRequest(server.url, path, null, data, done) |
187 | }) | |
188 | }) | |
189 | }) | |
190 | ||
191 | it('Should succeed with the correct parameters', function (done) { | |
192 | const data = { | |
a4254ea1 | 193 | host: 'coucou.com', |
d57d6f26 C |
194 | publicKey: 'mysuperpublickey' |
195 | } | |
196 | requestsUtils.makePostBodyRequest(server.url, path, null, data, done, 200) | |
197 | }) | |
198 | }) | |
9f10b292 | 199 | }) |
34ca3b52 | 200 | |
9f10b292 | 201 | describe('Of the videos API', function () { |
f0f5567b | 202 | const path = '/api/v1/videos/' |
34ca3b52 | 203 | |
a877d5ac C |
204 | describe('When listing a video', function () { |
205 | it('Should fail with a bad start pagination', function (done) { | |
206 | request(server.url) | |
207 | .get(path) | |
208 | .query({ start: 'hello' }) | |
209 | .set('Accept', 'application/json') | |
210 | .expect(400, done) | |
211 | }) | |
212 | ||
213 | it('Should fail with a bad count pagination', function (done) { | |
214 | request(server.url) | |
215 | .get(path) | |
216 | .query({ count: 'hello' }) | |
217 | .set('Accept', 'application/json') | |
218 | .expect(400, done) | |
219 | }) | |
220 | ||
221 | it('Should fail with an incorrect sort', function (done) { | |
222 | request(server.url) | |
223 | .get(path) | |
224 | .query({ sort: 'hello' }) | |
225 | .set('Accept', 'application/json') | |
226 | .expect(400, done) | |
227 | }) | |
228 | }) | |
229 | ||
9f10b292 C |
230 | describe('When searching a video', function () { |
231 | it('Should fail with nothing', function (done) { | |
0c1cbbfe | 232 | request(server.url) |
9f10b292 C |
233 | .get(pathUtils.join(path, 'search')) |
234 | .set('Accept', 'application/json') | |
235 | .expect(400, done) | |
34ca3b52 | 236 | }) |
a877d5ac C |
237 | |
238 | it('Should fail with a bad start pagination', function (done) { | |
239 | request(server.url) | |
240 | .get(pathUtils.join(path, 'search', 'test')) | |
241 | .query({ start: 'hello' }) | |
242 | .set('Accept', 'application/json') | |
243 | .expect(400, done) | |
244 | }) | |
245 | ||
246 | it('Should fail with a bad count pagination', function (done) { | |
247 | request(server.url) | |
248 | .get(pathUtils.join(path, 'search', 'test')) | |
249 | .query({ count: 'hello' }) | |
250 | .set('Accept', 'application/json') | |
251 | .expect(400, done) | |
252 | }) | |
253 | ||
254 | it('Should fail with an incorrect sort', function (done) { | |
255 | request(server.url) | |
256 | .get(pathUtils.join(path, 'search', 'test')) | |
257 | .query({ sort: 'hello' }) | |
258 | .set('Accept', 'application/json') | |
259 | .expect(400, done) | |
260 | }) | |
9f10b292 | 261 | }) |
34ca3b52 | 262 | |
9f10b292 C |
263 | describe('When adding a video', function () { |
264 | it('Should fail with nothing', function (done) { | |
f0f5567b C |
265 | const data = {} |
266 | const attach = {} | |
25ed57f3 | 267 | requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done) |
9f10b292 | 268 | }) |
34ca3b52 | 269 | |
9f10b292 | 270 | it('Should fail without name', function (done) { |
f0f5567b | 271 | const data = { |
be587647 C |
272 | description: 'my super description', |
273 | tags: [ 'tag1', 'tag2' ] | |
9f10b292 | 274 | } |
f0f5567b | 275 | const attach = { |
8c9c1942 | 276 | 'videofile': pathUtils.join(__dirname, 'fixtures', 'video_short.webm') |
9f10b292 | 277 | } |
25ed57f3 | 278 | requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done) |
9f10b292 | 279 | }) |
34ca3b52 | 280 | |
9f10b292 | 281 | it('Should fail with a long name', function (done) { |
f0f5567b | 282 | const data = { |
9f10b292 | 283 | name: 'My very very very very very very very very very very very very very very very very long name', |
be587647 C |
284 | description: 'my super description', |
285 | tags: [ 'tag1', 'tag2' ] | |
9f10b292 | 286 | } |
f0f5567b | 287 | const attach = { |
8c9c1942 | 288 | 'videofile': pathUtils.join(__dirname, 'fixtures', 'video_short.webm') |
9f10b292 | 289 | } |
25ed57f3 | 290 | requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done) |
9f10b292 | 291 | }) |
34ca3b52 | 292 | |
9f10b292 | 293 | it('Should fail without description', function (done) { |
f0f5567b | 294 | const data = { |
be587647 C |
295 | name: 'my super name', |
296 | tags: [ 'tag1', 'tag2' ] | |
9f10b292 | 297 | } |
f0f5567b | 298 | const attach = { |
8c9c1942 | 299 | 'videofile': pathUtils.join(__dirname, 'fixtures', 'video_short.webm') |
9f10b292 | 300 | } |
25ed57f3 | 301 | requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done) |
9f10b292 | 302 | }) |
34ca3b52 | 303 | |
9f10b292 | 304 | it('Should fail with a long description', function (done) { |
f0f5567b | 305 | const data = { |
9f10b292 C |
306 | name: 'my super name', |
307 | description: 'my super description which is very very very very very very very very very very very very very very' + | |
308 | 'very very very very very very very very very very very very very very very very very very very very very' + | |
be587647 C |
309 | 'very very very very very very very very very very very very very very very long', |
310 | tags: [ 'tag1', 'tag2' ] | |
9f10b292 | 311 | } |
f0f5567b | 312 | const attach = { |
8c9c1942 | 313 | 'videofile': pathUtils.join(__dirname, 'fixtures', 'video_short.webm') |
9f10b292 | 314 | } |
25ed57f3 | 315 | requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done) |
9f10b292 | 316 | }) |
34ca3b52 | 317 | |
be587647 | 318 | it('Should fail without tags', function (done) { |
f0f5567b | 319 | const data = { |
9f10b292 C |
320 | name: 'my super name', |
321 | description: 'my super description' | |
322 | } | |
be587647 C |
323 | const attach = { |
324 | 'videofile': pathUtils.join(__dirname, 'fixtures', 'video_short.webm') | |
325 | } | |
25ed57f3 | 326 | requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done) |
be587647 C |
327 | }) |
328 | ||
329 | it('Should fail with too many tags', function (done) { | |
330 | const data = { | |
331 | name: 'my super name', | |
332 | description: 'my super description', | |
333 | tags: [ 'tag1', 'tag2', 'tag3', 'tag4' ] | |
334 | } | |
335 | const attach = { | |
336 | 'videofile': pathUtils.join(__dirname, 'fixtures', 'video_short.webm') | |
337 | } | |
25ed57f3 | 338 | requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done) |
be587647 C |
339 | }) |
340 | ||
341 | it('Should fail with not enough tags', function (done) { | |
342 | const data = { | |
343 | name: 'my super name', | |
344 | description: 'my super description', | |
345 | tags: [ ] | |
346 | } | |
347 | const attach = { | |
348 | 'videofile': pathUtils.join(__dirname, 'fixtures', 'video_short.webm') | |
349 | } | |
25ed57f3 | 350 | requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done) |
be587647 C |
351 | }) |
352 | ||
353 | it('Should fail with a tag length too low', function (done) { | |
354 | const data = { | |
355 | name: 'my super name', | |
356 | description: 'my super description', | |
357 | tags: [ 'tag1', 't' ] | |
358 | } | |
359 | const attach = { | |
360 | 'videofile': pathUtils.join(__dirname, 'fixtures', 'video_short.webm') | |
361 | } | |
25ed57f3 | 362 | requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done) |
be587647 C |
363 | }) |
364 | ||
365 | it('Should fail with a tag length too big', function (done) { | |
366 | const data = { | |
367 | name: 'my super name', | |
368 | description: 'my super description', | |
369 | tags: [ 'mysupertagtoolong', 'tag1' ] | |
370 | } | |
371 | const attach = { | |
372 | 'videofile': pathUtils.join(__dirname, 'fixtures', 'video_short.webm') | |
373 | } | |
25ed57f3 | 374 | requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done) |
be587647 C |
375 | }) |
376 | ||
377 | it('Should fail with malformed tags', function (done) { | |
378 | const data = { | |
379 | name: 'my super name', | |
380 | description: 'my super description', | |
381 | tags: [ 'my tag' ] | |
382 | } | |
383 | const attach = { | |
384 | 'videofile': pathUtils.join(__dirname, 'fixtures', 'video_short.webm') | |
385 | } | |
25ed57f3 | 386 | requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done) |
be587647 C |
387 | }) |
388 | ||
389 | it('Should fail without an input file', function (done) { | |
390 | const data = { | |
391 | name: 'my super name', | |
392 | description: 'my super description', | |
393 | tags: [ 'tag1', 'tag2' ] | |
394 | } | |
f0f5567b | 395 | const attach = {} |
25ed57f3 | 396 | requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done) |
9f10b292 | 397 | }) |
34ca3b52 | 398 | |
9f10b292 | 399 | it('Should fail without an incorrect input file', function (done) { |
f0f5567b | 400 | const data = { |
9f10b292 | 401 | name: 'my super name', |
be587647 C |
402 | description: 'my super description', |
403 | tags: [ 'tag1', 'tag2' ] | |
9f10b292 | 404 | } |
f0f5567b | 405 | const attach = { |
67100f1f C |
406 | 'videofile': pathUtils.join(__dirname, 'fixtures', 'video_short_fake.webm') |
407 | } | |
25ed57f3 | 408 | requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done) |
67100f1f C |
409 | }) |
410 | ||
411 | it('Should fail with a too big duration', function (done) { | |
412 | const data = { | |
413 | name: 'my super name', | |
be587647 C |
414 | description: 'my super description', |
415 | tags: [ 'tag1', 'tag2' ] | |
67100f1f C |
416 | } |
417 | const attach = { | |
418 | 'videofile': pathUtils.join(__dirname, 'fixtures', 'video_too_long.webm') | |
9f10b292 | 419 | } |
25ed57f3 | 420 | requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done) |
9f10b292 | 421 | }) |
34ca3b52 | 422 | |
9f10b292 | 423 | it('Should succeed with the correct parameters', function (done) { |
f0f5567b | 424 | const data = { |
9f10b292 | 425 | name: 'my super name', |
be587647 C |
426 | description: 'my super description', |
427 | tags: [ 'tag1', 'tag2' ] | |
9f10b292 | 428 | } |
f0f5567b | 429 | const attach = { |
8c9c1942 | 430 | 'videofile': pathUtils.join(__dirname, 'fixtures', 'video_short.webm') |
9f10b292 | 431 | } |
25ed57f3 | 432 | requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, function () { |
8c9c1942 | 433 | attach.videofile = pathUtils.join(__dirname, 'fixtures', 'video_short.mp4') |
25ed57f3 | 434 | requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, function () { |
8c9c1942 | 435 | attach.videofile = pathUtils.join(__dirname, 'fixtures', 'video_short.ogv') |
25ed57f3 | 436 | requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done, 204) |
67100f1f C |
437 | }, false) |
438 | }, false) | |
34ca3b52 | 439 | }) |
9f10b292 | 440 | }) |
34ca3b52 | 441 | |
9f10b292 C |
442 | describe('When getting a video', function () { |
443 | it('Should return the list of the videos with nothing', function (done) { | |
0c1cbbfe | 444 | request(server.url) |
9f10b292 C |
445 | .get(path) |
446 | .set('Accept', 'application/json') | |
447 | .expect(200) | |
448 | .expect('Content-Type', /json/) | |
449 | .end(function (err, res) { | |
450 | if (err) throw err | |
34ca3b52 | 451 | |
68ce3ae0 C |
452 | expect(res.body.data).to.be.an('array') |
453 | expect(res.body.data.length).to.equal(3) | |
34ca3b52 | 454 | |
9f10b292 C |
455 | done() |
456 | }) | |
457 | }) | |
34ca3b52 | 458 | |
9f10b292 | 459 | it('Should fail without a mongodb id', function (done) { |
0c1cbbfe | 460 | request(server.url) |
9f10b292 C |
461 | .get(path + 'coucou') |
462 | .set('Accept', 'application/json') | |
463 | .expect(400, done) | |
34ca3b52 C |
464 | }) |
465 | ||
9f10b292 | 466 | it('Should return 404 with an incorrect video', function (done) { |
0c1cbbfe | 467 | request(server.url) |
feb4bdfd | 468 | .get(path + '4da6fde3-88f7-4d16-b119-108df5630b06') |
9f10b292 | 469 | .set('Accept', 'application/json') |
34ca3b52 | 470 | .expect(404, done) |
34ca3b52 | 471 | }) |
9f10b292 C |
472 | |
473 | it('Should succeed with the correct parameters') | |
34ca3b52 C |
474 | }) |
475 | ||
9f10b292 C |
476 | describe('When removing a video', function () { |
477 | it('Should have 404 with nothing', function (done) { | |
0c1cbbfe C |
478 | request(server.url) |
479 | .delete(path) | |
b6c6f935 | 480 | .set('Authorization', 'Bearer ' + server.accessToken) |
0c1cbbfe | 481 | .expect(400, done) |
34ca3b52 C |
482 | }) |
483 | ||
9f10b292 | 484 | it('Should fail without a mongodb id', function (done) { |
0c1cbbfe | 485 | request(server.url) |
9f10b292 | 486 | .delete(path + 'hello') |
b6c6f935 | 487 | .set('Authorization', 'Bearer ' + server.accessToken) |
9f10b292 | 488 | .expect(400, done) |
34ca3b52 C |
489 | }) |
490 | ||
9f10b292 | 491 | it('Should fail with a video which does not exist', function (done) { |
0c1cbbfe | 492 | request(server.url) |
feb4bdfd | 493 | .delete(path + '4da6fde3-88f7-4d16-b119-108df5630b06') |
b6c6f935 | 494 | .set('Authorization', 'Bearer ' + server.accessToken) |
9f10b292 | 495 | .expect(404, done) |
34ca3b52 | 496 | }) |
9f10b292 | 497 | |
58b2ba55 C |
498 | it('Should fail with a video of another user') |
499 | ||
9f10b292 C |
500 | it('Should fail with a video of another pod') |
501 | ||
502 | it('Should succeed with the correct parameters') | |
34ca3b52 | 503 | }) |
9f10b292 | 504 | }) |
34ca3b52 | 505 | |
9bd26629 C |
506 | describe('Of the users API', function () { |
507 | const path = '/api/v1/users/' | |
99a64bfe | 508 | let userId = null |
af1068ce | 509 | let rootId = null |
9bd26629 | 510 | |
5c39adb7 C |
511 | describe('When listing users', function () { |
512 | it('Should fail with a bad start pagination', function (done) { | |
513 | request(server.url) | |
514 | .get(path) | |
515 | .query({ start: 'hello' }) | |
516 | .set('Accept', 'application/json') | |
517 | .expect(400, done) | |
518 | }) | |
519 | ||
520 | it('Should fail with a bad count pagination', function (done) { | |
521 | request(server.url) | |
522 | .get(path) | |
523 | .query({ count: 'hello' }) | |
524 | .set('Accept', 'application/json') | |
525 | .expect(400, done) | |
526 | }) | |
527 | ||
528 | it('Should fail with an incorrect sort', function (done) { | |
529 | request(server.url) | |
530 | .get(path) | |
531 | .query({ sort: 'hello' }) | |
532 | .set('Accept', 'application/json') | |
533 | .expect(400, done) | |
534 | }) | |
535 | }) | |
536 | ||
9bd26629 C |
537 | describe('When adding a new user', function () { |
538 | it('Should fail with a too small username', function (done) { | |
539 | const data = { | |
540 | username: 'ji', | |
541 | password: 'mysuperpassword' | |
542 | } | |
543 | ||
25ed57f3 | 544 | requestsUtils.makePostBodyRequest(server.url, path, server.accessToken, data, done) |
9bd26629 C |
545 | }) |
546 | ||
547 | it('Should fail with a too long username', function (done) { | |
548 | const data = { | |
549 | username: 'mysuperusernamewhichisverylong', | |
550 | password: 'mysuperpassword' | |
551 | } | |
552 | ||
25ed57f3 | 553 | requestsUtils.makePostBodyRequest(server.url, path, server.accessToken, data, done) |
9bd26629 C |
554 | }) |
555 | ||
556 | it('Should fail with an incorrect username', function (done) { | |
557 | const data = { | |
558 | username: 'my username', | |
559 | password: 'mysuperpassword' | |
560 | } | |
561 | ||
25ed57f3 | 562 | requestsUtils.makePostBodyRequest(server.url, path, server.accessToken, data, done) |
9bd26629 C |
563 | }) |
564 | ||
565 | it('Should fail with a too small password', function (done) { | |
566 | const data = { | |
567 | username: 'myusername', | |
568 | password: 'bla' | |
569 | } | |
570 | ||
25ed57f3 | 571 | requestsUtils.makePostBodyRequest(server.url, path, server.accessToken, data, done) |
9bd26629 C |
572 | }) |
573 | ||
574 | it('Should fail with a too long password', function (done) { | |
575 | const data = { | |
576 | username: 'myusername', | |
577 | password: 'my super long password which is very very very very very very very very very very very very very very' + | |
578 | 'very very very very very very very very very very very very very very very veryv very very very very' + | |
579 | 'very very very very very very very very very very very very very very very very very very very very long' | |
580 | } | |
581 | ||
25ed57f3 | 582 | requestsUtils.makePostBodyRequest(server.url, path, server.accessToken, data, done) |
9bd26629 C |
583 | }) |
584 | ||
585 | it('Should fail with an non authenticated user', function (done) { | |
586 | const data = { | |
587 | username: 'myusername', | |
588 | password: 'my super password' | |
589 | } | |
590 | ||
25ed57f3 | 591 | requestsUtils.makePostBodyRequest(server.url, path, 'super token', data, done, 401) |
9bd26629 C |
592 | }) |
593 | ||
327680c9 | 594 | it('Should fail if we add a user with the same username', function (done) { |
9bd26629 C |
595 | const data = { |
596 | username: 'user1', | |
597 | password: 'my super password' | |
598 | } | |
599 | ||
327680c9 | 600 | requestsUtils.makePostBodyRequest(server.url, path, server.accessToken, data, done, 409) |
9bd26629 C |
601 | }) |
602 | ||
327680c9 C |
603 | it('Should succeed with the correct params', function (done) { |
604 | const data = { | |
605 | username: 'user2', | |
606 | password: 'my super password' | |
607 | } | |
bf68dd75 | 608 | |
327680c9 | 609 | requestsUtils.makePostBodyRequest(server.url, path, server.accessToken, data, done, 204) |
bf68dd75 C |
610 | }) |
611 | ||
9bd26629 C |
612 | it('Should fail with a non admin user', function (done) { |
613 | server.user = { | |
614 | username: 'user1', | |
327680c9 | 615 | password: 'password' |
9bd26629 C |
616 | } |
617 | ||
8d309058 | 618 | loginUtils.loginAndGetAccessToken(server, function (err, accessToken) { |
9bd26629 C |
619 | if (err) throw err |
620 | ||
99a64bfe C |
621 | userAccessToken = accessToken |
622 | ||
9bd26629 | 623 | const data = { |
327680c9 | 624 | username: 'user3', |
9bd26629 C |
625 | password: 'my super password' |
626 | } | |
627 | ||
25ed57f3 | 628 | requestsUtils.makePostBodyRequest(server.url, path, userAccessToken, data, done, 403) |
9bd26629 C |
629 | }) |
630 | }) | |
631 | }) | |
632 | ||
633 | describe('When updating a user', function () { | |
9bd26629 | 634 | before(function (done) { |
8d309058 | 635 | usersUtils.getUsersList(server.url, function (err, res) { |
9bd26629 C |
636 | if (err) throw err |
637 | ||
638 | userId = res.body.data[1].id | |
af1068ce | 639 | rootId = res.body.data[2].id |
9bd26629 C |
640 | done() |
641 | }) | |
642 | }) | |
643 | ||
644 | it('Should fail with a too small password', function (done) { | |
645 | const data = { | |
646 | password: 'bla' | |
647 | } | |
648 | ||
25ed57f3 | 649 | requestsUtils.makePutBodyRequest(server.url, path + userId, userAccessToken, data, done) |
9bd26629 C |
650 | }) |
651 | ||
652 | it('Should fail with a too long password', function (done) { | |
653 | const data = { | |
654 | password: 'my super long password which is very very very very very very very very very very very very very very' + | |
655 | 'very very very very very very very very very very very very very very very veryv very very very very' + | |
656 | 'very very very very very very very very very very very very very very very very very very very very long' | |
657 | } | |
658 | ||
25ed57f3 | 659 | requestsUtils.makePutBodyRequest(server.url, path + userId, userAccessToken, data, done) |
9bd26629 C |
660 | }) |
661 | ||
662 | it('Should fail with an non authenticated user', function (done) { | |
663 | const data = { | |
664 | password: 'my super password' | |
665 | } | |
666 | ||
25ed57f3 | 667 | requestsUtils.makePutBodyRequest(server.url, path + userId, 'super token', data, done, 401) |
9bd26629 C |
668 | }) |
669 | ||
670 | it('Should succeed with the correct params', function (done) { | |
671 | const data = { | |
672 | password: 'my super password' | |
673 | } | |
674 | ||
25ed57f3 | 675 | requestsUtils.makePutBodyRequest(server.url, path + userId, userAccessToken, data, done, 204) |
99a64bfe C |
676 | }) |
677 | }) | |
678 | ||
679 | describe('When getting my information', function () { | |
680 | it('Should fail with a non authenticated user', function (done) { | |
681 | request(server.url) | |
682 | .get(path + 'me') | |
683 | .set('Authorization', 'Bearer faketoken') | |
684 | .set('Accept', 'application/json') | |
685 | .expect(401, done) | |
686 | }) | |
687 | ||
688 | it('Should success with the correct parameters', function (done) { | |
689 | request(server.url) | |
690 | .get(path + 'me') | |
691 | .set('Authorization', 'Bearer ' + userAccessToken) | |
692 | .set('Accept', 'application/json') | |
693 | .expect(200, done) | |
9bd26629 C |
694 | }) |
695 | }) | |
696 | ||
697 | describe('When removing an user', function () { | |
68a3b9f2 | 698 | it('Should fail with an incorrect id', function (done) { |
9bd26629 C |
699 | request(server.url) |
700 | .delete(path + 'bla-bla') | |
701 | .set('Authorization', 'Bearer ' + server.accessToken) | |
702 | .expect(400, done) | |
703 | }) | |
704 | ||
af1068ce C |
705 | it('Should fail with the root user', function (done) { |
706 | request(server.url) | |
707 | .delete(path + rootId) | |
708 | .set('Authorization', 'Bearer ' + server.accessToken) | |
709 | .expect(400, done) | |
710 | }) | |
711 | ||
68a3b9f2 | 712 | it('Should return 404 with a non existing id', function (done) { |
9bd26629 | 713 | request(server.url) |
feb4bdfd | 714 | .delete(path + '45') |
9bd26629 C |
715 | .set('Authorization', 'Bearer ' + server.accessToken) |
716 | .expect(404, done) | |
717 | }) | |
9bd26629 C |
718 | }) |
719 | }) | |
720 | ||
9f10b292 C |
721 | describe('Of the remote videos API', function () { |
722 | describe('When making a secure request', function () { | |
723 | it('Should check a secure request') | |
724 | }) | |
34ca3b52 | 725 | |
9f10b292 C |
726 | describe('When adding a video', function () { |
727 | it('Should check when adding a video') | |
34ca3b52 | 728 | }) |
9f10b292 C |
729 | |
730 | describe('When removing a video', function () { | |
731 | it('Should check when removing a video') | |
732 | }) | |
733 | }) | |
734 | ||
d3cd34be C |
735 | describe('Of the requests API', function () { |
736 | const path = '/api/v1/requests/stats' | |
737 | ||
738 | it('Should fail with an non authenticated user', function (done) { | |
739 | request(server.url) | |
740 | .get(path) | |
741 | .set('Accept', 'application/json') | |
742 | .expect(401, done) | |
743 | }) | |
744 | ||
745 | it('Should fail with a non admin user', function (done) { | |
746 | request(server.url) | |
747 | .get(path) | |
748 | .set('Authorization', 'Bearer ' + userAccessToken) | |
749 | .set('Accept', 'application/json') | |
750 | .expect(403, done) | |
751 | }) | |
752 | }) | |
753 | ||
9f10b292 | 754 | after(function (done) { |
0c1cbbfe | 755 | process.kill(-server.app.pid) |
9f10b292 C |
756 | |
757 | // Keep the logs if the test failed | |
758 | if (this.ok) { | |
8d309058 | 759 | serversUtils.flushTests(done) |
9f10b292 C |
760 | } else { |
761 | done() | |
762 | } | |
34ca3b52 | 763 | }) |
9f10b292 | 764 | }) |