From b4c5ac97ffa3e16f837b7e2d72291656eefac812 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Sun, 26 Mar 2017 18:39:01 +0200 Subject: Server: refractoring upload/update video test utils --- server/tests/utils/videos.js | 42 ++++++++++++++++++++++++++---------------- 1 file changed, 26 insertions(+), 16 deletions(-) (limited to 'server/tests/utils') diff --git a/server/tests/utils/videos.js b/server/tests/utils/videos.js index 0aa6ec5a8..ad0d74076 100644 --- a/server/tests/utils/videos.js +++ b/server/tests/utils/videos.js @@ -193,7 +193,7 @@ function testVideoImage (url, videoName, imagePath, callback) { } } -function uploadVideo (url, accessToken, name, category, description, tags, fixture, specialStatus, end) { +function uploadVideo (url, accessToken, videoAttributesArg, specialStatus, end) { if (!end) { end = specialStatus specialStatus = 204 @@ -201,23 +201,33 @@ function uploadVideo (url, accessToken, name, category, description, tags, fixtu const path = '/api/v1/videos' + // Default attributes + let attributes = { + name: 'my super video', + category: 5, + description: 'my super description', + tags: [ 'tag' ], + fixture: 'video_short.webm' + } + attributes = Object.assign(attributes, videoAttributesArg) + const req = request(url) .post(path) .set('Accept', 'application/json') .set('Authorization', 'Bearer ' + accessToken) - .field('name', name) - .field('category', category) - .field('description', description) + .field('name', attributes.name) + .field('category', attributes.category) + .field('description', attributes.description) - for (let i = 0; i < tags.length; i++) { - req.field('tags[' + i + ']', tags[i]) + for (let i = 0; i < attributes.tags.length; i++) { + req.field('tags[' + i + ']', attributes.tags[i]) } let filepath = '' - if (pathUtils.isAbsolute(fixture)) { - filepath = fixture + if (pathUtils.isAbsolute(attributes.fixture)) { + filepath = attributes.fixture } else { - filepath = pathUtils.join(__dirname, '..', 'api', 'fixtures', fixture) + filepath = pathUtils.join(__dirname, '..', 'api', 'fixtures', attributes.fixture) } req.attach('videofile', filepath) @@ -225,7 +235,7 @@ function uploadVideo (url, accessToken, name, category, description, tags, fixtu .end(end) } -function updateVideo (url, accessToken, id, name, category, description, tags, specialStatus, end) { +function updateVideo (url, accessToken, id, attributes, specialStatus, end) { if (!end) { end = specialStatus specialStatus = 204 @@ -238,13 +248,13 @@ function updateVideo (url, accessToken, id, name, category, description, tags, s .set('Accept', 'application/json') .set('Authorization', 'Bearer ' + accessToken) - if (name) req.field('name', name) - if (category) req.field('category', category) - if (description) req.field('description', description) + if (attributes.name) req.field('name', attributes.name) + if (attributes.category) req.field('category', attributes.category) + if (attributes.description) req.field('description', attributes.description) - if (tags) { - for (let i = 0; i < tags.length; i++) { - req.field('tags[' + i + ']', tags[i]) + if (attributes.tags) { + for (let i = 0; i < attributes.tags.length; i++) { + req.field('tags[' + i + ']', attributes.tags[i]) } } -- cgit v1.2.3