diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2016-06-06 14:15:03 +0200 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2016-06-06 14:15:03 +0200 |
commit | be587647f98a4b83ca06a61fe55c7ac5d60927c6 (patch) | |
tree | 8a28a1cb9c9a06d80803ecd3fa00aa6767bb3f8b /server/tests/api/checkParams.js | |
parent | 8483b2216454afdb88f6aa53cad5eecd8c394bc0 (diff) | |
download | PeerTube-be587647f98a4b83ca06a61fe55c7ac5d60927c6.tar.gz PeerTube-be587647f98a4b83ca06a61fe55c7ac5d60927c6.tar.zst PeerTube-be587647f98a4b83ca06a61fe55c7ac5d60927c6.zip |
Add tags support to server
Diffstat (limited to 'server/tests/api/checkParams.js')
-rw-r--r-- | server/tests/api/checkParams.js | 104 |
1 files changed, 95 insertions, 9 deletions
diff --git a/server/tests/api/checkParams.js b/server/tests/api/checkParams.js index e02fd0da5..95a7738f8 100644 --- a/server/tests/api/checkParams.js +++ b/server/tests/api/checkParams.js | |||
@@ -23,7 +23,14 @@ describe('Test parameters validator', function () { | |||
23 | 23 | ||
24 | Object.keys(fields).forEach(function (field) { | 24 | Object.keys(fields).forEach(function (field) { |
25 | const value = fields[field] | 25 | const value = fields[field] |
26 | req.field(field, value) | 26 | |
27 | if (Array.isArray(value)) { | ||
28 | for (let i = 0; i < value.length; i++) { | ||
29 | req.field(field + '[' + i + ']', value[i]) | ||
30 | } | ||
31 | } else { | ||
32 | req.field(field, value) | ||
33 | } | ||
27 | }) | 34 | }) |
28 | 35 | ||
29 | Object.keys(attaches).forEach(function (attach) { | 36 | Object.keys(attaches).forEach(function (attach) { |
@@ -198,7 +205,8 @@ describe('Test parameters validator', function () { | |||
198 | 205 | ||
199 | it('Should fail without name', function (done) { | 206 | it('Should fail without name', function (done) { |
200 | const data = { | 207 | const data = { |
201 | description: 'my super description' | 208 | description: 'my super description', |
209 | tags: [ 'tag1', 'tag2' ] | ||
202 | } | 210 | } |
203 | const attach = { | 211 | const attach = { |
204 | 'videofile': pathUtils.join(__dirname, 'fixtures', 'video_short.webm') | 212 | 'videofile': pathUtils.join(__dirname, 'fixtures', 'video_short.webm') |
@@ -209,7 +217,8 @@ describe('Test parameters validator', function () { | |||
209 | it('Should fail with a long name', function (done) { | 217 | it('Should fail with a long name', function (done) { |
210 | const data = { | 218 | const data = { |
211 | name: 'My very very very very very very very very very very very very very very very very long name', | 219 | name: 'My very very very very very very very very very very very very very very very very long name', |
212 | description: 'my super description' | 220 | description: 'my super description', |
221 | tags: [ 'tag1', 'tag2' ] | ||
213 | } | 222 | } |
214 | const attach = { | 223 | const attach = { |
215 | 'videofile': pathUtils.join(__dirname, 'fixtures', 'video_short.webm') | 224 | 'videofile': pathUtils.join(__dirname, 'fixtures', 'video_short.webm') |
@@ -219,7 +228,8 @@ describe('Test parameters validator', function () { | |||
219 | 228 | ||
220 | it('Should fail without description', function (done) { | 229 | it('Should fail without description', function (done) { |
221 | const data = { | 230 | const data = { |
222 | name: 'my super name' | 231 | name: 'my super name', |
232 | tags: [ 'tag1', 'tag2' ] | ||
223 | } | 233 | } |
224 | const attach = { | 234 | const attach = { |
225 | 'videofile': pathUtils.join(__dirname, 'fixtures', 'video_short.webm') | 235 | 'videofile': pathUtils.join(__dirname, 'fixtures', 'video_short.webm') |
@@ -232,7 +242,8 @@ describe('Test parameters validator', function () { | |||
232 | name: 'my super name', | 242 | name: 'my super name', |
233 | description: 'my super description which is very very very very very very very very very very very very very very' + | 243 | description: 'my super description which is very very very very very very very very very very very very very very' + |
234 | 'very very very very very very very very very very very very very very very very very very very very very' + | 244 | 'very very very very very very very very very very very very very very very very very very very very very' + |
235 | 'very very very very very very very very very very very very very very very long' | 245 | 'very very very very very very very very very very very very very very very long', |
246 | tags: [ 'tag1', 'tag2' ] | ||
236 | } | 247 | } |
237 | const attach = { | 248 | const attach = { |
238 | 'videofile': pathUtils.join(__dirname, 'fixtures', 'video_short.webm') | 249 | 'videofile': pathUtils.join(__dirname, 'fixtures', 'video_short.webm') |
@@ -240,11 +251,83 @@ describe('Test parameters validator', function () { | |||
240 | makePostRequest(path, server.accessToken, data, attach, done) | 251 | makePostRequest(path, server.accessToken, data, attach, done) |
241 | }) | 252 | }) |
242 | 253 | ||
243 | it('Should fail without an input file', function (done) { | 254 | it('Should fail without tags', function (done) { |
244 | const data = { | 255 | const data = { |
245 | name: 'my super name', | 256 | name: 'my super name', |
246 | description: 'my super description' | 257 | description: 'my super description' |
247 | } | 258 | } |
259 | const attach = { | ||
260 | 'videofile': pathUtils.join(__dirname, 'fixtures', 'video_short.webm') | ||
261 | } | ||
262 | makePostRequest(path, server.accessToken, data, attach, done) | ||
263 | }) | ||
264 | |||
265 | it('Should fail with too many tags', function (done) { | ||
266 | const data = { | ||
267 | name: 'my super name', | ||
268 | description: 'my super description', | ||
269 | tags: [ 'tag1', 'tag2', 'tag3', 'tag4' ] | ||
270 | } | ||
271 | const attach = { | ||
272 | 'videofile': pathUtils.join(__dirname, 'fixtures', 'video_short.webm') | ||
273 | } | ||
274 | makePostRequest(path, server.accessToken, data, attach, done) | ||
275 | }) | ||
276 | |||
277 | it('Should fail with not enough tags', function (done) { | ||
278 | const data = { | ||
279 | name: 'my super name', | ||
280 | description: 'my super description', | ||
281 | tags: [ ] | ||
282 | } | ||
283 | const attach = { | ||
284 | 'videofile': pathUtils.join(__dirname, 'fixtures', 'video_short.webm') | ||
285 | } | ||
286 | makePostRequest(path, server.accessToken, data, attach, done) | ||
287 | }) | ||
288 | |||
289 | it('Should fail with a tag length too low', function (done) { | ||
290 | const data = { | ||
291 | name: 'my super name', | ||
292 | description: 'my super description', | ||
293 | tags: [ 'tag1', 't' ] | ||
294 | } | ||
295 | const attach = { | ||
296 | 'videofile': pathUtils.join(__dirname, 'fixtures', 'video_short.webm') | ||
297 | } | ||
298 | makePostRequest(path, server.accessToken, data, attach, done) | ||
299 | }) | ||
300 | |||
301 | it('Should fail with a tag length too big', function (done) { | ||
302 | const data = { | ||
303 | name: 'my super name', | ||
304 | description: 'my super description', | ||
305 | tags: [ 'mysupertagtoolong', 'tag1' ] | ||
306 | } | ||
307 | const attach = { | ||
308 | 'videofile': pathUtils.join(__dirname, 'fixtures', 'video_short.webm') | ||
309 | } | ||
310 | makePostRequest(path, server.accessToken, data, attach, done) | ||
311 | }) | ||
312 | |||
313 | it('Should fail with malformed tags', function (done) { | ||
314 | const data = { | ||
315 | name: 'my super name', | ||
316 | description: 'my super description', | ||
317 | tags: [ 'my tag' ] | ||
318 | } | ||
319 | const attach = { | ||
320 | 'videofile': pathUtils.join(__dirname, 'fixtures', 'video_short.webm') | ||
321 | } | ||
322 | makePostRequest(path, server.accessToken, data, attach, done) | ||
323 | }) | ||
324 | |||
325 | it('Should fail without an input file', function (done) { | ||
326 | const data = { | ||
327 | name: 'my super name', | ||
328 | description: 'my super description', | ||
329 | tags: [ 'tag1', 'tag2' ] | ||
330 | } | ||
248 | const attach = {} | 331 | const attach = {} |
249 | makePostRequest(path, server.accessToken, data, attach, done) | 332 | makePostRequest(path, server.accessToken, data, attach, done) |
250 | }) | 333 | }) |
@@ -252,7 +335,8 @@ describe('Test parameters validator', function () { | |||
252 | it('Should fail without an incorrect input file', function (done) { | 335 | it('Should fail without an incorrect input file', function (done) { |
253 | const data = { | 336 | const data = { |
254 | name: 'my super name', | 337 | name: 'my super name', |
255 | description: 'my super description' | 338 | description: 'my super description', |
339 | tags: [ 'tag1', 'tag2' ] | ||
256 | } | 340 | } |
257 | const attach = { | 341 | const attach = { |
258 | 'videofile': pathUtils.join(__dirname, 'fixtures', 'video_short_fake.webm') | 342 | 'videofile': pathUtils.join(__dirname, 'fixtures', 'video_short_fake.webm') |
@@ -263,7 +347,8 @@ describe('Test parameters validator', function () { | |||
263 | it('Should fail with a too big duration', function (done) { | 347 | it('Should fail with a too big duration', function (done) { |
264 | const data = { | 348 | const data = { |
265 | name: 'my super name', | 349 | name: 'my super name', |
266 | description: 'my super description' | 350 | description: 'my super description', |
351 | tags: [ 'tag1', 'tag2' ] | ||
267 | } | 352 | } |
268 | const attach = { | 353 | const attach = { |
269 | 'videofile': pathUtils.join(__dirname, 'fixtures', 'video_too_long.webm') | 354 | 'videofile': pathUtils.join(__dirname, 'fixtures', 'video_too_long.webm') |
@@ -274,7 +359,8 @@ describe('Test parameters validator', function () { | |||
274 | it('Should succeed with the correct parameters', function (done) { | 359 | it('Should succeed with the correct parameters', function (done) { |
275 | const data = { | 360 | const data = { |
276 | name: 'my super name', | 361 | name: 'my super name', |
277 | description: 'my super description' | 362 | description: 'my super description', |
363 | tags: [ 'tag1', 'tag2' ] | ||
278 | } | 364 | } |
279 | const attach = { | 365 | const attach = { |
280 | 'videofile': pathUtils.join(__dirname, 'fixtures', 'video_short.webm') | 366 | 'videofile': pathUtils.join(__dirname, 'fixtures', 'video_short.webm') |