thumbnail: thumbnailName
}
- Videos.add(videoData, function (err) {
+ Videos.add(videoData, function (err, insertedVideo) {
if (err) {
// TODO unseed the video
logger.error('Cannot insert this video in the database.')
return next(err)
}
+ videoData.createdDate = insertedVideo.createdDate
+
fs.readFile(thumbnailsDir + thumbnailName, function (err, data) {
if (err) {
// TODO: remove video?
magnetUri: videoObj.magnetUri,
author: videoObj.author,
duration: videoObj.duration,
- thumbnailPath: constants.THUMBNAILS_STATIC_PATH + '/' + videoObj.thumbnail
+ thumbnailPath: constants.THUMBNAILS_STATIC_PATH + '/' + videoObj.thumbnail,
+ createdDate: videoObj.createdDate
}
return formatedVideo
validator.isLength(val.description, 1, 50) &&
validator.isLength(val.magnetUri, 10) &&
validator.isURL(val.podUrl) &&
- !isNaN(val.duration)
+ !isNaN(val.duration) &&
+ validator.isDate(val.createdDate)
})
}
podUrl: String,
author: String,
duration: Number,
- thumbnail: String
+ thumbnail: String,
+ createdDate: {
+ type: Date,
+ default: Date.now
+ }
})
const VideosDB = mongoose.model('videos', videosSchema)
const params = video
params.podUrl = http + '://' + host + ':' + port
- VideosDB.create(params, function (err, video) {
+ VideosDB.create(params, function (err, insertedVideo) {
if (err) {
logger.error('Cannot insert this video into database.')
return callback(err)
}
- callback(null)
+ callback(null, insertedVideo)
})
}
expect(video.podUrl).to.equal('http://localhost:9001')
expect(video.magnetUri).to.exist
expect(video.duration).to.equal(10)
+ expect(utils.dateIsValid(video.createdDate)).to.be.true
if (server.url !== 'http://localhost:9001') {
expect(video.isLocal).to.be.false
expect(video.podUrl).to.equal('http://localhost:9002')
expect(video.magnetUri).to.exist
expect(video.duration).to.equal(5)
+ expect(utils.dateIsValid(video.createdDate)).to.be.true
if (server.url !== 'http://localhost:9002') {
expect(video.isLocal).to.be.false
expect(video1.podUrl).to.equal('http://localhost:9003')
expect(video1.magnetUri).to.exist
expect(video1.duration).to.equal(5)
+ expect(utils.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.podUrl).to.equal('http://localhost:9003')
expect(video2.magnetUri).to.exist
expect(video2.duration).to.equal(5)
+ expect(utils.dateIsValid(video2.createdDate)).to.be.true
if (server.url !== 'http://localhost:9003') {
expect(video1.isLocal).to.be.false
expect(video.magnetUri).to.exist
expect(video.author).to.equal('root')
expect(video.isLocal).to.be.true
+ expect(utils.dateIsValid(video.createdDate)).to.be.true
utils.testImage(server.url, 'video_short.webm', video.thumbnailPath, function (err, test) {
if (err) throw err
expect(video.magnetUri).to.exist
expect(video.author).to.equal('root')
expect(video.isLocal).to.be.true
+ expect(utils.dateIsValid(video.createdDate)).to.be.true
utils.testImage(server.url, 'video_short.webm', video.thumbnailPath, function (err, test) {
if (err) throw err
expect(video.podUrl).to.equal('http://localhost:9001')
expect(video.author).to.equal('root')
expect(video.isLocal).to.be.true
+ expect(utils.dateIsValid(video.createdDate)).to.be.true
utils.testImage(server.url, 'video_short.webm', video.thumbnailPath, function (err, test) {
if (err) throw err
const request = require('supertest')
const testUtils = {
+ dateIsValid: dateIsValid,
flushTests: flushTests,
getFriendsList: getFriendsList,
getVideo: getVideo,
// ---------------------- 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
+}
+
function flushTests (callback) {
exec('npm run clean:server:test', callback)
}