const request = require('supertest')
const videosUtils = {
+ getVideoCategories,
+ getVideoLicences,
getAllVideosListBy,
getVideo,
getVideosList,
searchVideoWithSort,
testVideoImage,
uploadVideo,
- updateVideo
+ 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'
.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) {
.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) {
}
}
-function uploadVideo (url, accessToken, name, description, tags, fixture, specialStatus, end) {
+function uploadVideo (url, accessToken, videoAttributesArg, specialStatus, end) {
if (!end) {
end = specialStatus
specialStatus = 204
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)
.end(end)
}
-function updateVideo (url, accessToken, id, name, description, tags, specialStatus, end) {
+function updateVideo (url, accessToken, id, attributes, specialStatus, end) {
if (!end) {
end = specialStatus
specialStatus = 204
.set('Accept', 'application/json')
.set('Authorization', 'Bearer ' + accessToken)
- if (name) req.field('name', name)
- if (description) req.field('description', description)
+ 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 (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])
}
}
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