const request = require('supertest')
const series = require('async/series')
-const utils = require('./utils')
+const loginUtils = require('../utils/login')
+const serversUtils = require('../utils/servers')
+const usersUtils = require('../utils/users')
describe('Test parameters validator', function () {
let server = null
series([
function (next) {
- utils.flushTests(next)
+ serversUtils.flushTests(next)
},
function (next) {
- utils.runServer(1, function (server1) {
+ serversUtils.runServer(1, function (server1) {
server = server1
next()
})
},
function (next) {
- utils.loginAndGetAccessToken(server, function (err, token) {
+ loginUtils.loginAndGetAccessToken(server, function (err, token) {
if (err) throw err
server.accessToken = token
let userAccessToken = null
before(function (done) {
- utils.createUser(server.url, server.accessToken, 'user1', 'password', function () {
+ usersUtils.createUser(server.url, server.accessToken, 'user1', 'password', function () {
server.user = {
username: 'user1',
password: 'password'
}
- utils.loginAndGetAccessToken(server, function (err, accessToken) {
+ loginUtils.loginAndGetAccessToken(server, function (err, accessToken) {
if (err) throw err
userAccessToken = accessToken
password: 'my super password'
}
- utils.loginAndGetAccessToken(server, function (err, accessToken) {
+ loginUtils.loginAndGetAccessToken(server, function (err, accessToken) {
if (err) throw err
userAccessToken = accessToken
describe('When updating a user', function () {
before(function (done) {
- utils.getUsersList(server.url, function (err, res) {
+ usersUtils.getUsersList(server.url, function (err, res) {
if (err) throw err
userId = res.body.data[1].id
// Keep the logs if the test failed
if (this.ok) {
- utils.flushTests(done)
+ serversUtils.flushTests(done)
} else {
done()
}
const expect = chai.expect
const series = require('async/series')
-const utils = require('./utils')
+const loginUtils = require('../utils/login')
+const podsUtils = require('../utils/pods')
+const serversUtils = require('../utils/servers')
+const videosUtils = require('../utils/videos')
describe('Test advanced friends', function () {
let servers = []
function makeFriends (podNumber, callback) {
const server = servers[podNumber - 1]
- return utils.makeFriends(server.url, server.accessToken, callback)
+ return podsUtils.makeFriends(server.url, server.accessToken, callback)
}
function quitFriends (podNumber, callback) {
const server = servers[podNumber - 1]
- return utils.quitFriends(server.url, server.accessToken, callback)
+ return podsUtils.quitFriends(server.url, server.accessToken, callback)
}
function getFriendsList (podNumber, end) {
const server = servers[podNumber - 1]
- return utils.getFriendsList(server.url, end)
+ return podsUtils.getFriendsList(server.url, end)
}
function uploadVideo (podNumber, callback) {
const fixture = 'video_short.webm'
const server = servers[podNumber - 1]
- return utils.uploadVideo(server.url, server.accessToken, name, description, tags, fixture, callback)
+ return videosUtils.uploadVideo(server.url, server.accessToken, name, description, tags, fixture, callback)
}
function getVideos (podNumber, callback) {
- return utils.getVideosList(servers[podNumber - 1].url, callback)
+ return videosUtils.getVideosList(servers[podNumber - 1].url, callback)
}
// ---------------------------------------------------------------
before(function (done) {
this.timeout(30000)
- utils.flushAndRunMultipleServers(6, function (serversRun, urlsRun) {
+ serversUtils.flushAndRunMultipleServers(6, function (serversRun, urlsRun) {
servers = serversRun
each(servers, function (server, callbackEach) {
- utils.loginAndGetAccessToken(server, function (err, accessToken) {
+ loginUtils.loginAndGetAccessToken(server, function (err, accessToken) {
if (err) return callbackEach(err)
server.accessToken = accessToken
},
// Rerun server 4
function (next) {
- utils.runServer(4, function (server) {
+ serversUtils.runServer(4, function (server) {
servers[3].app = server.app
next()
})
})
if (this.ok) {
- utils.flushTests(done)
+ serversUtils.flushTests(done)
} else {
done()
}
const expect = chai.expect
const series = require('async/series')
-const utils = require('./utils')
+const loginUtils = require('../utils/login')
+const podsUtils = require('../utils/pods')
+const serversUtils = require('../utils/servers')
describe('Test basic friends', function () {
let servers = []
function makeFriends (podNumber, callback) {
const server = servers[podNumber - 1]
- return utils.makeFriends(server.url, server.accessToken, callback)
+ return podsUtils.makeFriends(server.url, server.accessToken, callback)
}
function testMadeFriends (servers, serverToTest, callback) {
friends.push(servers[i].url)
}
- utils.getFriendsList(serverToTest.url, function (err, res) {
+ podsUtils.getFriendsList(serverToTest.url, function (err, res) {
if (err) throw err
const result = res.body
before(function (done) {
this.timeout(20000)
- utils.flushAndRunMultipleServers(3, function (serversRun, urlsRun) {
+ serversUtils.flushAndRunMultipleServers(3, function (serversRun, urlsRun) {
servers = serversRun
each(servers, function (server, callbackEach) {
- utils.loginAndGetAccessToken(server, function (err, accessToken) {
+ loginUtils.loginAndGetAccessToken(server, function (err, accessToken) {
if (err) return callbackEach(err)
server.accessToken = accessToken
it('Should not have friends', function (done) {
each(servers, function (server, callback) {
- utils.getFriendsList(server.url, function (err, res) {
+ podsUtils.getFriendsList(server.url, function (err, res) {
if (err) throw err
const result = res.body
},
// The second pod should have the third as a friend
function (next) {
- utils.getFriendsList(servers[1].url, function (err, res) {
+ podsUtils.getFriendsList(servers[1].url, function (err, res) {
if (err) throw err
const result = res.body
},
// Same here, the third pod should have the second pod as a friend
function (next) {
- utils.getFriendsList(servers[2].url, function (err, res) {
+ podsUtils.getFriendsList(servers[2].url, function (err, res) {
if (err) throw err
const result = res.body
it('Should not be allowed to make friend again', function (done) {
const server = servers[1]
- utils.makeFriends(server.url, server.accessToken, 409, done)
+ podsUtils.makeFriends(server.url, server.accessToken, 409, done)
})
it('Should quit friends of pod 2', function (done) {
// Pod 1 quit friends
function (next) {
const server = servers[1]
- utils.quitFriends(server.url, server.accessToken, next)
+ podsUtils.quitFriends(server.url, server.accessToken, next)
},
// Pod 1 should not have friends anymore
function (next) {
- utils.getFriendsList(servers[1].url, function (err, res) {
+ podsUtils.getFriendsList(servers[1].url, function (err, res) {
if (err) throw err
const result = res.body
// Other pods shouldn't have pod 1 too
function (next) {
each([ servers[0].url, servers[2].url ], function (url, callback) {
- utils.getFriendsList(url, function (err, res) {
+ podsUtils.getFriendsList(url, function (err, res) {
if (err) throw err
const result = res.body
it('Should allow pod 2 to make friend again', function (done) {
const server = servers[1]
- utils.makeFriends(server.url, server.accessToken, function () {
+ podsUtils.makeFriends(server.url, server.accessToken, function () {
each(servers, function (server, callback) {
testMadeFriends(servers, server, callback)
}, done)
})
if (this.ok) {
- utils.flushTests(done)
+ serversUtils.flushTests(done)
} else {
done()
}
const pathUtils = require('path')
const series = require('async/series')
-const utils = require('./utils')
+const loginUtils = require('../utils/login')
+const miscsUtils = require('../utils/miscs')
+const podsUtils = require('../utils/pods')
+const serversUtils = require('../utils/servers')
+const videosUtils = require('../utils/videos')
const webtorrent = require(pathUtils.join(__dirname, '../../lib/webtorrent'))
webtorrent.silent = true
series([
// Run servers
function (next) {
- utils.flushAndRunMultipleServers(3, function (serversRun) {
+ serversUtils.flushAndRunMultipleServers(3, function (serversRun) {
servers = serversRun
next()
})
// Get the access tokens
function (next) {
each(servers, function (server, callbackEach) {
- utils.loginAndGetAccessToken(server, function (err, accessToken) {
+ loginUtils.loginAndGetAccessToken(server, function (err, accessToken) {
if (err) return callbackEach(err)
server.accessToken = accessToken
// The second pod make friend with the third
function (next) {
const server = servers[1]
- utils.makeFriends(server.url, server.accessToken, next)
+ podsUtils.makeFriends(server.url, server.accessToken, next)
},
// Wait for the request between pods
function (next) {
// Pod 1 make friends too
function (next) {
const server = servers[0]
- utils.makeFriends(server.url, server.accessToken, next)
+ podsUtils.makeFriends(server.url, server.accessToken, next)
},
function (next) {
webtorrent.create({ host: 'client', port: '1' }, next)
it('Should not have videos for all pods', function (done) {
each(servers, function (server, callback) {
- utils.getVideosList(server.url, function (err, res) {
+ videosUtils.getVideosList(server.url, function (err, res) {
if (err) throw err
const videos = res.body.data
const description = 'my super description for pod 1'
const tags = [ 'tag1p1', 'tag2p1' ]
const file = 'video_short1.webm'
- utils.uploadVideo(servers[0].url, servers[0].accessToken, name, description, tags, file, next)
+ videosUtils.uploadVideo(servers[0].url, servers[0].accessToken, name, description, tags, file, next)
},
function (next) {
setTimeout(next, 11000)
each(servers, function (server, callback) {
let baseMagnet = null
- utils.getVideosList(server.url, function (err, res) {
+ videosUtils.getVideosList(server.url, function (err, res) {
if (err) throw err
const videos = res.body.data
expect(video.magnetUri).to.exist
expect(video.duration).to.equal(10)
expect(video.tags).to.deep.equal([ 'tag1p1', 'tag2p1' ])
- expect(utils.dateIsValid(video.createdDate)).to.be.true
+ expect(miscsUtils.dateIsValid(video.createdDate)).to.be.true
expect(video.author).to.equal('root')
if (server.url !== 'http://localhost:9001') {
expect(video.magnetUri).to.equal.magnetUri
}
- utils.testImage(server.url, 'video_short1.webm', video.thumbnailPath, function (err, test) {
+ videosUtils.testVideoImage(server.url, 'video_short1.webm', video.thumbnailPath, function (err, test) {
if (err) throw err
expect(test).to.equal(true)
const description = 'my super description for pod 2'
const tags = [ 'tag1p2', 'tag2p2', 'tag3p2' ]
const file = 'video_short2.webm'
- utils.uploadVideo(servers[1].url, servers[1].accessToken, name, description, tags, file, next)
+ videosUtils.uploadVideo(servers[1].url, servers[1].accessToken, name, description, tags, file, next)
},
function (next) {
setTimeout(next, 11000)
each(servers, function (server, callback) {
let baseMagnet = null
- utils.getVideosList(server.url, function (err, res) {
+ videosUtils.getVideosList(server.url, function (err, res) {
if (err) throw err
const videos = res.body.data
expect(video.magnetUri).to.exist
expect(video.duration).to.equal(5)
expect(video.tags).to.deep.equal([ 'tag1p2', 'tag2p2', 'tag3p2' ])
- expect(utils.dateIsValid(video.createdDate)).to.be.true
+ expect(miscsUtils.dateIsValid(video.createdDate)).to.be.true
expect(video.author).to.equal('root')
if (server.url !== 'http://localhost:9002') {
expect(video.magnetUri).to.equal.magnetUri
}
- utils.testImage(server.url, 'video_short2.webm', video.thumbnailPath, function (err, test) {
+ videosUtils.testVideoImage(server.url, 'video_short2.webm', video.thumbnailPath, function (err, test) {
if (err) throw err
expect(test).to.equal(true)
const description = 'my super description for pod 3'
const tags = [ 'tag1p3' ]
const file = 'video_short3.webm'
- utils.uploadVideo(servers[2].url, servers[2].accessToken, name, description, tags, file, next)
+ videosUtils.uploadVideo(servers[2].url, servers[2].accessToken, name, description, tags, file, next)
},
function (next) {
const name = 'my super name for pod 3-2'
const description = 'my super description for pod 3-2'
const tags = [ 'tag2p3', 'tag3p3', 'tag4p3' ]
const file = 'video_short.webm'
- utils.uploadVideo(servers[2].url, servers[2].accessToken, name, description, tags, file, next)
+ videosUtils.uploadVideo(servers[2].url, servers[2].accessToken, name, description, tags, file, next)
},
function (next) {
setTimeout(next, 22000)
let baseMagnet = null
// All pods should have this video
each(servers, function (server, callback) {
- utils.getVideosList(server.url, function (err, res) {
+ videosUtils.getVideosList(server.url, function (err, res) {
if (err) throw err
const videos = res.body.data
expect(video1.duration).to.equal(5)
expect(video1.tags).to.deep.equal([ 'tag1p3' ])
expect(video1.author).to.equal('root')
- expect(utils.dateIsValid(video1.createdDate)).to.be.true
+ expect(miscsUtils.dateIsValid(video1.createdDate)).to.be.true
expect(video2.name).to.equal('my super name for pod 3-2')
expect(video2.description).to.equal('my super description for pod 3-2')
expect(video2.duration).to.equal(5)
expect(video2.tags).to.deep.equal([ 'tag2p3', 'tag3p3', 'tag4p3' ])
expect(video2.author).to.equal('root')
- expect(utils.dateIsValid(video2.createdDate)).to.be.true
+ expect(miscsUtils.dateIsValid(video2.createdDate)).to.be.true
if (server.url !== 'http://localhost:9003') {
expect(video1.isLocal).to.be.false
expect(video2.magnetUri).to.equal.magnetUri
}
- utils.testImage(server.url, 'video_short3.webm', video1.thumbnailPath, function (err, test) {
+ videosUtils.testVideoImage(server.url, 'video_short3.webm', video1.thumbnailPath, function (err, test) {
if (err) throw err
expect(test).to.equal(true)
- utils.testImage(server.url, 'video_short.webm', video2.thumbnailPath, function (err, test) {
+ videosUtils.testVideoImage(server.url, 'video_short.webm', video2.thumbnailPath, function (err, test) {
if (err) throw err
expect(test).to.equal(true)
// Yes, this could be long
this.timeout(200000)
- utils.getVideosList(servers[2].url, function (err, res) {
+ videosUtils.getVideosList(servers[2].url, function (err, res) {
if (err) throw err
const video = res.body.data[0]
// Yes, this could be long
this.timeout(200000)
- utils.getVideosList(servers[0].url, function (err, res) {
+ videosUtils.getVideosList(servers[0].url, function (err, res) {
if (err) throw err
const video = res.body.data[1]
// Yes, this could be long
this.timeout(200000)
- utils.getVideosList(servers[1].url, function (err, res) {
+ videosUtils.getVideosList(servers[1].url, function (err, res) {
if (err) throw err
const video = res.body.data[2]
// Yes, this could be long
this.timeout(200000)
- utils.getVideosList(servers[0].url, function (err, res) {
+ videosUtils.getVideosList(servers[0].url, function (err, res) {
if (err) throw err
const video = res.body.data[3]
series([
function (next) {
- utils.removeVideo(servers[2].url, servers[2].accessToken, toRemove[0], next)
+ videosUtils.removeVideo(servers[2].url, servers[2].accessToken, toRemove[0], next)
},
function (next) {
- utils.removeVideo(servers[2].url, servers[2].accessToken, toRemove[1], next)
+ videosUtils.removeVideo(servers[2].url, servers[2].accessToken, toRemove[1], next)
}],
function (err) {
if (err) throw err
it('Should have videos 1 and 3 on each pod', function (done) {
each(servers, function (server, callback) {
- utils.getVideosList(server.url, function (err, res) {
+ videosUtils.getVideosList(server.url, function (err, res) {
if (err) throw err
const videos = res.body.data
// Keep the logs if the test failed
if (this.ok) {
- utils.flushTests(done)
+ serversUtils.flushTests(done)
} else {
done()
}
const pathUtils = require('path')
const series = require('async/series')
+const loginUtils = require('../utils/login')
+const miscsUtils = require('../utils/miscs')
+const serversUtils = require('../utils/servers')
+const videosUtils = require('../utils/videos')
const webtorrent = require(pathUtils.join(__dirname, '../../lib/webtorrent'))
webtorrent.silent = true
-const utils = require('./utils')
-
describe('Test a single pod', function () {
let server = null
let videoId = -1
series([
function (next) {
- utils.flushTests(next)
+ serversUtils.flushTests(next)
},
function (next) {
- utils.runServer(1, function (server1) {
+ serversUtils.runServer(1, function (server1) {
server = server1
next()
})
},
function (next) {
- utils.loginAndGetAccessToken(server, function (err, token) {
+ loginUtils.loginAndGetAccessToken(server, function (err, token) {
if (err) throw err
server.accessToken = token
next()
})
it('Should not have videos', function (done) {
- utils.getVideosList(server.url, function (err, res) {
+ videosUtils.getVideosList(server.url, function (err, res) {
if (err) throw err
expect(res.body.total).to.equal(0)
const description = 'my super description'
const tags = [ 'tag1', 'tag2', 'tag3' ]
const file = 'video_short.webm'
- utils.uploadVideo(server.url, server.accessToken, name, description, tags, file, done)
+ videosUtils.uploadVideo(server.url, server.accessToken, name, description, tags, file, done)
})
it('Should seed the uploaded video', function (done) {
// Yes, this could be long
this.timeout(60000)
- utils.getVideosList(server.url, function (err, res) {
+ videosUtils.getVideosList(server.url, function (err, res) {
if (err) throw err
expect(res.body.total).to.equal(1)
expect(video.author).to.equal('root')
expect(video.isLocal).to.be.true
expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ])
- expect(utils.dateIsValid(video.createdDate)).to.be.true
+ expect(miscsUtils.dateIsValid(video.createdDate)).to.be.true
- utils.testImage(server.url, 'video_short.webm', video.thumbnailPath, function (err, test) {
+ videosUtils.testVideoImage(server.url, 'video_short.webm', video.thumbnailPath, function (err, test) {
if (err) throw err
expect(test).to.equal(true)
// Yes, this could be long
this.timeout(60000)
- utils.getVideo(server.url, videoId, function (err, res) {
+ videosUtils.getVideo(server.url, videoId, function (err, res) {
if (err) throw err
const video = res.body
expect(video.author).to.equal('root')
expect(video.isLocal).to.be.true
expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ])
- expect(utils.dateIsValid(video.createdDate)).to.be.true
+ expect(miscsUtils.dateIsValid(video.createdDate)).to.be.true
- utils.testImage(server.url, 'video_short.webm', video.thumbnailPath, function (err, test) {
+ videosUtils.testVideoImage(server.url, 'video_short.webm', video.thumbnailPath, function (err, test) {
if (err) throw err
expect(test).to.equal(true)
})
it('Should search the video by name by default', function (done) {
- utils.searchVideo(server.url, 'my', function (err, res) {
+ videosUtils.searchVideo(server.url, 'my', function (err, res) {
if (err) throw err
expect(res.body.total).to.equal(1)
expect(video.author).to.equal('root')
expect(video.isLocal).to.be.true
expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ])
- expect(utils.dateIsValid(video.createdDate)).to.be.true
+ expect(miscsUtils.dateIsValid(video.createdDate)).to.be.true
- utils.testImage(server.url, 'video_short.webm', video.thumbnailPath, function (err, test) {
+ videosUtils.testVideoImage(server.url, 'video_short.webm', video.thumbnailPath, function (err, test) {
if (err) throw err
expect(test).to.equal(true)
})
it('Should search the video by podUrl', function (done) {
- utils.searchVideo(server.url, '9001', 'podUrl', function (err, res) {
+ videosUtils.searchVideo(server.url, '9001', 'podUrl', function (err, res) {
if (err) throw err
expect(res.body.total).to.equal(1)
expect(video.author).to.equal('root')
expect(video.isLocal).to.be.true
expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ])
- expect(utils.dateIsValid(video.createdDate)).to.be.true
+ expect(miscsUtils.dateIsValid(video.createdDate)).to.be.true
- utils.testImage(server.url, 'video_short.webm', video.thumbnailPath, function (err, test) {
+ videosUtils.testVideoImage(server.url, 'video_short.webm', video.thumbnailPath, function (err, test) {
if (err) throw err
expect(test).to.equal(true)
})
it('Should search the video by tag', function (done) {
- utils.searchVideo(server.url, 'tag1', 'tags', function (err, res) {
+ videosUtils.searchVideo(server.url, 'tag1', 'tags', function (err, res) {
if (err) throw err
expect(res.body.total).to.equal(1)
expect(video.author).to.equal('root')
expect(video.isLocal).to.be.true
expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ])
- expect(utils.dateIsValid(video.createdDate)).to.be.true
+ expect(miscsUtils.dateIsValid(video.createdDate)).to.be.true
- utils.testImage(server.url, 'video_short.webm', video.thumbnailPath, function (err, test) {
+ videosUtils.testVideoImage(server.url, 'video_short.webm', video.thumbnailPath, function (err, test) {
if (err) throw err
expect(test).to.equal(true)
})
it('Should not find a search by name by default', function (done) {
- utils.searchVideo(server.url, 'hello', function (err, res) {
+ videosUtils.searchVideo(server.url, 'hello', function (err, res) {
if (err) throw err
expect(res.body.total).to.equal(0)
})
it('Should not find a search by author', function (done) {
- utils.searchVideo(server.url, 'hello', 'author', function (err, res) {
+ videosUtils.searchVideo(server.url, 'hello', 'author', function (err, res) {
if (err) throw err
expect(res.body.total).to.equal(0)
})
it('Should not find a search by tag', function (done) {
- utils.searchVideo(server.url, 'tag', 'tags', function (err, res) {
+ videosUtils.searchVideo(server.url, 'tag', 'tags', function (err, res) {
if (err) throw err
expect(res.body.total).to.equal(0)
})
it('Should remove the video', function (done) {
- utils.removeVideo(server.url, server.accessToken, videoId, function (err) {
+ videosUtils.removeVideo(server.url, server.accessToken, videoId, function (err) {
if (err) throw err
fs.readdir(pathUtils.join(__dirname, '../../../test1/uploads/'), function (err, files) {
})
it('Should not have videos', function (done) {
- utils.getVideosList(server.url, function (err, res) {
+ videosUtils.getVideosList(server.url, function (err, res) {
if (err) throw err
expect(res.body.total).to.equal(0)
const description = video + ' description'
const tags = [ 'tag1', 'tag2', 'tag3' ]
- utils.uploadVideo(server.url, server.accessToken, name, description, tags, video, callbackEach)
+ videosUtils.uploadVideo(server.url, server.accessToken, name, description, tags, video, callbackEach)
}, done)
})
it('Should have the correct durations', function (done) {
- utils.getVideosList(server.url, function (err, res) {
+ videosUtils.getVideosList(server.url, function (err, res) {
if (err) throw err
expect(res.body.total).to.equal(6)
})
it('Should have the correct thumbnails', function (done) {
- utils.getVideosList(server.url, function (err, res) {
+ videosUtils.getVideosList(server.url, function (err, res) {
if (err) throw err
const videos = res.body.data
if (err) throw err
const videoName = video.name.replace(' name', '')
- utils.testImage(server.url, videoName, video.thumbnailPath, function (err, test) {
+ videosUtils.testVideoImage(server.url, videoName, video.thumbnailPath, function (err, test) {
if (err) throw err
expect(test).to.equal(true)
})
it('Should list only the two first videos', function (done) {
- utils.getVideosListPagination(server.url, 0, 2, function (err, res) {
+ videosUtils.getVideosListPagination(server.url, 0, 2, function (err, res) {
if (err) throw err
const videos = res.body.data
})
it('Should list only the next three videos', function (done) {
- utils.getVideosListPagination(server.url, 2, 3, function (err, res) {
+ videosUtils.getVideosListPagination(server.url, 2, 3, function (err, res) {
if (err) throw err
const videos = res.body.data
})
it('Should list the last video', function (done) {
- utils.getVideosListPagination(server.url, 5, 6, function (err, res) {
+ videosUtils.getVideosListPagination(server.url, 5, 6, function (err, res) {
if (err) throw err
const videos = res.body.data
})
it('Should search the first video', function (done) {
- utils.searchVideoWithPagination(server.url, 'webm', 'name', 0, 1, function (err, res) {
+ videosUtils.searchVideoWithPagination(server.url, 'webm', 'name', 0, 1, function (err, res) {
if (err) throw err
const videos = res.body.data
})
it('Should search the last two videos', function (done) {
- utils.searchVideoWithPagination(server.url, 'webm', 'name', 2, 2, function (err, res) {
+ videosUtils.searchVideoWithPagination(server.url, 'webm', 'name', 2, 2, function (err, res) {
if (err) throw err
const videos = res.body.data
})
it('Should search all the webm videos', function (done) {
- utils.searchVideoWithPagination(server.url, 'webm', 'name', 0, 15, function (err, res) {
+ videosUtils.searchVideoWithPagination(server.url, 'webm', 'name', 0, 15, function (err, res) {
if (err) throw err
const videos = res.body.data
})
it('Should search all the root author videos', function (done) {
- utils.searchVideoWithPagination(server.url, 'root', 'author', 0, 15, function (err, res) {
+ videosUtils.searchVideoWithPagination(server.url, 'root', 'author', 0, 15, function (err, res) {
if (err) throw err
const videos = res.body.data
})
it('Should search all the 9001 port videos', function (done) {
- utils.searchVideoWithPagination(server.url, '9001', 'podUrl', 0, 15, function (err, res) {
+ videosUtils.searchVideoWithPagination(server.url, '9001', 'podUrl', 0, 15, function (err, res) {
if (err) throw err
const videos = res.body.data
})
it('Should search all the localhost videos', function (done) {
- utils.searchVideoWithPagination(server.url, 'localhost', 'podUrl', 0, 15, function (err, res) {
+ videosUtils.searchVideoWithPagination(server.url, 'localhost', 'podUrl', 0, 15, function (err, res) {
if (err) throw err
const videos = res.body.data
it('Should search the good magnetUri video', function (done) {
const video = videosListBase[0]
- utils.searchVideoWithPagination(server.url, encodeURIComponent(video.magnetUri), 'magnetUri', 0, 15, function (err, res) {
+ videosUtils.searchVideoWithPagination(server.url, encodeURIComponent(video.magnetUri), 'magnetUri', 0, 15, function (err, res) {
if (err) throw err
const videos = res.body.data
})
it('Should list and sort by name in descending order', function (done) {
- utils.getVideosListSort(server.url, '-name', function (err, res) {
+ videosUtils.getVideosListSort(server.url, '-name', function (err, res) {
if (err) throw err
const videos = res.body.data
})
it('Should search and sort by name in ascending order', function (done) {
- utils.searchVideoWithSort(server.url, 'webm', 'name', function (err, res) {
+ videosUtils.searchVideoWithSort(server.url, 'webm', 'name', function (err, res) {
if (err) throw err
const videos = res.body.data
// Keep the logs if the test failed
if (this.ok) {
- utils.flushTests(done)
+ serversUtils.flushTests(done)
} else {
done()
}
const pathUtils = require('path')
const series = require('async/series')
+const loginUtils = require('../utils/login')
+const podsUtils = require('../utils/pods')
+const serversUtils = require('../utils/servers')
+const usersUtils = require('../utils/users')
+const videosUtils = require('../utils/videos')
const webtorrent = require(pathUtils.join(__dirname, '../../lib/webtorrent'))
webtorrent.silent = true
-const utils = require('./utils')
-
describe('Test users', function () {
let server = null
let accessToken = null
series([
function (next) {
- utils.flushTests(next)
+ serversUtils.flushTests(next)
},
function (next) {
- utils.runServer(1, function (server1) {
+ serversUtils.runServer(1, function (server1) {
server = server1
next()
})
it('Should not login with an invalid client id', function (done) {
const client = { id: 'client', password: server.client.secret }
- utils.login(server.url, client, server.user, 400, function (err, res) {
+ loginUtils.login(server.url, client, server.user, 400, function (err, res) {
if (err) throw err
expect(res.body.error).to.equal('invalid_client')
it('Should not login with an invalid client password', function (done) {
const client = { id: server.client.id, password: 'coucou' }
- utils.login(server.url, client, server.user, 400, function (err, res) {
+ loginUtils.login(server.url, client, server.user, 400, function (err, res) {
if (err) throw err
expect(res.body.error).to.equal('invalid_client')
it('Should not login with an invalid username', function (done) {
const user = { username: 'captain crochet', password: server.user.password }
- utils.login(server.url, server.client, user, 400, function (err, res) {
+ loginUtils.login(server.url, server.client, user, 400, function (err, res) {
if (err) throw err
expect(res.body.error).to.equal('invalid_grant')
it('Should not login with an invalid password', function (done) {
const user = { username: server.user.username, password: 'mewthree' }
- utils.login(server.url, server.client, user, 400, function (err, res) {
+ loginUtils.login(server.url, server.client, user, 400, function (err, res) {
if (err) throw err
expect(res.body.error).to.equal('invalid_grant')
const description = 'my super description'
const tags = [ 'tag1', 'tag2' ]
const video = 'video_short.webm'
- utils.uploadVideo(server.url, accessToken, name, description, tags, video, 401, done)
+ videosUtils.uploadVideo(server.url, accessToken, name, description, tags, video, 401, done)
})
it('Should not be able to make friends', function (done) {
accessToken = 'mysupertoken'
- utils.makeFriends(server.url, accessToken, 401, done)
+ podsUtils.makeFriends(server.url, accessToken, 401, done)
})
it('Should not be able to quit friends', function (done) {
accessToken = 'mysupertoken'
- utils.quitFriends(server.url, accessToken, 401, done)
+ podsUtils.quitFriends(server.url, accessToken, 401, done)
})
it('Should be able to login', function (done) {
- utils.login(server.url, server.client, server.user, 200, function (err, res) {
+ loginUtils.login(server.url, server.client, server.user, 200, function (err, res) {
if (err) throw err
accessToken = res.body.access_token
const description = 'my super description'
const tags = [ 'tag1', 'tag2' ]
const video = 'video_short.webm'
- utils.uploadVideo(server.url, accessToken, name, description, tags, video, 204, function (err, res) {
+ videosUtils.uploadVideo(server.url, accessToken, name, description, tags, video, 204, function (err, res) {
if (err) throw err
- utils.getVideosList(server.url, function (err, res) {
+ videosUtils.getVideosList(server.url, function (err, res) {
if (err) throw err
const video = res.body.data[0]
const description = 'my super description 2'
const tags = [ 'tag1' ]
const video = 'video_short.webm'
- utils.uploadVideo(server.url, accessToken, name, description, tags, video, 204, done)
+ videosUtils.uploadVideo(server.url, accessToken, name, description, tags, video, 204, done)
})
it('Should not be able to remove the video with an incorrect token', function (done) {
- utils.removeVideo(server.url, 'bad_token', videoId, 401, done)
+ videosUtils.removeVideo(server.url, 'bad_token', videoId, 401, done)
})
it('Should not be able to remove the video with the token of another account')
it('Should be able to remove the video with the correct token', function (done) {
- utils.removeVideo(server.url, accessToken, videoId, done)
+ videosUtils.removeVideo(server.url, accessToken, videoId, done)
})
it('Should logout (revoke token)')
it('Should be able to upload a video again')
it('Should be able to create a new user', function (done) {
- utils.createUser(server.url, accessToken, 'user_1', 'super password', done)
+ usersUtils.createUser(server.url, accessToken, 'user_1', 'super password', done)
})
it('Should be able to login with this user', function (done) {
password: 'super password'
}
- utils.loginAndGetAccessToken(server, function (err, token) {
+ loginUtils.loginAndGetAccessToken(server, function (err, token) {
if (err) throw err
accessTokenUser = token
})
it('Should be able to get the user informations', function (done) {
- utils.getUserInformation(server.url, accessTokenUser, function (err, res) {
+ usersUtils.getUserInformation(server.url, accessTokenUser, function (err, res) {
if (err) throw err
const user = res.body
const description = 'my super description'
const tags = [ 'tag1', 'tag2', 'tag3' ]
const file = 'video_short.webm'
- utils.uploadVideo(server.url, accessTokenUser, name, description, tags, file, done)
+ videosUtils.uploadVideo(server.url, accessTokenUser, name, description, tags, file, done)
})
it('Should list all the users', function (done) {
- utils.getUsersList(server.url, function (err, res) {
+ usersUtils.getUsersList(server.url, function (err, res) {
if (err) throw err
const users = res.body.data
})
it('Should update the user password', function (done) {
- utils.updateUser(server.url, userId, accessTokenUser, 'new password', function (err, res) {
+ usersUtils.updateUser(server.url, userId, accessTokenUser, 'new password', function (err, res) {
if (err) throw err
server.user.password = 'new password'
- utils.login(server.url, server.client, server.user, 200, done)
+ loginUtils.login(server.url, server.client, server.user, 200, done)
})
})
it('Should be able to remove this user', function (done) {
- utils.removeUser(server.url, accessToken, 'user_1', done)
+ usersUtils.removeUser(server.url, accessToken, 'user_1', done)
})
it('Should not be able to login with this user', function (done) {
// server.user is already set to user 1
- utils.login(server.url, server.client, server.user, 400, done)
+ loginUtils.login(server.url, server.client, server.user, 400, done)
})
it('Should not have videos of this user', function (done) {
- utils.getVideosList(server.url, function (err, res) {
+ videosUtils.getVideosList(server.url, function (err, res) {
if (err) throw err
expect(res.body.total).to.equal(1)
// Keep the logs if the test failed
if (this.ok) {
- utils.flushTests(done)
+ serversUtils.flushTests(done)
} else {
done()
}
+++ /dev/null
-'use strict'
-
-const childProcess = require('child_process')
-const exec = childProcess.exec
-const fork = childProcess.fork
-const fs = require('fs')
-const pathUtils = require('path')
-const request = require('supertest')
-
-const testUtils = {
- createUser: createUser,
- dateIsValid: dateIsValid,
- flushTests: flushTests,
- getAllVideosListBy: getAllVideosListBy,
- getClient: getClient,
- getFriendsList: getFriendsList,
- getUserInformation: getUserInformation,
- getUsersList: getUsersList,
- getVideo: getVideo,
- getVideosList: getVideosList,
- getVideosListPagination: getVideosListPagination,
- getVideosListSort: getVideosListSort,
- login: login,
- loginAndGetAccessToken: loginAndGetAccessToken,
- makeFriends: makeFriends,
- quitFriends: quitFriends,
- removeUser: removeUser,
- removeVideo: removeVideo,
- flushAndRunMultipleServers: flushAndRunMultipleServers,
- runServer: runServer,
- searchVideo: searchVideo,
- searchVideoWithPagination: searchVideoWithPagination,
- searchVideoWithSort: searchVideoWithSort,
- testImage: testImage,
- uploadVideo: uploadVideo,
- updateUser: updateUser
-}
-
-// ---------------------- Export functions --------------------
-
-function createUser (url, accessToken, username, password, specialStatus, end) {
- if (!end) {
- end = specialStatus
- specialStatus = 204
- }
-
- const path = '/api/v1/users'
-
- request(url)
- .post(path)
- .set('Accept', 'application/json')
- .set('Authorization', 'Bearer ' + accessToken)
- .send({ username: username, password: password })
- .expect(specialStatus)
- .end(end)
-}
-
-function dateIsValid (dateString) {
- const dateToCheck = new Date(dateString)
- const now = new Date()
-
- // Check if the interval is more than 2 minutes
- if (now - dateToCheck > 120000) return false
-
- return true
-}
-
-function flushTests (callback) {
- exec('npm run clean:server:test', callback)
-}
-
-function getAllVideosListBy (url, end) {
- const path = '/api/v1/videos'
-
- request(url)
- .get(path)
- .query({ sort: 'createdDate' })
- .query({ start: 0 })
- .query({ count: 10000 })
- .set('Accept', 'application/json')
- .expect(200)
- .expect('Content-Type', /json/)
- .end(end)
-}
-
-function getClient (url, end) {
- const path = '/api/v1/users/client'
-
- request(url)
- .get(path)
- .set('Accept', 'application/json')
- .expect(200)
- .expect('Content-Type', /json/)
- .end(end)
-}
-
-function getUserInformation (url, accessToken, end) {
- const path = '/api/v1/users/me'
-
- request(url)
- .get(path)
- .set('Accept', 'application/json')
- .set('Authorization', 'Bearer ' + accessToken)
- .expect(200)
- .expect('Content-Type', /json/)
- .end(end)
-}
-
-function getUsersList (url, end) {
- const path = '/api/v1/users'
-
- request(url)
- .get(path)
- .set('Accept', 'application/json')
- .expect(200)
- .expect('Content-Type', /json/)
- .end(end)
-}
-
-function getFriendsList (url, end) {
- const path = '/api/v1/pods/'
-
- request(url)
- .get(path)
- .set('Accept', 'application/json')
- .expect(200)
- .expect('Content-Type', /json/)
- .end(end)
-}
-
-function getVideo (url, id, end) {
- const path = '/api/v1/videos/' + id
-
- request(url)
- .get(path)
- .set('Accept', 'application/json')
- .expect(200)
- .expect('Content-Type', /json/)
- .end(end)
-}
-
-function getVideosList (url, end) {
- const path = '/api/v1/videos'
-
- request(url)
- .get(path)
- .query({ sort: 'name' })
- .set('Accept', 'application/json')
- .expect(200)
- .expect('Content-Type', /json/)
- .end(end)
-}
-
-function getVideosListPagination (url, start, count, end) {
- 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)
-}
-
-function getVideosListSort (url, sort, end) {
- const path = '/api/v1/videos'
-
- request(url)
- .get(path)
- .query({ sort: sort })
- .set('Accept', 'application/json')
- .expect(200)
- .expect('Content-Type', /json/)
- .end(end)
-}
-
-function login (url, client, user, expectedStatus, end) {
- if (!end) {
- end = expectedStatus
- expectedStatus = 200
- }
-
- const path = '/api/v1/users/token'
-
- const body = {
- client_id: client.id,
- client_secret: client.secret,
- username: user.username,
- password: user.password,
- response_type: 'code',
- grant_type: 'password',
- scope: 'upload'
- }
-
- request(url)
- .post(path)
- .type('form')
- .send(body)
- .expect(expectedStatus)
- .end(end)
-}
-
-function loginAndGetAccessToken (server, callback) {
- login(server.url, server.client, server.user, 200, function (err, res) {
- if (err) return callback(err)
-
- return callback(null, res.body.access_token)
- })
-}
-
-function makeFriends (url, accessToken, expectedStatus, callback) {
- if (!callback) {
- callback = expectedStatus
- expectedStatus = 204
- }
-
- const path = '/api/v1/pods/makefriends'
-
- // The first pod make friend with the third
- request(url)
- .get(path)
- .set('Accept', 'application/json')
- .set('Authorization', 'Bearer ' + accessToken)
- .expect(expectedStatus)
- .end(function (err, res) {
- if (err) throw err
-
- // Wait for the request between pods
- setTimeout(callback, 1000)
- })
-}
-
-function quitFriends (url, accessToken, expectedStatus, callback) {
- if (!callback) {
- callback = expectedStatus
- expectedStatus = 204
- }
-
- const path = '/api/v1/pods/quitfriends'
-
- // The first pod make friend with the third
- request(url)
- .get(path)
- .set('Accept', 'application/json')
- .set('Authorization', 'Bearer ' + accessToken)
- .expect(expectedStatus)
- .end(function (err, res) {
- if (err) throw err
-
- // Wait for the request between pods
- setTimeout(callback, 1000)
- })
-}
-
-function removeUser (url, token, username, expectedStatus, end) {
- if (!end) {
- end = expectedStatus
- expectedStatus = 204
- }
-
- const path = '/api/v1/users'
-
- request(url)
- .delete(path + '/' + username)
- .set('Accept', 'application/json')
- .set('Authorization', 'Bearer ' + token)
- .expect(expectedStatus)
- .end(end)
-}
-
-function removeVideo (url, token, id, expectedStatus, end) {
- if (!end) {
- end = expectedStatus
- expectedStatus = 204
- }
-
- const path = '/api/v1/videos'
-
- request(url)
- .delete(path + '/' + id)
- .set('Accept', 'application/json')
- .set('Authorization', 'Bearer ' + token)
- .expect(expectedStatus)
- .end(end)
-}
-
-function flushAndRunMultipleServers (totalServers, serversRun) {
- let apps = []
- let urls = []
- let i = 0
-
- function anotherServerDone (number, app, url) {
- apps[number - 1] = app
- urls[number - 1] = url
- i++
- if (i === totalServers) {
- serversRun(apps, urls)
- }
- }
-
- flushTests(function () {
- for (let j = 1; j <= totalServers; j++) {
- // For the virtual buffer
- setTimeout(function () {
- runServer(j, function (app, url) {
- anotherServerDone(j, app, url)
- })
- }, 1000 * j)
- }
- })
-}
-
-function runServer (number, callback) {
- const server = {
- app: null,
- url: `http://localhost:${9000 + number}`,
- client: {
- id: null,
- secret: null
- },
- user: {
- username: null,
- password: null
- }
- }
-
- // These actions are async so we need to be sure that they have both been done
- const serverRunString = {
- 'Connected to mongodb': false,
- 'Server listening on port': false
- }
-
- const regexps = {
- client_id: 'Client id: ([a-f0-9]+)',
- client_secret: 'Client secret: (.+)',
- user_username: 'Username: (.+)',
- user_password: 'User password: (.+)'
- }
-
- // Share the environment
- const env = Object.create(process.env)
- env.NODE_ENV = 'test'
- env.NODE_APP_INSTANCE = number
- const options = {
- silent: true,
- env: env,
- detached: true
- }
-
- server.app = fork(pathUtils.join(__dirname, '../../../server.js'), [], options)
- server.app.stdout.on('data', function onStdout (data) {
- let dontContinue = false
-
- // Capture things if we want to
- for (const key of Object.keys(regexps)) {
- const regexp = regexps[key]
- const matches = data.toString().match(regexp)
- if (matches !== null) {
- if (key === 'client_id') server.client.id = matches[1]
- else if (key === 'client_secret') server.client.secret = matches[1]
- else if (key === 'user_username') server.user.username = matches[1]
- else if (key === 'user_password') server.user.password = matches[1]
- }
- }
-
- // Check if all required sentences are here
- for (const key of Object.keys(serverRunString)) {
- if (data.toString().indexOf(key) !== -1) serverRunString[key] = true
- if (serverRunString[key] === false) dontContinue = true
- }
-
- // If no, there is maybe one thing not already initialized (mongodb...)
- if (dontContinue === true) return
-
- server.app.stdout.removeListener('data', onStdout)
- callback(server)
- })
-}
-
-function searchVideo (url, search, field, end) {
- if (!end) {
- end = field
- field = null
- }
-
- const path = '/api/v1/videos'
- const req = request(url)
- .get(path + '/search/' + search)
- .set('Accept', 'application/json')
-
- if (field) req.query({ field: field })
- req.expect(200)
- .expect('Content-Type', /json/)
- .end(end)
-}
-
-function searchVideoWithPagination (url, search, field, start, count, end) {
- 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)
-}
-
-function searchVideoWithSort (url, search, sort, end) {
- const path = '/api/v1/videos'
-
- request(url)
- .get(path + '/search/' + search)
- .query({ sort: sort })
- .set('Accept', 'application/json')
- .expect(200)
- .expect('Content-Type', /json/)
- .end(end)
-}
-
-function testImage (url, videoName, imagePath, callback) {
- // Don't test images if the node env is not set
- // Because we need a special ffmpeg version for this test
- if (process.env.NODE_TEST_IMAGE) {
- request(url)
- .get(imagePath)
- .expect(200)
- .end(function (err, res) {
- if (err) return callback(err)
-
- fs.readFile(pathUtils.join(__dirname, 'fixtures', videoName + '.jpg'), function (err, data) {
- if (err) return callback(err)
-
- callback(null, data.equals(res.body))
- })
- })
- } else {
- console.log('Do not test images. Enable it by setting NODE_TEST_IMAGE env variable.')
- callback(null, true)
- }
-}
-
-function uploadVideo (url, accessToken, name, description, tags, fixture, specialStatus, end) {
- if (!end) {
- end = specialStatus
- specialStatus = 204
- }
-
- const path = '/api/v1/videos'
-
- const req = request(url)
- .post(path)
- .set('Accept', 'application/json')
- .set('Authorization', 'Bearer ' + accessToken)
- .field('name', name)
- .field('description', description)
-
- for (let i = 0; i < tags.length; i++) {
- req.field('tags[' + i + ']', tags[i])
- }
-
- let filepath = ''
- if (pathUtils.isAbsolute(fixture)) {
- filepath = fixture
- } else {
- filepath = pathUtils.join(__dirname, 'fixtures', fixture)
- }
-
- req.attach('videofile', filepath)
- .expect(specialStatus)
- .end(end)
-}
-
-function updateUser (url, userId, accessToken, newPassword, end) {
- const path = '/api/v1/users/' + userId
-
- request(url)
- .put(path)
- .set('Accept', 'application/json')
- .set('Authorization', 'Bearer ' + accessToken)
- .send({ password: newPassword })
- .expect(204)
- .end(end)
-}
-
-// ---------------------------------------------------------------------------
-
-module.exports = testUtils
--- /dev/null
+'use strict'
+
+const request = require('supertest')
+
+const clientsUtils = {
+ getClient: getClient
+}
+
+// ---------------------- Export functions --------------------
+
+function getClient (url, end) {
+ const path = '/api/v1/users/client'
+
+ request(url)
+ .get(path)
+ .set('Accept', 'application/json')
+ .expect(200)
+ .expect('Content-Type', /json/)
+ .end(end)
+}
+
+// ---------------------------------------------------------------------------
+
+module.exports = clientsUtils
--- /dev/null
+'use strict'
+
+const request = require('supertest')
+
+const loginUtils = {
+ login: login,
+ loginAndGetAccessToken: loginAndGetAccessToken
+}
+
+// ---------------------- Export functions --------------------
+
+function login (url, client, user, expectedStatus, end) {
+ if (!end) {
+ end = expectedStatus
+ expectedStatus = 200
+ }
+
+ const path = '/api/v1/users/token'
+
+ const body = {
+ client_id: client.id,
+ client_secret: client.secret,
+ username: user.username,
+ password: user.password,
+ response_type: 'code',
+ grant_type: 'password',
+ scope: 'upload'
+ }
+
+ request(url)
+ .post(path)
+ .type('form')
+ .send(body)
+ .expect(expectedStatus)
+ .end(end)
+}
+
+function loginAndGetAccessToken (server, callback) {
+ login(server.url, server.client, server.user, 200, function (err, res) {
+ if (err) return callback(err)
+
+ return callback(null, res.body.access_token)
+ })
+}
+
+// ---------------------------------------------------------------------------
+
+module.exports = loginUtils
--- /dev/null
+'use strict'
+
+const miscsUtils = {
+ dateIsValid: dateIsValid
+}
+
+// ---------------------- Export functions --------------------
+
+function dateIsValid (dateString) {
+ const dateToCheck = new Date(dateString)
+ const now = new Date()
+
+ // Check if the interval is more than 2 minutes
+ if (now - dateToCheck > 120000) return false
+
+ return true
+}
+
+// ---------------------------------------------------------------------------
+
+module.exports = miscsUtils
--- /dev/null
+'use strict'
+
+const request = require('supertest')
+
+const podsUtils = {
+ getFriendsList: getFriendsList,
+ makeFriends: makeFriends,
+ quitFriends: quitFriends
+}
+
+// ---------------------- Export functions --------------------
+
+function getFriendsList (url, end) {
+ const path = '/api/v1/pods/'
+
+ request(url)
+ .get(path)
+ .set('Accept', 'application/json')
+ .expect(200)
+ .expect('Content-Type', /json/)
+ .end(end)
+}
+
+function makeFriends (url, accessToken, expectedStatus, end) {
+ if (!end) {
+ end = expectedStatus
+ expectedStatus = 204
+ }
+
+ const path = '/api/v1/pods/makefriends'
+
+ // The first pod make friend with the third
+ request(url)
+ .get(path)
+ .set('Accept', 'application/json')
+ .set('Authorization', 'Bearer ' + accessToken)
+ .expect(expectedStatus)
+ .end(function (err, res) {
+ if (err) throw err
+
+ // Wait for the request between pods
+ setTimeout(end, 1000)
+ })
+}
+
+function quitFriends (url, accessToken, expectedStatus, end) {
+ if (!end) {
+ end = expectedStatus
+ expectedStatus = 204
+ }
+
+ const path = '/api/v1/pods/quitfriends'
+
+ // The first pod make friend with the third
+ request(url)
+ .get(path)
+ .set('Accept', 'application/json')
+ .set('Authorization', 'Bearer ' + accessToken)
+ .expect(expectedStatus)
+ .end(function (err, res) {
+ if (err) throw err
+
+ // Wait for the request between pods
+ setTimeout(end, 1000)
+ })
+}
+
+// ---------------------------------------------------------------------------
+
+module.exports = podsUtils
--- /dev/null
+'use strict'
+
+const childProcess = require('child_process')
+const exec = childProcess.exec
+const fork = childProcess.fork
+const pathUtils = require('path')
+
+const serversUtils = {
+ flushAndRunMultipleServers: flushAndRunMultipleServers,
+ flushTests: flushTests,
+ runServer: runServer
+}
+
+// ---------------------- Export functions --------------------
+
+function flushAndRunMultipleServers (totalServers, serversRun) {
+ let apps = []
+ let urls = []
+ let i = 0
+
+ function anotherServerDone (number, app, url) {
+ apps[number - 1] = app
+ urls[number - 1] = url
+ i++
+ if (i === totalServers) {
+ serversRun(apps, urls)
+ }
+ }
+
+ flushTests(function () {
+ for (let j = 1; j <= totalServers; j++) {
+ // For the virtual buffer
+ setTimeout(function () {
+ runServer(j, function (app, url) {
+ anotherServerDone(j, app, url)
+ })
+ }, 1000 * j)
+ }
+ })
+}
+
+function flushTests (callback) {
+ exec('npm run clean:server:test', callback)
+}
+
+function runServer (number, callback) {
+ const server = {
+ app: null,
+ url: `http://localhost:${9000 + number}`,
+ client: {
+ id: null,
+ secret: null
+ },
+ user: {
+ username: null,
+ password: null
+ }
+ }
+
+ // These actions are async so we need to be sure that they have both been done
+ const serverRunString = {
+ 'Connected to mongodb': false,
+ 'Server listening on port': false
+ }
+
+ const regexps = {
+ client_id: 'Client id: ([a-f0-9]+)',
+ client_secret: 'Client secret: (.+)',
+ user_username: 'Username: (.+)',
+ user_password: 'User password: (.+)'
+ }
+
+ // Share the environment
+ const env = Object.create(process.env)
+ env.NODE_ENV = 'test'
+ env.NODE_APP_INSTANCE = number
+ const options = {
+ silent: true,
+ env: env,
+ detached: true
+ }
+
+ server.app = fork(pathUtils.join(__dirname, '../../../server.js'), [], options)
+ server.app.stdout.on('data', function onStdout (data) {
+ let dontContinue = false
+
+ // Capture things if we want to
+ for (const key of Object.keys(regexps)) {
+ const regexp = regexps[key]
+ const matches = data.toString().match(regexp)
+ if (matches !== null) {
+ if (key === 'client_id') server.client.id = matches[1]
+ else if (key === 'client_secret') server.client.secret = matches[1]
+ else if (key === 'user_username') server.user.username = matches[1]
+ else if (key === 'user_password') server.user.password = matches[1]
+ }
+ }
+
+ // Check if all required sentences are here
+ for (const key of Object.keys(serverRunString)) {
+ if (data.toString().indexOf(key) !== -1) serverRunString[key] = true
+ if (serverRunString[key] === false) dontContinue = true
+ }
+
+ // If no, there is maybe one thing not already initialized (mongodb...)
+ if (dontContinue === true) return
+
+ server.app.stdout.removeListener('data', onStdout)
+ callback(server)
+ })
+}
+
+// ---------------------------------------------------------------------------
+
+module.exports = serversUtils
--- /dev/null
+'use strict'
+
+const request = require('supertest')
+
+const usersUtils = {
+ createUser: createUser,
+ getUserInformation: getUserInformation,
+ getUsersList: getUsersList,
+ removeUser: removeUser,
+ updateUser: updateUser
+}
+
+// ---------------------- Export functions --------------------
+
+function createUser (url, accessToken, username, password, specialStatus, end) {
+ if (!end) {
+ end = specialStatus
+ specialStatus = 204
+ }
+
+ const path = '/api/v1/users'
+
+ request(url)
+ .post(path)
+ .set('Accept', 'application/json')
+ .set('Authorization', 'Bearer ' + accessToken)
+ .send({ username: username, password: password })
+ .expect(specialStatus)
+ .end(end)
+}
+
+function getUserInformation (url, accessToken, end) {
+ const path = '/api/v1/users/me'
+
+ request(url)
+ .get(path)
+ .set('Accept', 'application/json')
+ .set('Authorization', 'Bearer ' + accessToken)
+ .expect(200)
+ .expect('Content-Type', /json/)
+ .end(end)
+}
+
+function getUsersList (url, end) {
+ const path = '/api/v1/users'
+
+ request(url)
+ .get(path)
+ .set('Accept', 'application/json')
+ .expect(200)
+ .expect('Content-Type', /json/)
+ .end(end)
+}
+
+function removeUser (url, token, username, expectedStatus, end) {
+ if (!end) {
+ end = expectedStatus
+ expectedStatus = 204
+ }
+
+ const path = '/api/v1/users'
+
+ request(url)
+ .delete(path + '/' + username)
+ .set('Accept', 'application/json')
+ .set('Authorization', 'Bearer ' + token)
+ .expect(expectedStatus)
+ .end(end)
+}
+
+function updateUser (url, userId, accessToken, newPassword, end) {
+ const path = '/api/v1/users/' + userId
+
+ request(url)
+ .put(path)
+ .set('Accept', 'application/json')
+ .set('Authorization', 'Bearer ' + accessToken)
+ .send({ password: newPassword })
+ .expect(204)
+ .end(end)
+}
+
+// ---------------------------------------------------------------------------
+
+module.exports = usersUtils
--- /dev/null
+'use strict'
+
+const fs = require('fs')
+const pathUtils = require('path')
+const request = require('supertest')
+
+const videosUtils = {
+ getAllVideosListBy: getAllVideosListBy,
+ getVideo: getVideo,
+ getVideosList: getVideosList,
+ getVideosListPagination: getVideosListPagination,
+ getVideosListSort: getVideosListSort,
+ removeVideo: removeVideo,
+ searchVideo: searchVideo,
+ searchVideoWithPagination: searchVideoWithPagination,
+ searchVideoWithSort: searchVideoWithSort,
+ testVideoImage: testVideoImage,
+ uploadVideo: uploadVideo
+}
+
+// ---------------------- Export functions --------------------
+
+function getAllVideosListBy (url, end) {
+ const path = '/api/v1/videos'
+
+ request(url)
+ .get(path)
+ .query({ sort: 'createdDate' })
+ .query({ start: 0 })
+ .query({ count: 10000 })
+ .set('Accept', 'application/json')
+ .expect(200)
+ .expect('Content-Type', /json/)
+ .end(end)
+}
+
+function getVideo (url, id, end) {
+ const path = '/api/v1/videos/' + id
+
+ request(url)
+ .get(path)
+ .set('Accept', 'application/json')
+ .expect(200)
+ .expect('Content-Type', /json/)
+ .end(end)
+}
+
+function getVideosList (url, end) {
+ const path = '/api/v1/videos'
+
+ request(url)
+ .get(path)
+ .query({ sort: 'name' })
+ .set('Accept', 'application/json')
+ .expect(200)
+ .expect('Content-Type', /json/)
+ .end(end)
+}
+
+function getVideosListPagination (url, start, count, end) {
+ 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)
+}
+
+function getVideosListSort (url, sort, end) {
+ const path = '/api/v1/videos'
+
+ request(url)
+ .get(path)
+ .query({ sort: sort })
+ .set('Accept', 'application/json')
+ .expect(200)
+ .expect('Content-Type', /json/)
+ .end(end)
+}
+
+function removeVideo (url, token, id, expectedStatus, end) {
+ if (!end) {
+ end = expectedStatus
+ expectedStatus = 204
+ }
+
+ const path = '/api/v1/videos'
+
+ request(url)
+ .delete(path + '/' + id)
+ .set('Accept', 'application/json')
+ .set('Authorization', 'Bearer ' + token)
+ .expect(expectedStatus)
+ .end(end)
+}
+
+function searchVideo (url, search, field, end) {
+ if (!end) {
+ end = field
+ field = null
+ }
+
+ const path = '/api/v1/videos'
+ const req = request(url)
+ .get(path + '/search/' + search)
+ .set('Accept', 'application/json')
+
+ if (field) req.query({ field: field })
+ req.expect(200)
+ .expect('Content-Type', /json/)
+ .end(end)
+}
+
+function searchVideoWithPagination (url, search, field, start, count, end) {
+ 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)
+}
+
+function searchVideoWithSort (url, search, sort, end) {
+ const path = '/api/v1/videos'
+
+ request(url)
+ .get(path + '/search/' + search)
+ .query({ sort: sort })
+ .set('Accept', 'application/json')
+ .expect(200)
+ .expect('Content-Type', /json/)
+ .end(end)
+}
+
+function testVideoImage (url, videoName, imagePath, callback) {
+ // Don't test images if the node env is not set
+ // Because we need a special ffmpeg version for this test
+ if (process.env.NODE_TEST_IMAGE) {
+ request(url)
+ .get(imagePath)
+ .expect(200)
+ .end(function (err, res) {
+ if (err) return callback(err)
+
+ fs.readFile(pathUtils.join(__dirname, '..', 'api', 'fixtures', videoName + '.jpg'), function (err, data) {
+ if (err) return callback(err)
+
+ callback(null, data.equals(res.body))
+ })
+ })
+ } else {
+ console.log('Do not test images. Enable it by setting NODE_TEST_IMAGE env variable.')
+ callback(null, true)
+ }
+}
+
+function uploadVideo (url, accessToken, name, description, tags, fixture, specialStatus, end) {
+ if (!end) {
+ end = specialStatus
+ specialStatus = 204
+ }
+
+ const path = '/api/v1/videos'
+
+ const req = request(url)
+ .post(path)
+ .set('Accept', 'application/json')
+ .set('Authorization', 'Bearer ' + accessToken)
+ .field('name', name)
+ .field('description', description)
+
+ for (let i = 0; i < tags.length; i++) {
+ req.field('tags[' + i + ']', tags[i])
+ }
+
+ let filepath = ''
+ if (pathUtils.isAbsolute(fixture)) {
+ filepath = fixture
+ } else {
+ filepath = pathUtils.join(__dirname, '..', 'api', 'fixtures', fixture)
+ }
+
+ req.attach('videofile', filepath)
+ .expect(specialStatus)
+ .end(end)
+}
+
+// ---------------------------------------------------------------------------
+
+module.exports = videosUtils