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