aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api/checkParams.js
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests/api/checkParams.js')
-rw-r--r--server/tests/api/checkParams.js68
1 files changed, 40 insertions, 28 deletions
diff --git a/server/tests/api/checkParams.js b/server/tests/api/checkParams.js
index dcc190e97..59ee0bfc3 100644
--- a/server/tests/api/checkParams.js
+++ b/server/tests/api/checkParams.js
@@ -9,17 +9,18 @@ const request = require('supertest')
9const utils = require('./utils') 9const utils = require('./utils')
10 10
11describe('Test parameters validator', function () { 11describe('Test parameters validator', function () {
12 let app = null 12 let server = null
13 let url = ''
14 13
15 function makePostRequest (path, fields, attach, done, fail) { 14 function makePostRequest (path, token, fields, attach, done, fail) {
16 let status_code = 400 15 let status_code = 400
17 if (fail !== undefined && fail === false) status_code = 200 16 if (fail !== undefined && fail === false) status_code = 200
18 17
19 const req = request(url) 18 const req = request(server.url)
20 .post(path) 19 .post(path)
21 .set('Accept', 'application/json') 20 .set('Accept', 'application/json')
22 21
22 if (token) req.set('Authorization', 'Bearer ' + token)
23
23 Object.keys(fields).forEach(function (field) { 24 Object.keys(fields).forEach(function (field) {
24 const value = fields[field] 25 const value = fields[field]
25 req.field(field, value) 26 req.field(field, value)
@@ -32,7 +33,7 @@ describe('Test parameters validator', function () {
32 let status_code = 400 33 let status_code = 400
33 if (fail !== undefined && fail === false) status_code = 200 34 if (fail !== undefined && fail === false) status_code = 200
34 35
35 request(url) 36 request(server.url)
36 .post(path) 37 .post(path)
37 .set('Accept', 'application/json') 38 .set('Accept', 'application/json')
38 .send(fields) 39 .send(fields)
@@ -49,9 +50,17 @@ describe('Test parameters validator', function () {
49 utils.flushTests(next) 50 utils.flushTests(next)
50 }, 51 },
51 function (next) { 52 function (next) {
52 utils.runServer(1, function (app1, url1) { 53 utils.runServer(1, function (server1) {
53 app = app1 54 server = server1
54 url = url1 55
56 next()
57 })
58 },
59 function (next) {
60 utils.loginAndGetAccessToken(server, function (err, token) {
61 if (err) throw err
62 server.access_token = token
63
55 next() 64 next()
56 }) 65 })
57 } 66 }
@@ -118,7 +127,7 @@ describe('Test parameters validator', function () {
118 127
119 describe('When searching a video', function () { 128 describe('When searching a video', function () {
120 it('Should fail with nothing', function (done) { 129 it('Should fail with nothing', function (done) {
121 request(url) 130 request(server.url)
122 .get(pathUtils.join(path, 'search')) 131 .get(pathUtils.join(path, 'search'))
123 .set('Accept', 'application/json') 132 .set('Accept', 'application/json')
124 .expect(400, done) 133 .expect(400, done)
@@ -129,7 +138,7 @@ describe('Test parameters validator', function () {
129 it('Should fail with nothing', function (done) { 138 it('Should fail with nothing', function (done) {
130 const data = {} 139 const data = {}
131 const attach = {} 140 const attach = {}
132 makePostRequest(path, data, attach, done) 141 makePostRequest(path, server.access_token, data, attach, done)
133 }) 142 })
134 143
135 it('Should fail without name', function (done) { 144 it('Should fail without name', function (done) {
@@ -139,7 +148,7 @@ describe('Test parameters validator', function () {
139 const attach = { 148 const attach = {
140 'videofile': pathUtils.join(__dirname, 'fixtures', 'video_short.webm') 149 'videofile': pathUtils.join(__dirname, 'fixtures', 'video_short.webm')
141 } 150 }
142 makePostRequest(path, data, attach, done) 151 makePostRequest(path, server.access_token, data, attach, done)
143 }) 152 })
144 153
145 it('Should fail with a long name', function (done) { 154 it('Should fail with a long name', function (done) {
@@ -150,7 +159,7 @@ describe('Test parameters validator', function () {
150 const attach = { 159 const attach = {
151 'videofile': pathUtils.join(__dirname, 'fixtures', 'video_short.webm') 160 'videofile': pathUtils.join(__dirname, 'fixtures', 'video_short.webm')
152 } 161 }
153 makePostRequest(path, data, attach, done) 162 makePostRequest(path, server.access_token, data, attach, done)
154 }) 163 })
155 164
156 it('Should fail without description', function (done) { 165 it('Should fail without description', function (done) {
@@ -160,7 +169,7 @@ describe('Test parameters validator', function () {
160 const attach = { 169 const attach = {
161 'videofile': pathUtils.join(__dirname, 'fixtures', 'video_short.webm') 170 'videofile': pathUtils.join(__dirname, 'fixtures', 'video_short.webm')
162 } 171 }
163 makePostRequest(path, data, attach, done) 172 makePostRequest(path, server.access_token, data, attach, done)
164 }) 173 })
165 174
166 it('Should fail with a long description', function (done) { 175 it('Should fail with a long description', function (done) {
@@ -173,7 +182,7 @@ describe('Test parameters validator', function () {
173 const attach = { 182 const attach = {
174 'videofile': pathUtils.join(__dirname, 'fixtures', 'video_short.webm') 183 'videofile': pathUtils.join(__dirname, 'fixtures', 'video_short.webm')
175 } 184 }
176 makePostRequest(path, data, attach, done) 185 makePostRequest(path, server.access_token, data, attach, done)
177 }) 186 })
178 187
179 it('Should fail without an input file', function (done) { 188 it('Should fail without an input file', function (done) {
@@ -182,7 +191,7 @@ describe('Test parameters validator', function () {
182 description: 'my super description' 191 description: 'my super description'
183 } 192 }
184 const attach = {} 193 const attach = {}
185 makePostRequest(path, data, attach, done) 194 makePostRequest(path, server.access_token, data, attach, done)
186 }) 195 })
187 196
188 it('Should fail without an incorrect input file', function (done) { 197 it('Should fail without an incorrect input file', function (done) {
@@ -193,7 +202,7 @@ describe('Test parameters validator', function () {
193 const attach = { 202 const attach = {
194 'videofile': pathUtils.join(__dirname, '..', 'fixtures', 'video_short_fake.webm') 203 'videofile': pathUtils.join(__dirname, '..', 'fixtures', 'video_short_fake.webm')
195 } 204 }
196 makePostRequest(path, data, attach, done) 205 makePostRequest(path, server.access_token, data, attach, done)
197 }) 206 })
198 207
199 it('Should succeed with the correct parameters', function (done) { 208 it('Should succeed with the correct parameters', function (done) {
@@ -204,11 +213,11 @@ describe('Test parameters validator', function () {
204 const attach = { 213 const attach = {
205 'videofile': pathUtils.join(__dirname, 'fixtures', 'video_short.webm') 214 'videofile': pathUtils.join(__dirname, 'fixtures', 'video_short.webm')
206 } 215 }
207 makePostRequest(path, data, attach, function () { 216 makePostRequest(path, server.access_token, data, attach, function () {
208 attach.videofile = pathUtils.join(__dirname, 'fixtures', 'video_short.mp4') 217 attach.videofile = pathUtils.join(__dirname, 'fixtures', 'video_short.mp4')
209 makePostRequest(path, data, attach, function () { 218 makePostRequest(path, server.access_token, data, attach, function () {
210 attach.videofile = pathUtils.join(__dirname, 'fixtures', 'video_short.ogv') 219 attach.videofile = pathUtils.join(__dirname, 'fixtures', 'video_short.ogv')
211 makePostRequest(path, data, attach, done, true) 220 makePostRequest(path, server.access_token, data, attach, done, true)
212 }, true) 221 }, true)
213 }, true) 222 }, true)
214 }) 223 })
@@ -216,7 +225,7 @@ describe('Test parameters validator', function () {
216 225
217 describe('When getting a video', function () { 226 describe('When getting a video', function () {
218 it('Should return the list of the videos with nothing', function (done) { 227 it('Should return the list of the videos with nothing', function (done) {
219 request(url) 228 request(server.url)
220 .get(path) 229 .get(path)
221 .set('Accept', 'application/json') 230 .set('Accept', 'application/json')
222 .expect(200) 231 .expect(200)
@@ -232,14 +241,14 @@ describe('Test parameters validator', function () {
232 }) 241 })
233 242
234 it('Should fail without a mongodb id', function (done) { 243 it('Should fail without a mongodb id', function (done) {
235 request(url) 244 request(server.url)
236 .get(path + 'coucou') 245 .get(path + 'coucou')
237 .set('Accept', 'application/json') 246 .set('Accept', 'application/json')
238 .expect(400, done) 247 .expect(400, done)
239 }) 248 })
240 249
241 it('Should return 404 with an incorrect video', function (done) { 250 it('Should return 404 with an incorrect video', function (done) {
242 request(url) 251 request(server.url)
243 .get(path + '123456789012345678901234') 252 .get(path + '123456789012345678901234')
244 .set('Accept', 'application/json') 253 .set('Accept', 'application/json')
245 .expect(404, done) 254 .expect(404, done)
@@ -250,20 +259,23 @@ describe('Test parameters validator', function () {
250 259
251 describe('When removing a video', function () { 260 describe('When removing a video', function () {
252 it('Should have 404 with nothing', function (done) { 261 it('Should have 404 with nothing', function (done) {
253 request(url) 262 request(server.url)
254 .delete(path) 263 .delete(path)
255 .expect(400, done) 264 .set('Authorization', 'Bearer ' + server.access_token)
265 .expect(400, done)
256 }) 266 })
257 267
258 it('Should fail without a mongodb id', function (done) { 268 it('Should fail without a mongodb id', function (done) {
259 request(url) 269 request(server.url)
260 .delete(path + 'hello') 270 .delete(path + 'hello')
271 .set('Authorization', 'Bearer ' + server.access_token)
261 .expect(400, done) 272 .expect(400, done)
262 }) 273 })
263 274
264 it('Should fail with a video which does not exist', function (done) { 275 it('Should fail with a video which does not exist', function (done) {
265 request(url) 276 request(server.url)
266 .delete(path + '123456789012345678901234') 277 .delete(path + '123456789012345678901234')
278 .set('Authorization', 'Bearer ' + server.access_token)
267 .expect(404, done) 279 .expect(404, done)
268 }) 280 })
269 281
@@ -288,7 +300,7 @@ describe('Test parameters validator', function () {
288 }) 300 })
289 301
290 after(function (done) { 302 after(function (done) {
291 process.kill(-app.pid) 303 process.kill(-server.app.pid)
292 304
293 // Keep the logs if the test failed 305 // Keep the logs if the test failed
294 if (this.ok) { 306 if (this.ok) {