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