mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2025-02-25 18:55:32 -06:00
Server: add ability to update a video
This commit is contained in:
@@ -10,6 +10,7 @@ const loginUtils = require('../utils/login')
|
||||
const requestsUtils = require('../utils/requests')
|
||||
const serversUtils = require('../utils/servers')
|
||||
const usersUtils = require('../utils/users')
|
||||
const videosUtils = require('../utils/videos')
|
||||
|
||||
describe('Test parameters validator', function () {
|
||||
let server = null
|
||||
@@ -439,6 +440,106 @@ describe('Test parameters validator', function () {
|
||||
})
|
||||
})
|
||||
|
||||
describe('When updating a video', function () {
|
||||
let videoId
|
||||
|
||||
before(function (done) {
|
||||
videosUtils.getVideosList(server.url, function (err, res) {
|
||||
if (err) throw err
|
||||
|
||||
videoId = res.body.data[0].id
|
||||
|
||||
return done()
|
||||
})
|
||||
})
|
||||
|
||||
it('Should fail with nothing', function (done) {
|
||||
const data = {}
|
||||
requestsUtils.makePutBodyRequest(server.url, path + videoId, server.accessToken, data, done)
|
||||
})
|
||||
|
||||
it('Should fail without a valid uuid', function (done) {
|
||||
const data = {
|
||||
description: 'my super description',
|
||||
tags: [ 'tag1', 'tag2' ]
|
||||
}
|
||||
requestsUtils.makePutBodyRequest(server.url, path + 'blabla', server.accessToken, data, done)
|
||||
})
|
||||
|
||||
it('Should fail with an unknown id', function (done) {
|
||||
const data = {
|
||||
description: 'my super description',
|
||||
tags: [ 'tag1', 'tag2' ]
|
||||
}
|
||||
requestsUtils.makePutBodyRequest(server.url, path + '4da6fde3-88f7-4d16-b119-108df5630b06', server.accessToken, data, done)
|
||||
})
|
||||
|
||||
it('Should fail with a long name', function (done) {
|
||||
const data = {
|
||||
name: 'My very very very very very very very very very very very very very very very very long name',
|
||||
description: 'my super description',
|
||||
tags: [ 'tag1', 'tag2' ]
|
||||
}
|
||||
requestsUtils.makePutBodyRequest(server.url, path + videoId, server.accessToken, data, done)
|
||||
})
|
||||
|
||||
it('Should fail with a long description', function (done) {
|
||||
const data = {
|
||||
name: 'my super name',
|
||||
description: 'my super description which is very very very very very very very very very very very very very very' +
|
||||
'very very very very very very very very very very very very very very very very very very very very very' +
|
||||
'very very very very very very very very very very very very very very very long',
|
||||
tags: [ 'tag1', 'tag2' ]
|
||||
}
|
||||
requestsUtils.makePutBodyRequest(server.url, path + videoId, server.accessToken, data, done)
|
||||
})
|
||||
|
||||
it('Should fail with too many tags', function (done) {
|
||||
const data = {
|
||||
name: 'my super name',
|
||||
description: 'my super description',
|
||||
tags: [ 'tag1', 'tag2', 'tag3', 'tag4' ]
|
||||
}
|
||||
requestsUtils.makePutBodyRequest(server.url, path + videoId, server.accessToken, data, done)
|
||||
})
|
||||
|
||||
it('Should fail with not enough tags', function (done) {
|
||||
const data = {
|
||||
name: 'my super name',
|
||||
description: 'my super description',
|
||||
tags: [ ]
|
||||
}
|
||||
requestsUtils.makePutBodyRequest(server.url, path + videoId, server.accessToken, data, done)
|
||||
})
|
||||
|
||||
it('Should fail with a tag length too low', function (done) {
|
||||
const data = {
|
||||
name: 'my super name',
|
||||
description: 'my super description',
|
||||
tags: [ 'tag1', 't' ]
|
||||
}
|
||||
requestsUtils.makePutBodyRequest(server.url, path + videoId, server.accessToken, data, done)
|
||||
})
|
||||
|
||||
it('Should fail with a tag length too big', function (done) {
|
||||
const data = {
|
||||
name: 'my super name',
|
||||
description: 'my super description',
|
||||
tags: [ 'mysupertagtoolong', 'tag1' ]
|
||||
}
|
||||
requestsUtils.makePutBodyRequest(server.url, path + videoId, server.accessToken, data, done)
|
||||
})
|
||||
|
||||
it('Should fail with malformed tags', function (done) {
|
||||
const data = {
|
||||
name: 'my super name',
|
||||
description: 'my super description',
|
||||
tags: [ 'my tag' ]
|
||||
}
|
||||
requestsUtils.makePutBodyRequest(server.url, path + videoId, server.accessToken, data, done)
|
||||
})
|
||||
})
|
||||
|
||||
describe('When getting a video', function () {
|
||||
it('Should return the list of the videos with nothing', function (done) {
|
||||
request(server.url)
|
||||
|
||||
@@ -495,10 +495,86 @@ describe('Test a single pod', function () {
|
||||
expect(videos[2].name === 'video_short2.webm name')
|
||||
expect(videos[3].name === 'video_short3.webm name')
|
||||
|
||||
videoId = videos[3].id
|
||||
|
||||
done()
|
||||
})
|
||||
})
|
||||
|
||||
it('Should update a video', function (done) {
|
||||
const name = 'my super video updated'
|
||||
const description = 'my super description updated'
|
||||
const tags = [ 'tagup1', 'tagup2' ]
|
||||
|
||||
videosUtils.updateVideo(server.url, server.accessToken, videoId, name, description, tags, done)
|
||||
})
|
||||
|
||||
it('Should have the video updated', function (done) {
|
||||
videosUtils.getVideo(server.url, videoId, function (err, res) {
|
||||
if (err) throw err
|
||||
|
||||
const video = res.body
|
||||
|
||||
expect(video.name).to.equal('my super video updated')
|
||||
expect(video.description).to.equal('my super description updated')
|
||||
expect(video.podHost).to.equal('localhost:9001')
|
||||
expect(video.author).to.equal('root')
|
||||
expect(video.isLocal).to.be.true
|
||||
expect(video.tags).to.deep.equal([ 'tagup1', 'tagup2' ])
|
||||
expect(miscsUtils.dateIsValid(video.createdAt)).to.be.true
|
||||
|
||||
done()
|
||||
})
|
||||
})
|
||||
|
||||
it('Should update only the tags of a video', function (done) {
|
||||
const tags = [ 'tag1', 'tag2', 'supertag' ]
|
||||
|
||||
videosUtils.updateVideo(server.url, server.accessToken, videoId, null, null, tags, function (err) {
|
||||
if (err) throw err
|
||||
|
||||
videosUtils.getVideo(server.url, videoId, function (err, res) {
|
||||
if (err) throw err
|
||||
|
||||
const video = res.body
|
||||
|
||||
expect(video.name).to.equal('my super video updated')
|
||||
expect(video.description).to.equal('my super description updated')
|
||||
expect(video.podHost).to.equal('localhost:9001')
|
||||
expect(video.author).to.equal('root')
|
||||
expect(video.isLocal).to.be.true
|
||||
expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'supertag' ])
|
||||
expect(miscsUtils.dateIsValid(video.createdAt)).to.be.true
|
||||
|
||||
done()
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
it('Should update only the description of a video', function (done) {
|
||||
const description = 'hello everybody'
|
||||
|
||||
videosUtils.updateVideo(server.url, server.accessToken, videoId, null, description, null, function (err) {
|
||||
if (err) throw err
|
||||
|
||||
videosUtils.getVideo(server.url, videoId, function (err, res) {
|
||||
if (err) throw err
|
||||
|
||||
const video = res.body
|
||||
|
||||
expect(video.name).to.equal('my super video updated')
|
||||
expect(video.description).to.equal('hello everybody')
|
||||
expect(video.podHost).to.equal('localhost:9001')
|
||||
expect(video.author).to.equal('root')
|
||||
expect(video.isLocal).to.be.true
|
||||
expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'supertag' ])
|
||||
expect(miscsUtils.dateIsValid(video.createdAt)).to.be.true
|
||||
|
||||
done()
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
after(function (done) {
|
||||
process.kill(-server.app.pid)
|
||||
|
||||
|
||||
@@ -15,7 +15,8 @@ const videosUtils = {
|
||||
searchVideoWithPagination,
|
||||
searchVideoWithSort,
|
||||
testVideoImage,
|
||||
uploadVideo
|
||||
uploadVideo,
|
||||
updateVideo
|
||||
}
|
||||
|
||||
// ---------------------- Export functions --------------------
|
||||
@@ -194,6 +195,31 @@ function uploadVideo (url, accessToken, name, description, tags, fixture, specia
|
||||
.end(end)
|
||||
}
|
||||
|
||||
function updateVideo (url, accessToken, id, name, description, tags, 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 (name) req.field('name', name)
|
||||
if (description) req.field('description', description)
|
||||
|
||||
if (tags) {
|
||||
for (let i = 0; i < tags.length; i++) {
|
||||
req.field('tags[' + i + ']', tags[i])
|
||||
}
|
||||
}
|
||||
|
||||
req.expect(specialStatus).end(end)
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
module.exports = videosUtils
|
||||
|
||||
Reference in New Issue
Block a user