]>
git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - test/api/checkParams.js
4 var request
= require('supertest')
5 var chai
= require('chai')
6 var expect
= chai
.expect
8 var utils
= require('../utils')
10 describe('Test parameters validator', function () {
14 before(function (done
) {
17 utils
.flushTests(function () {
18 utils
.runServer(1, function (app1
, url1
) {
26 function makePostRequest (path
, fields
, attach
, done
, fail
) {
28 if (fail
!== undefined && fail
=== false) status_code
= 200
30 var req
= request(url
)
32 .set('Accept', 'application/json')
34 Object
.keys(fields
).forEach(function (field
) {
35 var value
= fields
[field
]
36 req
.field(field
, value
)
39 req
.expect(status_code
, done
)
42 function makePostBodyRequest (path
, fields
, done
, fail
) {
44 if (fail
!== undefined && fail
=== false) status_code
= 200
48 .set('Accept', 'application/json')
50 .expect(status_code
, done
)
53 describe('Of the pods API', function () {
54 var path
= '/api/v1/pods/'
56 describe('When adding a pod', function () {
57 it('Should fail with nothing', function (done
) {
59 makePostBodyRequest(path
, data
, done
)
62 it('Should fail without public key', function (done
) {
65 url: 'http://coucou.com'
68 makePostBodyRequest(path
, data
, done
)
71 it('Should fail without an url', function (done
) {
74 publicKey: 'mysuperpublickey'
77 makePostBodyRequest(path
, data
, done
)
80 it('Should fail with an incorrect url', function (done
) {
84 publicKey: 'mysuperpublickey'
87 makePostBodyRequest(path
, data
, function () {
88 data
.data
.url
= 'http://coucou'
89 makePostBodyRequest(path
, data
, function () {
90 data
.data
.url
= 'coucou'
91 makePostBodyRequest(path
, data
, done
)
96 it('Should succeed with the correct parameters', function (done
) {
99 url: 'http://coucou.com',
100 publicKey: 'mysuperpublickey'
103 makePostBodyRequest(path
, data
, done
, false)
108 describe('Of the videos API', function () {
109 var path
= '/api/v1/videos/'
111 describe('When searching a video', function () {
112 it('Should fail with nothing', function (done
) {
114 .get(path
+ '/search/')
115 .set('Accept', 'application/json')
120 describe('When adding a video', function () {
121 it('Should fail with nothing', function (done
) {
124 makePostRequest(path
, data
, attach
, done
)
127 it('Should fail without name', function (done
) {
129 description: 'my super description'
132 'input_video': __dirname
+ '/../fixtures/video_short.webm'
134 makePostRequest(path
, data
, attach
, done
)
137 it('Should fail with a long name', function (done
) {
139 name: 'My very very very very very very very very very very very very very very very very long name',
140 description: 'my super description'
143 'input_video': __dirname
+ '/../fixtures/video_short.webm'
145 makePostRequest(path
, data
, attach
, done
)
148 it('Should fail without description', function (done
) {
150 name: 'my super name'
153 'input_video': __dirname
+ '/../fixtures/video_short.webm'
155 makePostRequest(path
, data
, attach
, done
)
158 it('Should fail with a long description', function (done
) {
160 name: 'my super name',
161 description: 'my super description which is very very very very very very very very very very very very very very' +
162 'very very very very very very very very very very very very very very very very very very very very very' +
163 'very very very very very very very very very very very very very very very long'
166 'input_video': __dirname
+ '/../fixtures/video_short.webm'
168 makePostRequest(path
, data
, attach
, done
)
171 it('Should fail without an input file', function (done
) {
173 name: 'my super name',
174 description: 'my super description'
177 makePostRequest(path
, data
, attach
, done
)
180 it('Should fail without an incorrect input file', function (done
) {
182 name: 'my super name',
183 description: 'my super description'
186 'input_video': __dirname
+ '/../fixtures/video_short_fake.webm'
188 makePostRequest(path
, data
, attach
, done
)
191 it('Should succeed with the correct parameters', function (done
) {
193 name: 'my super name',
194 description: 'my super description'
197 'input_video': __dirname
+ '/../fixtures/video_short.webm'
199 makePostRequest(path
, data
, attach
, function () {
200 attach
.input_video
= __dirname
+ '/../fixtures/video_short.mp4'
201 makePostRequest(path
, data
, attach
, function () {
202 attach
.input_video
= __dirname
+ '/../fixtures/video_short.ogv'
203 makePostRequest(path
, data
, attach
, done
, true)
209 describe('When getting a video', function () {
210 it('Should return the list of the videos with nothing', function (done
) {
213 .set('Accept', 'application/json')
215 .expect('Content-Type', /json/)
216 .end(function (err
, res
) {
219 expect(res
.body
).to
.be
.an('array')
220 expect(res
.body
.length
).to
.equal(0)
226 it('Should fail without a mongodb id', function (done
) {
228 .get(path
+ 'coucou')
229 .set('Accept', 'application/json')
233 it('Should return 404 with an incorrect video', function (done
) {
235 .get(path
+ '123456789012345678901234')
236 .set('Accept', 'application/json')
240 it('Should succeed with the correct parameters')
243 describe('When removing a video', function () {
244 it('Should have 404 with nothing', function (done
) {
250 it('Should fail without a mongodb id', function (done
) {
252 .delete(path
+ 'hello')
256 it('Should fail with a video which does not exist', function (done
) {
258 .delete(path
+ '123456789012345678901234')
262 it('Should fail with a video of another pod')
264 it('Should succeed with the correct parameters')
268 describe('Of the remote videos API', function () {
269 describe('When making a secure request', function () {
270 it('Should check a secure request')
273 describe('When adding a video', function () {
274 it('Should check when adding a video')
277 describe('When removing a video', function () {
278 it('Should check when removing a video')
282 after(function (done
) {
283 process
.kill(-app
.pid
)
285 // Keep the logs if the test failed
287 utils
.flushTests(function () {