Server: refractoring upload/update video test utils
This commit is contained in:
parent
f6e692f5ee
commit
b4c5ac97ff
|
@ -50,12 +50,8 @@ describe('Test users API validators', function () {
|
||||||
usersUtils.createUser(server.url, server.accessToken, username, password, next)
|
usersUtils.createUser(server.url, server.accessToken, username, password, next)
|
||||||
},
|
},
|
||||||
function (next) {
|
function (next) {
|
||||||
const name = 'my super name for pod'
|
const videoAttributes = {}
|
||||||
const category = 5
|
videosUtils.uploadVideo(server.url, server.accessToken, videoAttributes, next)
|
||||||
const description = 'my super description for pod'
|
|
||||||
const tags = [ 'tag' ]
|
|
||||||
const file = 'video_short2.webm'
|
|
||||||
videosUtils.uploadVideo(server.url, server.accessToken, name, category, description, tags, file, next)
|
|
||||||
},
|
},
|
||||||
function (next) {
|
function (next) {
|
||||||
videosUtils.getVideosList(server.url, function (err, res) {
|
videosUtils.getVideosList(server.url, function (err, res) {
|
||||||
|
|
|
@ -61,12 +61,8 @@ describe('Test video abuses API validators', function () {
|
||||||
},
|
},
|
||||||
// Upload some videos on each pods
|
// Upload some videos on each pods
|
||||||
function (next) {
|
function (next) {
|
||||||
const name = 'my super name for pod'
|
const videoAttributes = {}
|
||||||
const category = 2
|
videosUtils.uploadVideo(server.url, server.accessToken, videoAttributes, next)
|
||||||
const description = 'my super description for pod'
|
|
||||||
const tags = [ 'tag' ]
|
|
||||||
const file = 'video_short2.webm'
|
|
||||||
videosUtils.uploadVideo(server.url, server.accessToken, name, category, description, tags, file, next)
|
|
||||||
},
|
},
|
||||||
function (next) {
|
function (next) {
|
||||||
videosUtils.getVideosList(server.url, function (err, res) {
|
videosUtils.getVideosList(server.url, function (err, res) {
|
||||||
|
|
|
@ -31,14 +31,12 @@ describe('Test advanced friends', function () {
|
||||||
}
|
}
|
||||||
|
|
||||||
function uploadVideo (podNumber, callback) {
|
function uploadVideo (podNumber, callback) {
|
||||||
const name = 'my super video'
|
const videoAttributes = {
|
||||||
const category = 5
|
tags: [ 'tag1', 'tag2' ]
|
||||||
const description = 'my super description'
|
}
|
||||||
const tags = [ 'tag1', 'tag2' ]
|
|
||||||
const fixture = 'video_short.webm'
|
|
||||||
const server = servers[podNumber - 1]
|
const server = servers[podNumber - 1]
|
||||||
|
|
||||||
return videosUtils.uploadVideo(server.url, server.accessToken, name, category, description, tags, fixture, callback)
|
return videosUtils.uploadVideo(server.url, server.accessToken, videoAttributes, callback)
|
||||||
}
|
}
|
||||||
|
|
||||||
function getVideos (podNumber, callback) {
|
function getVideos (podNumber, callback) {
|
||||||
|
|
|
@ -7,4 +7,5 @@ require('./friends-basic')
|
||||||
require('./users')
|
require('./users')
|
||||||
require('./single-pod')
|
require('./single-pod')
|
||||||
require('./multiple-pods')
|
require('./multiple-pods')
|
||||||
|
require('./requests')
|
||||||
require('./friends-advanced')
|
require('./friends-advanced')
|
||||||
|
|
|
@ -80,12 +80,13 @@ describe('Test multiple pods', function () {
|
||||||
|
|
||||||
series([
|
series([
|
||||||
function (next) {
|
function (next) {
|
||||||
const name = 'my super name for pod 1'
|
const videoAttributes = {
|
||||||
const category = 5
|
name: 'my super name for pod 1',
|
||||||
const description = 'my super description for pod 1'
|
description: 'my super description for pod 1',
|
||||||
const tags = [ 'tag1p1', 'tag2p1' ]
|
tags: [ 'tag1p1', 'tag2p1' ],
|
||||||
const file = 'video_short1.webm'
|
fixture: 'video_short1.webm'
|
||||||
videosUtils.uploadVideo(servers[0].url, servers[0].accessToken, name, category, description, tags, file, next)
|
}
|
||||||
|
videosUtils.uploadVideo(servers[0].url, servers[0].accessToken, videoAttributes, next)
|
||||||
},
|
},
|
||||||
function (next) {
|
function (next) {
|
||||||
setTimeout(next, 11000)
|
setTimeout(next, 11000)
|
||||||
|
@ -146,12 +147,14 @@ describe('Test multiple pods', function () {
|
||||||
|
|
||||||
series([
|
series([
|
||||||
function (next) {
|
function (next) {
|
||||||
const name = 'my super name for pod 2'
|
const videoAttributes = {
|
||||||
const category = 4
|
name: 'my super name for pod 2',
|
||||||
const description = 'my super description for pod 2'
|
category: 4,
|
||||||
const tags = [ 'tag1p2', 'tag2p2', 'tag3p2' ]
|
description: 'my super description for pod 2',
|
||||||
const file = 'video_short2.webm'
|
tags: [ 'tag1p2', 'tag2p2', 'tag3p2' ],
|
||||||
videosUtils.uploadVideo(servers[1].url, servers[1].accessToken, name, category, description, tags, file, next)
|
fixture: 'video_short2.webm'
|
||||||
|
}
|
||||||
|
videosUtils.uploadVideo(servers[1].url, servers[1].accessToken, videoAttributes, next)
|
||||||
},
|
},
|
||||||
function (next) {
|
function (next) {
|
||||||
setTimeout(next, 11000)
|
setTimeout(next, 11000)
|
||||||
|
@ -212,20 +215,24 @@ describe('Test multiple pods', function () {
|
||||||
|
|
||||||
series([
|
series([
|
||||||
function (next) {
|
function (next) {
|
||||||
const name = 'my super name for pod 3'
|
const videoAttributes = {
|
||||||
const category = 6
|
name: 'my super name for pod 3',
|
||||||
const description = 'my super description for pod 3'
|
category: 6,
|
||||||
const tags = [ 'tag1p3' ]
|
description: 'my super description for pod 3',
|
||||||
const file = 'video_short3.webm'
|
tags: [ 'tag1p3' ],
|
||||||
videosUtils.uploadVideo(servers[2].url, servers[2].accessToken, name, category, description, tags, file, next)
|
fixture: 'video_short3.webm'
|
||||||
|
}
|
||||||
|
videosUtils.uploadVideo(servers[2].url, servers[2].accessToken, videoAttributes, next)
|
||||||
},
|
},
|
||||||
function (next) {
|
function (next) {
|
||||||
const name = 'my super name for pod 3-2'
|
const videoAttributes = {
|
||||||
const category = 7
|
name: 'my super name for pod 3-2',
|
||||||
const description = 'my super description for pod 3-2'
|
category: 7,
|
||||||
const tags = [ 'tag2p3', 'tag3p3', 'tag4p3' ]
|
description: 'my super description for pod 3-2',
|
||||||
const file = 'video_short.webm'
|
tags: [ 'tag2p3', 'tag3p3', 'tag4p3' ],
|
||||||
videosUtils.uploadVideo(servers[2].url, servers[2].accessToken, name, category, description, tags, file, next)
|
fixture: 'video_short.webm'
|
||||||
|
}
|
||||||
|
videosUtils.uploadVideo(servers[2].url, servers[2].accessToken, videoAttributes, next)
|
||||||
},
|
},
|
||||||
function (next) {
|
function (next) {
|
||||||
setTimeout(next, 22000)
|
setTimeout(next, 22000)
|
||||||
|
@ -614,12 +621,13 @@ describe('Test multiple pods', function () {
|
||||||
it('Should update the video 3 by asking pod 3', function (done) {
|
it('Should update the video 3 by asking pod 3', function (done) {
|
||||||
this.timeout(15000)
|
this.timeout(15000)
|
||||||
|
|
||||||
const name = 'my super video updated'
|
const attributes = {
|
||||||
const category = 10
|
name: 'my super video updated',
|
||||||
const description = 'my super description updated'
|
category: 10,
|
||||||
const tags = [ 'tagup1', 'tagup2' ]
|
description: 'my super description updated',
|
||||||
|
tags: [ 'tagup1', 'tagup2' ]
|
||||||
videosUtils.updateVideo(servers[2].url, servers[2].accessToken, toRemove[0].id, name, category, description, tags, function (err) {
|
}
|
||||||
|
videosUtils.updateVideo(servers[2].url, servers[2].accessToken, toRemove[0].id, attributes, function (err) {
|
||||||
if (err) throw err
|
if (err) throw err
|
||||||
|
|
||||||
setTimeout(done, 11000)
|
setTimeout(done, 11000)
|
||||||
|
|
|
@ -13,17 +13,16 @@ const serversUtils = require('../utils/servers')
|
||||||
const videosUtils = require('../utils/videos')
|
const videosUtils = require('../utils/videos')
|
||||||
|
|
||||||
describe('Test requests stats', function () {
|
describe('Test requests stats', function () {
|
||||||
|
const requestSchedulerNames = [ 'requestScheduler', 'requestVideoQaduScheduler', 'requestVideoEventScheduler' ]
|
||||||
const path = '/api/v1/requests/stats'
|
const path = '/api/v1/requests/stats'
|
||||||
let servers = []
|
let servers = []
|
||||||
|
|
||||||
function uploadVideo (server, callback) {
|
function uploadVideo (server, callback) {
|
||||||
const name = 'my super video'
|
const videoAttributes = {
|
||||||
const category = 5
|
tags: [ 'tag1', 'tag2' ]
|
||||||
const description = 'my super description'
|
}
|
||||||
const tags = [ 'tag1', 'tag2' ]
|
|
||||||
const fixture = 'video_short.webm'
|
|
||||||
|
|
||||||
videosUtils.uploadVideo(server.url, server.accessToken, name, category, description, tags, fixture, callback)
|
videosUtils.uploadVideo(server.url, server.accessToken, videoAttributes, callback)
|
||||||
}
|
}
|
||||||
|
|
||||||
function getRequestsStats (server, callback) {
|
function getRequestsStats (server, callback) {
|
||||||
|
@ -64,9 +63,13 @@ describe('Test requests stats', function () {
|
||||||
getRequestsStats(server, function (err, res) {
|
getRequestsStats(server, function (err, res) {
|
||||||
if (err) throw err
|
if (err) throw err
|
||||||
|
|
||||||
const body = res.body
|
const requestSchedulers = res.body
|
||||||
expect(body.remainingMilliSeconds).to.be.at.least(0)
|
for (const requestSchedulerName of requestSchedulerNames) {
|
||||||
expect(body.remainingMilliSeconds).to.be.at.most(10000)
|
const requestScheduler = requestSchedulers[requestSchedulerName]
|
||||||
|
|
||||||
|
expect(requestScheduler.remainingMilliSeconds).to.be.at.least(0)
|
||||||
|
expect(requestScheduler.remainingMilliSeconds).to.be.at.most(10000)
|
||||||
|
}
|
||||||
|
|
||||||
done()
|
done()
|
||||||
})
|
})
|
||||||
|
@ -86,8 +89,9 @@ describe('Test requests stats', function () {
|
||||||
getRequestsStats(server, function (err, res) {
|
getRequestsStats(server, function (err, res) {
|
||||||
if (err) throw err
|
if (err) throw err
|
||||||
|
|
||||||
const body = res.body
|
const requestSchedulers = res.body
|
||||||
expect(body.totalRequests).to.equal(1)
|
const requestScheduler = requestSchedulers.requestScheduler
|
||||||
|
expect(requestScheduler.totalRequests).to.equal(1)
|
||||||
|
|
||||||
done()
|
done()
|
||||||
})
|
})
|
||||||
|
|
|
@ -70,13 +70,12 @@ describe('Test a single pod', function () {
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Should upload the video', function (done) {
|
it('Should upload the video', function (done) {
|
||||||
this.timeout(5000)
|
const videoAttributes = {
|
||||||
const name = 'my super name'
|
name: 'my super name',
|
||||||
const description = 'my super description'
|
category: 2,
|
||||||
const category = 2
|
tags: [ 'tag1', 'tag2', 'tag3' ]
|
||||||
const tags = [ 'tag1', 'tag2', 'tag3' ]
|
}
|
||||||
const file = 'video_short.webm'
|
videosUtils.uploadVideo(server.url, server.accessToken, videoAttributes, done)
|
||||||
videosUtils.uploadVideo(server.url, server.accessToken, name, category, description, tags, file, done)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Should seed the uploaded video', function (done) {
|
it('Should seed the uploaded video', function (done) {
|
||||||
|
@ -321,12 +320,15 @@ describe('Test a single pod', function () {
|
||||||
'video_short1.webm', 'video_short2.webm', 'video_short3.webm'
|
'video_short1.webm', 'video_short2.webm', 'video_short3.webm'
|
||||||
]
|
]
|
||||||
each(videos, function (video, callbackEach) {
|
each(videos, function (video, callbackEach) {
|
||||||
const name = video + ' name'
|
const videoAttributes = {
|
||||||
const description = video + ' description'
|
name: video + ' name',
|
||||||
const category = 2
|
description: video + ' description',
|
||||||
const tags = [ 'tag1', 'tag2', 'tag3' ]
|
category: 2,
|
||||||
|
tags: [ 'tag1', 'tag2', 'tag3' ],
|
||||||
|
fixture: video
|
||||||
|
}
|
||||||
|
|
||||||
videosUtils.uploadVideo(server.url, server.accessToken, name, category, description, tags, video, callbackEach)
|
videosUtils.uploadVideo(server.url, server.accessToken, videoAttributes, callbackEach)
|
||||||
}, done)
|
}, done)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -543,12 +545,13 @@ describe('Test a single pod', function () {
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Should update a video', function (done) {
|
it('Should update a video', function (done) {
|
||||||
const name = 'my super video updated'
|
const attributes = {
|
||||||
const category = 4
|
name: 'my super video updated',
|
||||||
const description = 'my super description updated'
|
category: 4,
|
||||||
const tags = [ 'tagup1', 'tagup2' ]
|
description: 'my super description updated',
|
||||||
|
tags: [ 'tagup1', 'tagup2' ]
|
||||||
videosUtils.updateVideo(server.url, server.accessToken, videoId, name, category, description, tags, done)
|
}
|
||||||
|
videosUtils.updateVideo(server.url, server.accessToken, videoId, attributes, done)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Should have the video updated', function (done) {
|
it('Should have the video updated', function (done) {
|
||||||
|
@ -586,9 +589,11 @@ describe('Test a single pod', function () {
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Should update only the tags of a video', function (done) {
|
it('Should update only the tags of a video', function (done) {
|
||||||
const tags = [ 'tag1', 'tag2', 'supertag' ]
|
const attributes = {
|
||||||
|
tags: [ 'tag1', 'tag2', 'supertag' ]
|
||||||
|
}
|
||||||
|
|
||||||
videosUtils.updateVideo(server.url, server.accessToken, videoId, null, null, null, tags, function (err) {
|
videosUtils.updateVideo(server.url, server.accessToken, videoId, attributes, function (err) {
|
||||||
if (err) throw err
|
if (err) throw err
|
||||||
|
|
||||||
videosUtils.getVideo(server.url, videoId, function (err, res) {
|
videosUtils.getVideo(server.url, videoId, function (err, res) {
|
||||||
|
@ -613,9 +618,11 @@ describe('Test a single pod', function () {
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Should update only the description of a video', function (done) {
|
it('Should update only the description of a video', function (done) {
|
||||||
const description = 'hello everybody'
|
const attributes = {
|
||||||
|
description: 'hello everybody'
|
||||||
|
}
|
||||||
|
|
||||||
videosUtils.updateVideo(server.url, server.accessToken, videoId, null, null, description, null, function (err) {
|
videosUtils.updateVideo(server.url, server.accessToken, videoId, attributes, function (err) {
|
||||||
if (err) throw err
|
if (err) throw err
|
||||||
|
|
||||||
videosUtils.getVideo(server.url, videoId, function (err, res) {
|
videosUtils.getVideo(server.url, videoId, function (err, res) {
|
||||||
|
|
|
@ -85,12 +85,8 @@ describe('Test users', function () {
|
||||||
it('Should not be able to upload a video', function (done) {
|
it('Should not be able to upload a video', function (done) {
|
||||||
accessToken = 'mysupertoken'
|
accessToken = 'mysupertoken'
|
||||||
|
|
||||||
const name = 'my super name'
|
const videoAttributes = {}
|
||||||
const description = 'my super description'
|
videosUtils.uploadVideo(server.url, accessToken, videoAttributes, 401, done)
|
||||||
const category = 5
|
|
||||||
const tags = [ 'tag1', 'tag2' ]
|
|
||||||
const video = 'video_short.webm'
|
|
||||||
videosUtils.uploadVideo(server.url, accessToken, name, category, description, tags, video, 401, done)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Should not be able to make friends', function (done) {
|
it('Should not be able to make friends', function (done) {
|
||||||
|
@ -113,12 +109,8 @@ describe('Test users', function () {
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Should upload the video with the correct token', function (done) {
|
it('Should upload the video with the correct token', function (done) {
|
||||||
const name = 'my super name'
|
const videoAttributes = {}
|
||||||
const category = 5
|
videosUtils.uploadVideo(server.url, accessToken, videoAttributes, 204, function (err, res) {
|
||||||
const description = 'my super description'
|
|
||||||
const tags = [ 'tag1', 'tag2' ]
|
|
||||||
const video = 'video_short.webm'
|
|
||||||
videosUtils.uploadVideo(server.url, accessToken, name, category, description, tags, video, 204, function (err, res) {
|
|
||||||
if (err) throw err
|
if (err) throw err
|
||||||
|
|
||||||
videosUtils.getVideosList(server.url, function (err, res) {
|
videosUtils.getVideosList(server.url, function (err, res) {
|
||||||
|
@ -134,12 +126,8 @@ describe('Test users', function () {
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Should upload the video again with the correct token', function (done) {
|
it('Should upload the video again with the correct token', function (done) {
|
||||||
const name = 'my super name 2'
|
const videoAttributes = {}
|
||||||
const category = 5
|
videosUtils.uploadVideo(server.url, accessToken, videoAttributes, 204, done)
|
||||||
const description = 'my super description 2'
|
|
||||||
const tags = [ 'tag1' ]
|
|
||||||
const video = 'video_short.webm'
|
|
||||||
videosUtils.uploadVideo(server.url, accessToken, name, category, description, tags, video, 204, done)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Should retrieve a video rating', function (done) {
|
it('Should retrieve a video rating', function (done) {
|
||||||
|
@ -230,12 +218,8 @@ describe('Test users', function () {
|
||||||
it('Should be able to upload a video with this user', function (done) {
|
it('Should be able to upload a video with this user', function (done) {
|
||||||
this.timeout(5000)
|
this.timeout(5000)
|
||||||
|
|
||||||
const name = 'my super name'
|
const videoAttributes = {}
|
||||||
const category = 5
|
videosUtils.uploadVideo(server.url, accessTokenUser, videoAttributes, done)
|
||||||
const description = 'my super description'
|
|
||||||
const tags = [ 'tag1', 'tag2', 'tag3' ]
|
|
||||||
const file = 'video_short.webm'
|
|
||||||
videosUtils.uploadVideo(server.url, accessTokenUser, name, category, description, tags, file, done)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Should list all the users', function (done) {
|
it('Should list all the users', function (done) {
|
||||||
|
|
|
@ -45,20 +45,18 @@ describe('Test video abuses', function () {
|
||||||
},
|
},
|
||||||
// Upload some videos on each pods
|
// Upload some videos on each pods
|
||||||
function (next) {
|
function (next) {
|
||||||
const name = 'my super name for pod 1'
|
const videoAttributes = {
|
||||||
const category = 5
|
name: 'my super name for pod 1',
|
||||||
const description = 'my super description for pod 1'
|
description: 'my super description for pod 1'
|
||||||
const tags = [ 'tag' ]
|
}
|
||||||
const file = 'video_short2.webm'
|
videosUtils.uploadVideo(servers[0].url, servers[0].accessToken, videoAttributes, next)
|
||||||
videosUtils.uploadVideo(servers[0].url, servers[0].accessToken, name, category, description, tags, file, next)
|
|
||||||
},
|
},
|
||||||
function (next) {
|
function (next) {
|
||||||
const name = 'my super name for pod 2'
|
const videoAttributes = {
|
||||||
const category = 5
|
name: 'my super name for pod 2',
|
||||||
const description = 'my super description for pod 2'
|
description: 'my super description for pod 2'
|
||||||
const tags = [ 'tag' ]
|
}
|
||||||
const file = 'video_short2.webm'
|
videosUtils.uploadVideo(servers[1].url, servers[1].accessToken, videoAttributes, next)
|
||||||
videosUtils.uploadVideo(servers[1].url, servers[1].accessToken, name, category, description, tags, file, next)
|
|
||||||
},
|
},
|
||||||
// Wait videos propagation
|
// Wait videos propagation
|
||||||
function (next) {
|
function (next) {
|
||||||
|
|
|
@ -200,15 +200,16 @@ function exitServers (servers, callback) {
|
||||||
function upload (servers, numServer, callback) {
|
function upload (servers, numServer, callback) {
|
||||||
if (!callback) callback = function () {}
|
if (!callback) callback = function () {}
|
||||||
|
|
||||||
const name = Date.now() + ' name'
|
|
||||||
const category = 4
|
|
||||||
const description = Date.now() + ' description'
|
|
||||||
const tags = [ Date.now().toString().substring(0, 5) + 't1', Date.now().toString().substring(0, 5) + 't2' ]
|
|
||||||
const file = 'video_short1.webm'
|
|
||||||
|
|
||||||
console.log('Uploading video to server ' + numServer)
|
console.log('Uploading video to server ' + numServer)
|
||||||
|
|
||||||
videosUtils.uploadVideo(servers[numServer].url, servers[numServer].accessToken, name, category, description, tags, file, callback)
|
const videoAttributes = {
|
||||||
|
name: Date.now() + ' name',
|
||||||
|
category: 4,
|
||||||
|
description: Date.now() + ' description',
|
||||||
|
tags: [ Date.now().toString().substring(0, 5) + 't1', Date.now().toString().substring(0, 5) + 't2' ],
|
||||||
|
fixture: 'video_short1.webm'
|
||||||
|
}
|
||||||
|
videosUtils.uploadVideo(servers[numServer].url, servers[numServer].accessToken, videoAttributes, callback)
|
||||||
}
|
}
|
||||||
|
|
||||||
function update (servers, numServer, callback) {
|
function update (servers, numServer, callback) {
|
||||||
|
@ -221,13 +222,15 @@ function update (servers, numServer, callback) {
|
||||||
if (videos.length === 0) return callback()
|
if (videos.length === 0) return callback()
|
||||||
|
|
||||||
const toUpdate = videos[getRandomInt(0, videos.length)].id
|
const toUpdate = videos[getRandomInt(0, videos.length)].id
|
||||||
const name = Date.now() + ' name'
|
const attributes = {
|
||||||
const description = Date.now() + ' description'
|
name: Date.now() + ' name',
|
||||||
const tags = [ Date.now().toString().substring(0, 5) + 't1', Date.now().toString().substring(0, 5) + 't2' ]
|
description: Date.now() + ' description',
|
||||||
|
tags: [ Date.now().toString().substring(0, 5) + 't1', Date.now().toString().substring(0, 5) + 't2' ]
|
||||||
|
}
|
||||||
|
|
||||||
console.log('Updating video of server ' + numServer)
|
console.log('Updating video of server ' + numServer)
|
||||||
|
|
||||||
videosUtils.updateVideo(servers[numServer].url, servers[numServer].accessToken, toUpdate, name, description, tags, callback)
|
videosUtils.updateVideo(servers[numServer].url, servers[numServer].accessToken, toUpdate, attributes, callback)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -49,10 +49,17 @@ function list (val) {
|
||||||
return val.split(',')
|
return val.split(',')
|
||||||
}
|
}
|
||||||
|
|
||||||
function upload (url, accessToken, name, category, description, tags, file) {
|
function upload (url, accessToken, name, category, description, tags, fixture) {
|
||||||
console.log('Uploading %s video...', program.name)
|
console.log('Uploading %s video...', program.name)
|
||||||
|
|
||||||
utils.uploadVideo(url, accessToken, name, category, description, tags, file, function (err) {
|
const videoAttributes = {
|
||||||
|
name,
|
||||||
|
category,
|
||||||
|
description,
|
||||||
|
tags,
|
||||||
|
fixture
|
||||||
|
}
|
||||||
|
utils.uploadVideo(url, accessToken, videoAttributes, function (err) {
|
||||||
if (err) throw err
|
if (err) throw err
|
||||||
|
|
||||||
console.log('Video uploaded.')
|
console.log('Video uploaded.')
|
||||||
|
|
|
@ -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) {
|
if (!end) {
|
||||||
end = specialStatus
|
end = specialStatus
|
||||||
specialStatus = 204
|
specialStatus = 204
|
||||||
|
@ -201,23 +201,33 @@ function uploadVideo (url, accessToken, name, category, description, tags, fixtu
|
||||||
|
|
||||||
const path = '/api/v1/videos'
|
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)
|
const req = request(url)
|
||||||
.post(path)
|
.post(path)
|
||||||
.set('Accept', 'application/json')
|
.set('Accept', 'application/json')
|
||||||
.set('Authorization', 'Bearer ' + accessToken)
|
.set('Authorization', 'Bearer ' + accessToken)
|
||||||
.field('name', name)
|
.field('name', attributes.name)
|
||||||
.field('category', category)
|
.field('category', attributes.category)
|
||||||
.field('description', description)
|
.field('description', attributes.description)
|
||||||
|
|
||||||
for (let i = 0; i < tags.length; i++) {
|
for (let i = 0; i < attributes.tags.length; i++) {
|
||||||
req.field('tags[' + i + ']', tags[i])
|
req.field('tags[' + i + ']', attributes.tags[i])
|
||||||
}
|
}
|
||||||
|
|
||||||
let filepath = ''
|
let filepath = ''
|
||||||
if (pathUtils.isAbsolute(fixture)) {
|
if (pathUtils.isAbsolute(attributes.fixture)) {
|
||||||
filepath = fixture
|
filepath = attributes.fixture
|
||||||
} else {
|
} else {
|
||||||
filepath = pathUtils.join(__dirname, '..', 'api', 'fixtures', fixture)
|
filepath = pathUtils.join(__dirname, '..', 'api', 'fixtures', attributes.fixture)
|
||||||
}
|
}
|
||||||
|
|
||||||
req.attach('videofile', filepath)
|
req.attach('videofile', filepath)
|
||||||
|
@ -225,7 +235,7 @@ function uploadVideo (url, accessToken, name, category, description, tags, fixtu
|
||||||
.end(end)
|
.end(end)
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateVideo (url, accessToken, id, name, category, description, tags, specialStatus, end) {
|
function updateVideo (url, accessToken, id, attributes, specialStatus, end) {
|
||||||
if (!end) {
|
if (!end) {
|
||||||
end = specialStatus
|
end = specialStatus
|
||||||
specialStatus = 204
|
specialStatus = 204
|
||||||
|
@ -238,13 +248,13 @@ function updateVideo (url, accessToken, id, name, category, description, tags, s
|
||||||
.set('Accept', 'application/json')
|
.set('Accept', 'application/json')
|
||||||
.set('Authorization', 'Bearer ' + accessToken)
|
.set('Authorization', 'Bearer ' + accessToken)
|
||||||
|
|
||||||
if (name) req.field('name', name)
|
if (attributes.name) req.field('name', attributes.name)
|
||||||
if (category) req.field('category', category)
|
if (attributes.category) req.field('category', attributes.category)
|
||||||
if (description) req.field('description', description)
|
if (attributes.description) req.field('description', attributes.description)
|
||||||
|
|
||||||
if (tags) {
|
if (attributes.tags) {
|
||||||
for (let i = 0; i < tags.length; i++) {
|
for (let i = 0; i < attributes.tags.length; i++) {
|
||||||
req.field('tags[' + i + ']', tags[i])
|
req.field('tags[' + i + ']', attributes.tags[i])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue