aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api/checkParams.js
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2016-10-02 15:39:09 +0200
committerChocobozzz <florian.bigard@gmail.com>2016-10-02 15:39:09 +0200
commita6375e69668ea42e19531c6bc68dcd37f3f7cbd7 (patch)
tree03204a408d56311692c3528bedcf95d2455e94f2 /server/tests/api/checkParams.js
parent052937db8a8d282eccdbdf38d487ed8d85d3c0a7 (diff)
parentc4403b29ad4db097af528a7f04eea07e0ed320d0 (diff)
downloadPeerTube-a6375e69668ea42e19531c6bc68dcd37f3f7cbd7.tar.gz
PeerTube-a6375e69668ea42e19531c6bc68dcd37f3f7cbd7.tar.zst
PeerTube-a6375e69668ea42e19531c6bc68dcd37f3f7cbd7.zip
Merge branch 'master' into webseed-merged
Diffstat (limited to 'server/tests/api/checkParams.js')
-rw-r--r--server/tests/api/checkParams.js456
1 files changed, 0 insertions, 456 deletions
diff --git a/server/tests/api/checkParams.js b/server/tests/api/checkParams.js
deleted file mode 100644
index c1ba9c2c0..000000000
--- a/server/tests/api/checkParams.js
+++ /dev/null
@@ -1,456 +0,0 @@
1'use strict'
2
3const chai = require('chai')
4const expect = chai.expect
5const pathUtils = require('path')
6const request = require('supertest')
7const series = require('async/series')
8
9const utils = require('./utils')
10
11describe('Test parameters validator', function () {
12 let server = null
13
14 function makePostRequest (path, token, fields, attaches, done, fail) {
15 let statusCode = 400
16 if (fail !== undefined && fail === false) statusCode = 204
17
18 const req = request(server.url)
19 .post(path)
20 .set('Accept', 'application/json')
21
22 if (token) req.set('Authorization', 'Bearer ' + token)
23
24 Object.keys(fields).forEach(function (field) {
25 const value = fields[field]
26
27 if (Array.isArray(value)) {
28 for (let i = 0; i < value.length; i++) {
29 req.field(field + '[' + i + ']', value[i])
30 }
31 } else {
32 req.field(field, value)
33 }
34 })
35
36 Object.keys(attaches).forEach(function (attach) {
37 const value = attaches[attach]
38 req.attach(attach, value)
39 })
40
41 req.expect(statusCode, done)
42 }
43
44 function makePostBodyRequest (path, fields, done, fail) {
45 let statusCode = 400
46 if (fail !== undefined && fail === false) statusCode = 200
47
48 request(server.url)
49 .post(path)
50 .set('Accept', 'application/json')
51 .send(fields)
52 .expect(statusCode, done)
53 }
54
55 // ---------------------------------------------------------------
56
57 before(function (done) {
58 this.timeout(20000)
59
60 series([
61 function (next) {
62 utils.flushTests(next)
63 },
64 function (next) {
65 utils.runServer(1, function (server1) {
66 server = server1
67
68 next()
69 })
70 },
71 function (next) {
72 utils.loginAndGetAccessToken(server, function (err, token) {
73 if (err) throw err
74 server.accessToken = token
75
76 next()
77 })
78 }
79 ], done)
80 })
81
82 describe('Of the pods API', function () {
83 const path = '/api/v1/pods/'
84
85 describe('When adding a pod', function () {
86 it('Should fail with nothing', function (done) {
87 const data = {}
88 makePostBodyRequest(path, data, done)
89 })
90
91 it('Should fail without public key', function (done) {
92 const data = {
93 url: 'http://coucou.com'
94 }
95 makePostBodyRequest(path, data, done)
96 })
97
98 it('Should fail without an url', function (done) {
99 const data = {
100 publicKey: 'mysuperpublickey'
101 }
102 makePostBodyRequest(path, data, done)
103 })
104
105 it('Should fail with an incorrect url', function (done) {
106 const data = {
107 url: 'coucou.com',
108 publicKey: 'mysuperpublickey'
109 }
110 makePostBodyRequest(path, data, function () {
111 data.url = 'http://coucou'
112 makePostBodyRequest(path, data, function () {
113 data.url = 'coucou'
114 makePostBodyRequest(path, data, done)
115 })
116 })
117 })
118
119 it('Should succeed with the correct parameters', function (done) {
120 const data = {
121 url: 'http://coucou.com',
122 publicKey: 'mysuperpublickey'
123 }
124 makePostBodyRequest(path, data, done, false)
125 })
126 })
127 })
128
129 describe('Of the videos API', function () {
130 const path = '/api/v1/videos/'
131
132 describe('When listing a video', function () {
133 it('Should fail with a bad start pagination', function (done) {
134 request(server.url)
135 .get(path)
136 .query({ start: 'hello' })
137 .set('Accept', 'application/json')
138 .expect(400, done)
139 })
140
141 it('Should fail with a bad count pagination', function (done) {
142 request(server.url)
143 .get(path)
144 .query({ count: 'hello' })
145 .set('Accept', 'application/json')
146 .expect(400, done)
147 })
148
149 it('Should fail with an incorrect sort', function (done) {
150 request(server.url)
151 .get(path)
152 .query({ sort: 'hello' })
153 .set('Accept', 'application/json')
154 .expect(400, done)
155 })
156 })
157
158 describe('When searching a video', function () {
159 it('Should fail with nothing', function (done) {
160 request(server.url)
161 .get(pathUtils.join(path, 'search'))
162 .set('Accept', 'application/json')
163 .expect(400, done)
164 })
165
166 it('Should fail with a bad start pagination', function (done) {
167 request(server.url)
168 .get(pathUtils.join(path, 'search', 'test'))
169 .query({ start: 'hello' })
170 .set('Accept', 'application/json')
171 .expect(400, done)
172 })
173
174 it('Should fail with a bad count pagination', function (done) {
175 request(server.url)
176 .get(pathUtils.join(path, 'search', 'test'))
177 .query({ count: 'hello' })
178 .set('Accept', 'application/json')
179 .expect(400, done)
180 })
181
182 it('Should fail with an incorrect sort', function (done) {
183 request(server.url)
184 .get(pathUtils.join(path, 'search', 'test'))
185 .query({ sort: 'hello' })
186 .set('Accept', 'application/json')
187 .expect(400, done)
188 })
189 })
190
191 describe('When adding a video', function () {
192 it('Should fail with nothing', function (done) {
193 const data = {}
194 const attach = {}
195 makePostRequest(path, server.accessToken, data, attach, done)
196 })
197
198 it('Should fail without name', function (done) {
199 const data = {
200 description: 'my super description',
201 tags: [ 'tag1', 'tag2' ]
202 }
203 const attach = {
204 'videofile': pathUtils.join(__dirname, 'fixtures', 'video_short.webm')
205 }
206 makePostRequest(path, server.accessToken, data, attach, done)
207 })
208
209 it('Should fail with a long name', function (done) {
210 const data = {
211 name: 'My very very very very very very very very very very very very very very very very long name',
212 description: 'my super description',
213 tags: [ 'tag1', 'tag2' ]
214 }
215 const attach = {
216 'videofile': pathUtils.join(__dirname, 'fixtures', 'video_short.webm')
217 }
218 makePostRequest(path, server.accessToken, data, attach, done)
219 })
220
221 it('Should fail without description', function (done) {
222 const data = {
223 name: 'my super name',
224 tags: [ 'tag1', 'tag2' ]
225 }
226 const attach = {
227 'videofile': pathUtils.join(__dirname, 'fixtures', 'video_short.webm')
228 }
229 makePostRequest(path, server.accessToken, data, attach, done)
230 })
231
232 it('Should fail with a long description', function (done) {
233 const data = {
234 name: 'my super name',
235 description: 'my super description which is very very very very very very very very very very very very very very' +
236 'very very very very very very very very very very very very very very very very very very very very very' +
237 'very very very very very very very very very very very very very very very long',
238 tags: [ 'tag1', 'tag2' ]
239 }
240 const attach = {
241 'videofile': pathUtils.join(__dirname, 'fixtures', 'video_short.webm')
242 }
243 makePostRequest(path, server.accessToken, data, attach, done)
244 })
245
246 it('Should fail without tags', function (done) {
247 const data = {
248 name: 'my super name',
249 description: 'my super description'
250 }
251 const attach = {
252 'videofile': pathUtils.join(__dirname, 'fixtures', 'video_short.webm')
253 }
254 makePostRequest(path, server.accessToken, data, attach, done)
255 })
256
257 it('Should fail with too many tags', function (done) {
258 const data = {
259 name: 'my super name',
260 description: 'my super description',
261 tags: [ 'tag1', 'tag2', 'tag3', 'tag4' ]
262 }
263 const attach = {
264 'videofile': pathUtils.join(__dirname, 'fixtures', 'video_short.webm')
265 }
266 makePostRequest(path, server.accessToken, data, attach, done)
267 })
268
269 it('Should fail with not enough tags', function (done) {
270 const data = {
271 name: 'my super name',
272 description: 'my super description',
273 tags: [ ]
274 }
275 const attach = {
276 'videofile': pathUtils.join(__dirname, 'fixtures', 'video_short.webm')
277 }
278 makePostRequest(path, server.accessToken, data, attach, done)
279 })
280
281 it('Should fail with a tag length too low', function (done) {
282 const data = {
283 name: 'my super name',
284 description: 'my super description',
285 tags: [ 'tag1', 't' ]
286 }
287 const attach = {
288 'videofile': pathUtils.join(__dirname, 'fixtures', 'video_short.webm')
289 }
290 makePostRequest(path, server.accessToken, data, attach, done)
291 })
292
293 it('Should fail with a tag length too big', function (done) {
294 const data = {
295 name: 'my super name',
296 description: 'my super description',
297 tags: [ 'mysupertagtoolong', 'tag1' ]
298 }
299 const attach = {
300 'videofile': pathUtils.join(__dirname, 'fixtures', 'video_short.webm')
301 }
302 makePostRequest(path, server.accessToken, data, attach, done)
303 })
304
305 it('Should fail with malformed tags', function (done) {
306 const data = {
307 name: 'my super name',
308 description: 'my super description',
309 tags: [ 'my tag' ]
310 }
311 const attach = {
312 'videofile': pathUtils.join(__dirname, 'fixtures', 'video_short.webm')
313 }
314 makePostRequest(path, server.accessToken, data, attach, done)
315 })
316
317 it('Should fail without an input file', function (done) {
318 const data = {
319 name: 'my super name',
320 description: 'my super description',
321 tags: [ 'tag1', 'tag2' ]
322 }
323 const attach = {}
324 makePostRequest(path, server.accessToken, data, attach, done)
325 })
326
327 it('Should fail without an incorrect input file', function (done) {
328 const data = {
329 name: 'my super name',
330 description: 'my super description',
331 tags: [ 'tag1', 'tag2' ]
332 }
333 const attach = {
334 'videofile': pathUtils.join(__dirname, 'fixtures', 'video_short_fake.webm')
335 }
336 makePostRequest(path, server.accessToken, data, attach, done)
337 })
338
339 it('Should fail with a too big duration', function (done) {
340 const data = {
341 name: 'my super name',
342 description: 'my super description',
343 tags: [ 'tag1', 'tag2' ]
344 }
345 const attach = {
346 'videofile': pathUtils.join(__dirname, 'fixtures', 'video_too_long.webm')
347 }
348 makePostRequest(path, server.accessToken, data, attach, done)
349 })
350
351 it('Should succeed with the correct parameters', function (done) {
352 const data = {
353 name: 'my super name',
354 description: 'my super description',
355 tags: [ 'tag1', 'tag2' ]
356 }
357 const attach = {
358 'videofile': pathUtils.join(__dirname, 'fixtures', 'video_short.webm')
359 }
360 makePostRequest(path, server.accessToken, data, attach, function () {
361 attach.videofile = pathUtils.join(__dirname, 'fixtures', 'video_short.mp4')
362 makePostRequest(path, server.accessToken, data, attach, function () {
363 attach.videofile = pathUtils.join(__dirname, 'fixtures', 'video_short.ogv')
364 makePostRequest(path, server.accessToken, data, attach, done, false)
365 }, false)
366 }, false)
367 })
368 })
369
370 describe('When getting a video', function () {
371 it('Should return the list of the videos with nothing', function (done) {
372 request(server.url)
373 .get(path)
374 .set('Accept', 'application/json')
375 .expect(200)
376 .expect('Content-Type', /json/)
377 .end(function (err, res) {
378 if (err) throw err
379
380 expect(res.body.data).to.be.an('array')
381 expect(res.body.data.length).to.equal(3)
382
383 done()
384 })
385 })
386
387 it('Should fail without a mongodb id', function (done) {
388 request(server.url)
389 .get(path + 'coucou')
390 .set('Accept', 'application/json')
391 .expect(400, done)
392 })
393
394 it('Should return 404 with an incorrect video', function (done) {
395 request(server.url)
396 .get(path + '123456789012345678901234')
397 .set('Accept', 'application/json')
398 .expect(404, done)
399 })
400
401 it('Should succeed with the correct parameters')
402 })
403
404 describe('When removing a video', function () {
405 it('Should have 404 with nothing', function (done) {
406 request(server.url)
407 .delete(path)
408 .set('Authorization', 'Bearer ' + server.accessToken)
409 .expect(400, done)
410 })
411
412 it('Should fail without a mongodb id', function (done) {
413 request(server.url)
414 .delete(path + 'hello')
415 .set('Authorization', 'Bearer ' + server.accessToken)
416 .expect(400, done)
417 })
418
419 it('Should fail with a video which does not exist', function (done) {
420 request(server.url)
421 .delete(path + '123456789012345678901234')
422 .set('Authorization', 'Bearer ' + server.accessToken)
423 .expect(404, done)
424 })
425
426 it('Should fail with a video of another pod')
427
428 it('Should succeed with the correct parameters')
429 })
430 })
431
432 describe('Of the remote videos API', function () {
433 describe('When making a secure request', function () {
434 it('Should check a secure request')
435 })
436
437 describe('When adding a video', function () {
438 it('Should check when adding a video')
439 })
440
441 describe('When removing a video', function () {
442 it('Should check when removing a video')
443 })
444 })
445
446 after(function (done) {
447 process.kill(-server.app.pid)
448
449 // Keep the logs if the test failed
450 if (this.ok) {
451 utils.flushTests(done)
452 } else {
453 done()
454 }
455 })
456})