]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - tests/api/checkParams.js
Remove useless anonymous functions of files
[github/Chocobozzz/PeerTube.git] / tests / api / checkParams.js
CommitLineData
9f10b292 1'use strict'
34ca3b52 2
9f10b292
C
3var async = require('async')
4var chai = require('chai')
5var expect = chai.expect
6var pathUtils = require('path')
7var request = require('supertest')
34ca3b52 8
9f10b292 9var utils = require('./utils')
34ca3b52 10
9f10b292
C
11describe('Test parameters validator', function () {
12 var app = null
13 var url = ''
34ca3b52 14
9f10b292
C
15 function makePostRequest (path, fields, attach, done, fail) {
16 var status_code = 400
17 if (fail !== undefined && fail === false) status_code = 200
34ca3b52 18
9f10b292
C
19 var req = request(url)
20 .post(path)
21 .set('Accept', 'application/json')
34ca3b52 22
9f10b292
C
23 Object.keys(fields).forEach(function (field) {
24 var value = fields[field]
25 req.field(field, value)
ee66c593
C
26 })
27
9f10b292
C
28 req.expect(status_code, done)
29 }
30
31 function makePostBodyRequest (path, fields, done, fail) {
32 var status_code = 400
33 if (fail !== undefined && fail === false) status_code = 200
34
35 request(url)
36 .post(path)
37 .set('Accept', 'application/json')
38 .send(fields)
39 .expect(status_code, done)
40 }
41
42 // ---------------------------------------------------------------
43
44 before(function (done) {
45 this.timeout(20000)
46
47 async.series([
48 function (next) {
49 utils.flushTests(next)
50 },
51 function (next) {
52 utils.runServer(1, function (app1, url1) {
53 app = app1
54 url = url1
55 next()
34ca3b52 56 })
9f10b292
C
57 }
58 ], done)
59 })
60
61 describe('Of the pods API', function () {
62 var path = '/api/v1/pods/'
63
64 describe('When adding a pod', function () {
65 it('Should fail with nothing', function (done) {
66 var data = {}
67 makePostBodyRequest(path, data, done)
68 })
34ca3b52 69
9f10b292
C
70 it('Should fail without public key', function (done) {
71 var data = {
72 data: {
73 url: 'http://coucou.com'
34ca3b52 74 }
9f10b292
C
75 }
76 makePostBodyRequest(path, data, done)
77 })
34ca3b52 78
9f10b292
C
79 it('Should fail without an url', function (done) {
80 var data = {
81 data: {
82 publicKey: 'mysuperpublickey'
34ca3b52 83 }
9f10b292
C
84 }
85 makePostBodyRequest(path, data, done)
86 })
34ca3b52 87
9f10b292
C
88 it('Should fail with an incorrect url', function (done) {
89 var data = {
90 data: {
91 url: 'coucou.com',
92 publicKey: 'mysuperpublickey'
34ca3b52 93 }
9f10b292
C
94 }
95 makePostBodyRequest(path, data, function () {
96 data.data.url = 'http://coucou'
34ca3b52 97 makePostBodyRequest(path, data, function () {
9f10b292
C
98 data.data.url = 'coucou'
99 makePostBodyRequest(path, data, done)
34ca3b52
C
100 })
101 })
9f10b292 102 })
34ca3b52 103
9f10b292
C
104 it('Should succeed with the correct parameters', function (done) {
105 var data = {
106 data: {
107 url: 'http://coucou.com',
108 publicKey: 'mysuperpublickey'
34ca3b52 109 }
9f10b292
C
110 }
111 makePostBodyRequest(path, data, done, false)
34ca3b52
C
112 })
113 })
9f10b292 114 })
34ca3b52 115
9f10b292
C
116 describe('Of the videos API', function () {
117 var path = '/api/v1/videos/'
34ca3b52 118
9f10b292
C
119 describe('When searching a video', function () {
120 it('Should fail with nothing', function (done) {
121 request(url)
122 .get(pathUtils.join(path, 'search'))
123 .set('Accept', 'application/json')
124 .expect(400, done)
34ca3b52 125 })
9f10b292 126 })
34ca3b52 127
9f10b292
C
128 describe('When adding a video', function () {
129 it('Should fail with nothing', function (done) {
130 var data = {}
131 var attach = {}
132 makePostRequest(path, data, attach, done)
133 })
34ca3b52 134
9f10b292
C
135 it('Should fail without name', function (done) {
136 var data = {
137 description: 'my super description'
138 }
139 var attach = {
140 'input_video': pathUtils.join(__dirname, 'fixtures', 'video_short.webm')
141 }
142 makePostRequest(path, data, attach, done)
143 })
34ca3b52 144
9f10b292
C
145 it('Should fail with a long name', function (done) {
146 var data = {
147 name: 'My very very very very very very very very very very very very very very very very long name',
148 description: 'my super description'
149 }
150 var attach = {
151 'input_video': pathUtils.join(__dirname, 'fixtures', 'video_short.webm')
152 }
153 makePostRequest(path, data, attach, done)
154 })
34ca3b52 155
9f10b292
C
156 it('Should fail without description', function (done) {
157 var data = {
158 name: 'my super name'
159 }
160 var attach = {
161 'input_video': pathUtils.join(__dirname, 'fixtures', 'video_short.webm')
162 }
163 makePostRequest(path, data, attach, done)
164 })
34ca3b52 165
9f10b292
C
166 it('Should fail with a long description', function (done) {
167 var data = {
168 name: 'my super name',
169 description: 'my super description which is very very very very very very very very very very very very very very' +
170 'very very very very very very very very very very very very very very very very very very very very very' +
171 'very very very very very very very very very very very very very very very long'
172 }
173 var attach = {
174 'input_video': pathUtils.join(__dirname, 'fixtures', 'video_short.webm')
175 }
176 makePostRequest(path, data, attach, done)
177 })
34ca3b52 178
9f10b292
C
179 it('Should fail without an input file', function (done) {
180 var data = {
181 name: 'my super name',
182 description: 'my super description'
183 }
184 var attach = {}
185 makePostRequest(path, data, attach, done)
186 })
34ca3b52 187
9f10b292
C
188 it('Should fail without an incorrect input file', function (done) {
189 var data = {
190 name: 'my super name',
191 description: 'my super description'
192 }
193 var attach = {
194 'input_video': pathUtils.join(__dirname, '..', 'fixtures', 'video_short_fake.webm')
195 }
196 makePostRequest(path, data, attach, done)
197 })
34ca3b52 198
9f10b292
C
199 it('Should succeed with the correct parameters', function (done) {
200 var data = {
201 name: 'my super name',
202 description: 'my super description'
203 }
204 var attach = {
205 'input_video': pathUtils.join(__dirname, 'fixtures', 'video_short.webm')
206 }
207 makePostRequest(path, data, attach, function () {
208 attach.input_video = pathUtils.join(__dirname, 'fixtures', 'video_short.mp4')
34ca3b52 209 makePostRequest(path, data, attach, function () {
9f10b292
C
210 attach.input_video = pathUtils.join(__dirname, 'fixtures', 'video_short.ogv')
211 makePostRequest(path, data, attach, done, true)
34ca3b52 212 }, true)
9f10b292 213 }, true)
34ca3b52 214 })
9f10b292 215 })
34ca3b52 216
9f10b292
C
217 describe('When getting a video', function () {
218 it('Should return the list of the videos with nothing', function (done) {
219 request(url)
220 .get(path)
221 .set('Accept', 'application/json')
222 .expect(200)
223 .expect('Content-Type', /json/)
224 .end(function (err, res) {
225 if (err) throw err
34ca3b52 226
9f10b292
C
227 expect(res.body).to.be.an('array')
228 expect(res.body.length).to.equal(0)
34ca3b52 229
9f10b292
C
230 done()
231 })
232 })
34ca3b52 233
9f10b292
C
234 it('Should fail without a mongodb id', function (done) {
235 request(url)
236 .get(path + 'coucou')
237 .set('Accept', 'application/json')
238 .expect(400, done)
34ca3b52
C
239 })
240
9f10b292
C
241 it('Should return 404 with an incorrect video', function (done) {
242 request(url)
243 .get(path + '123456789012345678901234')
244 .set('Accept', 'application/json')
34ca3b52 245 .expect(404, done)
34ca3b52 246 })
9f10b292
C
247
248 it('Should succeed with the correct parameters')
34ca3b52
C
249 })
250
9f10b292
C
251 describe('When removing a video', function () {
252 it('Should have 404 with nothing', function (done) {
253 request(url)
254 .delete(path)
255 .expect(404, done)
34ca3b52
C
256 })
257
9f10b292
C
258 it('Should fail without a mongodb id', function (done) {
259 request(url)
260 .delete(path + 'hello')
261 .expect(400, done)
34ca3b52
C
262 })
263
9f10b292
C
264 it('Should fail with a video which does not exist', function (done) {
265 request(url)
266 .delete(path + '123456789012345678901234')
267 .expect(404, done)
34ca3b52 268 })
9f10b292
C
269
270 it('Should fail with a video of another pod')
271
272 it('Should succeed with the correct parameters')
34ca3b52 273 })
9f10b292 274 })
34ca3b52 275
9f10b292
C
276 describe('Of the remote videos API', function () {
277 describe('When making a secure request', function () {
278 it('Should check a secure request')
279 })
34ca3b52 280
9f10b292
C
281 describe('When adding a video', function () {
282 it('Should check when adding a video')
34ca3b52 283 })
9f10b292
C
284
285 describe('When removing a video', function () {
286 it('Should check when removing a video')
287 })
288 })
289
290 after(function (done) {
291 process.kill(-app.pid)
292
293 // Keep the logs if the test failed
294 if (this.ok) {
295 utils.flushTests(done)
296 } else {
297 done()
298 }
34ca3b52 299 })
9f10b292 300})