]>
git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/api/checkParams.js
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')
9 const utils
= require('./utils')
11 describe('Test parameters validator', function () {
14 function makePostRequest (path
, token
, fields
, attaches
, done
, fail
) {
16 if (fail
!== undefined && fail
=== false) statusCode
= 204
18 const req
= request(server
.url
)
20 .set('Accept', 'application/json')
22 if (token
) req
.set('Authorization', 'Bearer ' + token
)
24 Object
.keys(fields
).forEach(function (field
) {
25 const value
= fields
[field
]
26 req
.field(field
, value
)
29 Object
.keys(attaches
).forEach(function (attach
) {
30 const value
= attaches
[attach
]
31 req
.attach(attach
, value
)
34 req
.expect(statusCode
, done
)
37 function makePostBodyRequest (path
, fields
, done
, fail
) {
39 if (fail
!== undefined && fail
=== false) statusCode
= 200
43 .set('Accept', 'application/json')
45 .expect(statusCode
, done
)
48 // ---------------------------------------------------------------
50 before(function (done
) {
55 utils
.flushTests(next
)
58 utils
.runServer(1, function (server1
) {
65 utils
.loginAndGetAccessToken(server
, function (err
, token
) {
67 server
.accessToken
= token
75 describe('Of the pods API', function () {
76 const path
= '/api/v1/pods/'
78 describe('When adding a pod', function () {
79 it('Should fail with nothing', function (done
) {
81 makePostBodyRequest(path
, data
, done
)
84 it('Should fail without public key', function (done
) {
87 url: 'http://coucou.com'
90 makePostBodyRequest(path
, data
, done
)
93 it('Should fail without an url', function (done
) {
96 publicKey: 'mysuperpublickey'
99 makePostBodyRequest(path
, data
, done
)
102 it('Should fail with an incorrect url', function (done
) {
106 publicKey: 'mysuperpublickey'
109 makePostBodyRequest(path
, data
, function () {
110 data
.data
.url
= 'http://coucou'
111 makePostBodyRequest(path
, data
, function () {
112 data
.data
.url
= 'coucou'
113 makePostBodyRequest(path
, data
, done
)
118 it('Should succeed with the correct parameters', function (done
) {
121 url: 'http://coucou.com',
122 publicKey: 'mysuperpublickey'
125 makePostBodyRequest(path
, data
, done
, false)
130 describe('Of the videos API', function () {
131 const path
= '/api/v1/videos/'
133 describe('When listing a video', function () {
134 it('Should fail with a bad start pagination', function (done
) {
137 .query({ start: 'hello' })
138 .set('Accept', 'application/json')
142 it('Should fail with a bad count pagination', function (done
) {
145 .query({ count: 'hello' })
146 .set('Accept', 'application/json')
150 it('Should fail with an incorrect sort', function (done
) {
153 .query({ sort: 'hello' })
154 .set('Accept', 'application/json')
159 describe('When searching a video', function () {
160 it('Should fail with nothing', function (done
) {
162 .get(pathUtils
.join(path
, 'search'))
163 .set('Accept', 'application/json')
167 it('Should fail with a bad start pagination', function (done
) {
169 .get(pathUtils
.join(path
, 'search', 'test'))
170 .query({ start: 'hello' })
171 .set('Accept', 'application/json')
175 it('Should fail with a bad count pagination', function (done
) {
177 .get(pathUtils
.join(path
, 'search', 'test'))
178 .query({ count: 'hello' })
179 .set('Accept', 'application/json')
183 it('Should fail with an incorrect sort', function (done
) {
185 .get(pathUtils
.join(path
, 'search', 'test'))
186 .query({ sort: 'hello' })
187 .set('Accept', 'application/json')
192 describe('When adding a video', function () {
193 it('Should fail with nothing', function (done
) {
196 makePostRequest(path
, server
.accessToken
, data
, attach
, done
)
199 it('Should fail without name', function (done
) {
201 description: 'my super description'
204 'videofile': pathUtils
.join(__dirname
, 'fixtures', 'video_short.webm')
206 makePostRequest(path
, server
.accessToken
, data
, attach
, done
)
209 it('Should fail with a long name', function (done
) {
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'
215 'videofile': pathUtils
.join(__dirname
, 'fixtures', 'video_short.webm')
217 makePostRequest(path
, server
.accessToken
, data
, attach
, done
)
220 it('Should fail without description', function (done
) {
222 name: 'my super name'
225 'videofile': pathUtils
.join(__dirname
, 'fixtures', 'video_short.webm')
227 makePostRequest(path
, server
.accessToken
, data
, attach
, done
)
230 it('Should fail with a long description', function (done
) {
232 name: 'my super name',
233 description: 'my super description which is very very very very very very very very very very very very very very' +
234 'very very very very very very very very very very very very very very very very very very very very very' +
235 'very very very very very very very very very very very very very very very long'
238 'videofile': pathUtils
.join(__dirname
, 'fixtures', 'video_short.webm')
240 makePostRequest(path
, server
.accessToken
, data
, attach
, done
)
243 it('Should fail without an input file', function (done
) {
245 name: 'my super name',
246 description: 'my super description'
249 makePostRequest(path
, server
.accessToken
, data
, attach
, done
)
252 it('Should fail without an incorrect input file', function (done
) {
254 name: 'my super name',
255 description: 'my super description'
258 'videofile': pathUtils
.join(__dirname
, 'fixtures', 'video_short_fake.webm')
260 makePostRequest(path
, server
.accessToken
, data
, attach
, done
)
263 it('Should fail with a too big duration', function (done
) {
265 name: 'my super name',
266 description: 'my super description'
269 'videofile': pathUtils
.join(__dirname
, 'fixtures', 'video_too_long.webm')
271 makePostRequest(path
, server
.accessToken
, data
, attach
, done
)
274 it('Should succeed with the correct parameters', function (done
) {
276 name: 'my super name',
277 description: 'my super description'
280 'videofile': pathUtils
.join(__dirname
, 'fixtures', 'video_short.webm')
282 makePostRequest(path
, server
.accessToken
, data
, attach
, function () {
283 attach
.videofile
= pathUtils
.join(__dirname
, 'fixtures', 'video_short.mp4')
284 makePostRequest(path
, server
.accessToken
, data
, attach
, function () {
285 attach
.videofile
= pathUtils
.join(__dirname
, 'fixtures', 'video_short.ogv')
286 makePostRequest(path
, server
.accessToken
, data
, attach
, done
, false)
292 describe('When getting a video', function () {
293 it('Should return the list of the videos with nothing', function (done
) {
296 .set('Accept', 'application/json')
298 .expect('Content-Type', /json/)
299 .end(function (err
, res
) {
302 expect(res
.body
).to
.be
.an('array')
303 expect(res
.body
.length
).to
.equal(3)
309 it('Should fail without a mongodb id', function (done
) {
311 .get(path
+ 'coucou')
312 .set('Accept', 'application/json')
316 it('Should return 404 with an incorrect video', function (done
) {
318 .get(path
+ '123456789012345678901234')
319 .set('Accept', 'application/json')
323 it('Should succeed with the correct parameters')
326 describe('When removing a video', function () {
327 it('Should have 404 with nothing', function (done
) {
330 .set('Authorization', 'Bearer ' + server
.accessToken
)
334 it('Should fail without a mongodb id', function (done
) {
336 .delete(path
+ 'hello')
337 .set('Authorization', 'Bearer ' + server
.accessToken
)
341 it('Should fail with a video which does not exist', function (done
) {
343 .delete(path
+ '123456789012345678901234')
344 .set('Authorization', 'Bearer ' + server
.accessToken
)
348 it('Should fail with a video of another pod')
350 it('Should succeed with the correct parameters')
354 describe('Of the remote videos API', function () {
355 describe('When making a secure request', function () {
356 it('Should check a secure request')
359 describe('When adding a video', function () {
360 it('Should check when adding a video')
363 describe('When removing a video', function () {
364 it('Should check when removing a video')
368 after(function (done
) {
369 process
.kill(-server
.app
.pid
)
371 // Keep the logs if the test failed
373 utils
.flushTests(done
)