X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Ftests%2Futils%2Fvideos.js;h=d1e0b7b14e5ad8ba50efd1e29dc86b5345bb34b8;hb=d07137b90b2b2b0c1e93a6f0e7bf8719b133027c;hp=5c120597f0ac1dc762a196259139d945c8706fd9;hpb=feb4bdfd9b46e87aadfa7c0d5338cde887d1f58c;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/tests/utils/videos.js b/server/tests/utils/videos.js index 5c120597f..d1e0b7b14 100644 --- a/server/tests/utils/videos.js +++ b/server/tests/utils/videos.js @@ -5,6 +5,8 @@ const pathUtils = require('path') const request = require('supertest') const videosUtils = { + getVideoCategories, + getVideoLicences, getAllVideosListBy, getVideo, getVideosList, @@ -15,11 +17,35 @@ const videosUtils = { searchVideoWithPagination, searchVideoWithSort, testVideoImage, - uploadVideo + uploadVideo, + updateVideo, + rateVideo } // ---------------------- Export functions -------------------- +function getVideoCategories (url, end) { + const path = '/api/v1/videos/categories' + + request(url) + .get(path) + .set('Accept', 'application/json') + .expect(200) + .expect('Content-Type', /json/) + .end(end) +} + +function getVideoLicences (url, end) { + const path = '/api/v1/videos/licences' + + request(url) + .get(path) + .set('Accept', 'application/json') + .expect(200) + .expect('Content-Type', /json/) + .end(end) +} + function getAllVideosListBy (url, end) { const path = '/api/v1/videos' @@ -57,17 +83,25 @@ function getVideosList (url, end) { .end(end) } -function getVideosListPagination (url, start, count, end) { +function getVideosListPagination (url, start, count, sort, end) { + if (!end) { + end = sort + sort = null + } + const path = '/api/v1/videos' - request(url) - .get(path) - .query({ start: start }) - .query({ count: count }) - .set('Accept', 'application/json') - .expect(200) - .expect('Content-Type', /json/) - .end(end) + const req = request(url) + .get(path) + .query({ start: start }) + .query({ count: count }) + + if (sort) req.query({ sort }) + + req.set('Accept', 'application/json') + .expect(200) + .expect('Content-Type', /json/) + .end(end) } function getVideosListSort (url, sort, end) { @@ -115,18 +149,26 @@ function searchVideo (url, search, field, end) { .end(end) } -function searchVideoWithPagination (url, search, field, start, count, end) { +function searchVideoWithPagination (url, search, field, start, count, sort, end) { + if (!end) { + end = sort + sort = null + } + const path = '/api/v1/videos' - request(url) - .get(path + '/search/' + search) - .query({ start: start }) - .query({ count: count }) - .query({ field: field }) - .set('Accept', 'application/json') - .expect(200) - .expect('Content-Type', /json/) - .end(end) + const req = request(url) + .get(path + '/search/' + search) + .query({ start: start }) + .query({ count: count }) + .query({ field: field }) + + if (sort) req.query({ sort }) + + req.set('Accept', 'application/json') + .expect(200) + .expect('Content-Type', /json/) + .end(end) } function searchVideoWithSort (url, search, sort, end) { @@ -163,7 +205,7 @@ function testVideoImage (url, videoName, imagePath, callback) { } } -function uploadVideo (url, accessToken, name, description, tags, fixture, specialStatus, end) { +function uploadVideo (url, accessToken, videoAttributesArg, specialStatus, end) { if (!end) { end = specialStatus specialStatus = 204 @@ -171,22 +213,35 @@ function uploadVideo (url, accessToken, name, description, tags, fixture, specia const path = '/api/v1/videos' + // Default attributes + let attributes = { + name: 'my super video', + category: 5, + licence: 4, + 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('description', description) + .field('name', attributes.name) + .field('category', attributes.category) + .field('licence', attributes.licence) + .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) @@ -194,6 +249,50 @@ function uploadVideo (url, accessToken, name, description, tags, fixture, specia .end(end) } +function updateVideo (url, accessToken, id, attributes, specialStatus, end) { + if (!end) { + end = specialStatus + specialStatus = 204 + } + + const path = '/api/v1/videos/' + id + + const req = request(url) + .put(path) + .set('Accept', 'application/json') + .set('Authorization', 'Bearer ' + accessToken) + + if (attributes.name) req.field('name', attributes.name) + if (attributes.category) req.field('category', attributes.category) + if (attributes.licence) req.field('licence', attributes.licence) + if (attributes.description) req.field('description', attributes.description) + + if (attributes.tags) { + for (let i = 0; i < attributes.tags.length; i++) { + req.field('tags[' + i + ']', attributes.tags[i]) + } + } + + req.expect(specialStatus).end(end) +} + +function rateVideo (url, accessToken, id, rating, specialStatus, end) { + if (!end) { + end = specialStatus + specialStatus = 204 + } + + const path = '/api/v1/videos/' + id + '/rate' + + request(url) + .put(path) + .set('Accept', 'application/json') + .set('Authorization', 'Bearer ' + accessToken) + .send({ rating }) + .expect(specialStatus) + .end(end) +} + // --------------------------------------------------------------------------- module.exports = videosUtils