2017-02-28 09:35:09 +00:00
|
|
|
const should = require('should/as-function')
|
2017-07-24 11:40:03 +00:00
|
|
|
const File = require('../../src/model/file')
|
2017-02-28 09:35:09 +00:00
|
|
|
|
2017-07-24 11:40:03 +00:00
|
|
|
describe('File', function () {
|
2017-02-28 09:35:09 +00:00
|
|
|
it('reads the relative file path', function () {
|
2017-03-06 11:16:36 +00:00
|
|
|
var file = new File(dbFile({
|
|
|
|
SourceFile: 'holidays/beach.jpg'
|
|
|
|
}))
|
2017-02-28 09:35:09 +00:00
|
|
|
should(file.path).eql('holidays/beach.jpg')
|
|
|
|
})
|
|
|
|
|
|
|
|
it('parses the file modification date', function () {
|
2017-02-28 10:40:51 +00:00
|
|
|
var file = new File(dbFile({
|
2017-02-28 09:35:09 +00:00
|
|
|
File: {
|
|
|
|
FileModifyDate: '2017:01:27 14:38:29+05:00'
|
|
|
|
}
|
2017-02-28 10:40:51 +00:00
|
|
|
}))
|
2017-03-06 11:16:36 +00:00
|
|
|
should(file.date).eql(1485509909000)
|
2017-02-28 09:35:09 +00:00
|
|
|
})
|
|
|
|
|
2017-02-28 10:40:51 +00:00
|
|
|
it('can guess the media type for photos', function () {
|
|
|
|
var file = new File(dbFile({
|
2017-03-06 11:16:36 +00:00
|
|
|
File: {
|
|
|
|
MIMEType: 'image/jpeg'
|
|
|
|
}
|
2017-02-28 10:40:51 +00:00
|
|
|
}))
|
2017-03-06 11:16:36 +00:00
|
|
|
should(file.type).eql('image')
|
2017-02-28 10:40:51 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
it('can guess the media type for videos', function () {
|
|
|
|
var file = new File(dbFile({
|
2017-03-06 11:16:36 +00:00
|
|
|
File: {
|
|
|
|
MIMEType: 'video/quicktime'
|
|
|
|
}
|
2017-02-28 10:40:51 +00:00
|
|
|
}))
|
2017-03-06 11:16:36 +00:00
|
|
|
should(file.type).eql('video')
|
2017-02-28 09:35:09 +00:00
|
|
|
})
|
2017-07-24 11:40:03 +00:00
|
|
|
|
|
|
|
it('marks all other data types as unknown', function () {
|
|
|
|
var file = new File(dbFile({
|
|
|
|
File: {
|
|
|
|
MIMEType: 'text/html'
|
|
|
|
}
|
|
|
|
}))
|
|
|
|
should(file.type).eql('unknown')
|
|
|
|
})
|
|
|
|
|
|
|
|
it('has a boolean flag for videos to simplify templates', function () {
|
|
|
|
var photo = new File(dbFile({File: {MIMEType: 'image/jpeg'}}))
|
|
|
|
should(photo.isVideo).eql(false)
|
|
|
|
var video = new File(dbFile({File: {MIMEType: 'video/quicktime'}}))
|
|
|
|
should(video.isVideo).eql(true)
|
|
|
|
})
|
2017-02-28 09:35:09 +00:00
|
|
|
})
|
2017-02-28 10:40:51 +00:00
|
|
|
|
|
|
|
function dbFile (data) {
|
2017-03-06 12:27:44 +00:00
|
|
|
// some required data
|
|
|
|
if (!data.SourceFile) data.SourceFile = 'photo.jpg'
|
2017-02-28 10:40:51 +00:00
|
|
|
if (!data.File) data.File = {}
|
2017-03-06 12:46:46 +00:00
|
|
|
if (!data.File.FileModifyDate) data.File.FileModifyDate = '1999:12:31 23:59:59+00:00'
|
2017-02-28 10:40:51 +00:00
|
|
|
return data
|
|
|
|
}
|