]>
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 searching a video', function () {
134 it('Should fail with nothing', function (done
) {
136 .get(pathUtils
.join(path
, 'search'))
137 .set('Accept', 'application/json')
142 describe('When adding a video', function () {
143 it('Should fail with nothing', function (done
) {
146 makePostRequest(path
, server
.accessToken
, data
, attach
, done
)
149 it('Should fail without name', function (done
) {
151 description: 'my super description'
154 'videofile': pathUtils
.join(__dirname
, 'fixtures', 'video_short.webm')
156 makePostRequest(path
, server
.accessToken
, data
, attach
, done
)
159 it('Should fail with a long name', function (done
) {
161 name: 'My very very very very very very very very very very very very very very very very long name',
162 description: 'my super description'
165 'videofile': pathUtils
.join(__dirname
, 'fixtures', 'video_short.webm')
167 makePostRequest(path
, server
.accessToken
, data
, attach
, done
)
170 it('Should fail without description', function (done
) {
172 name: 'my super name'
175 'videofile': pathUtils
.join(__dirname
, 'fixtures', 'video_short.webm')
177 makePostRequest(path
, server
.accessToken
, data
, attach
, done
)
180 it('Should fail with a long description', function (done
) {
182 name: 'my super name',
183 description: 'my super description which is very very very very very very very very very very very very very very' +
184 'very very very very very very very very very very very very very very very very very very very very very' +
185 'very very very very very very very very very very very very very very very long'
188 'videofile': pathUtils
.join(__dirname
, 'fixtures', 'video_short.webm')
190 makePostRequest(path
, server
.accessToken
, data
, attach
, done
)
193 it('Should fail without an input file', function (done
) {
195 name: 'my super name',
196 description: 'my super description'
199 makePostRequest(path
, server
.accessToken
, data
, attach
, done
)
202 it('Should fail without an incorrect input file', function (done
) {
204 name: 'my super name',
205 description: 'my super description'
208 'videofile': pathUtils
.join(__dirname
, 'fixtures', 'video_short_fake.webm')
210 makePostRequest(path
, server
.accessToken
, data
, attach
, done
)
213 it('Should fail with a too big duration', function (done
) {
215 name: 'my super name',
216 description: 'my super description'
219 'videofile': pathUtils
.join(__dirname
, 'fixtures', 'video_too_long.webm')
221 makePostRequest(path
, server
.accessToken
, data
, attach
, done
)
224 it('Should succeed with the correct parameters', function (done
) {
226 name: 'my super name',
227 description: 'my super description'
230 'videofile': pathUtils
.join(__dirname
, 'fixtures', 'video_short.webm')
232 makePostRequest(path
, server
.accessToken
, data
, attach
, function () {
233 attach
.videofile
= pathUtils
.join(__dirname
, 'fixtures', 'video_short.mp4')
234 makePostRequest(path
, server
.accessToken
, data
, attach
, function () {
235 attach
.videofile
= pathUtils
.join(__dirname
, 'fixtures', 'video_short.ogv')
236 makePostRequest(path
, server
.accessToken
, data
, attach
, done
, false)
242 describe('When getting a video', function () {
243 it('Should return the list of the videos with nothing', function (done
) {
246 .set('Accept', 'application/json')
248 .expect('Content-Type', /json/)
249 .end(function (err
, res
) {
252 expect(res
.body
).to
.be
.an('array')
253 expect(res
.body
.length
).to
.equal(3)
259 it('Should fail without a mongodb id', function (done
) {
261 .get(path
+ 'coucou')
262 .set('Accept', 'application/json')
266 it('Should return 404 with an incorrect video', function (done
) {
268 .get(path
+ '123456789012345678901234')
269 .set('Accept', 'application/json')
273 it('Should succeed with the correct parameters')
276 describe('When removing a video', function () {
277 it('Should have 404 with nothing', function (done
) {
280 .set('Authorization', 'Bearer ' + server
.accessToken
)
284 it('Should fail without a mongodb id', function (done
) {
286 .delete(path
+ 'hello')
287 .set('Authorization', 'Bearer ' + server
.accessToken
)
291 it('Should fail with a video which does not exist', function (done
) {
293 .delete(path
+ '123456789012345678901234')
294 .set('Authorization', 'Bearer ' + server
.accessToken
)
298 it('Should fail with a video of another pod')
300 it('Should succeed with the correct parameters')
304 describe('Of the remote videos API', function () {
305 describe('When making a secure request', function () {
306 it('Should check a secure request')
309 describe('When adding a video', function () {
310 it('Should check when adding a video')
313 describe('When removing a video', function () {
314 it('Should check when removing a video')
318 after(function (done
) {
319 process
.kill(-server
.app
.pid
)
321 // Keep the logs if the test failed
323 utils
.flushTests(done
)