2
0
mirror of https://github.com/thumbsup/thumbsup synced 2024-11-09 13:10:28 +00:00
thumbsup/test/model/file.spec.js

63 lines
1.6 KiB
JavaScript
Raw Normal View History

2017-02-28 09:35:09 +00:00
const should = require('should/as-function')
const File = require('../../src/model/file')
2017-02-28 09:35:09 +00:00
describe('File', function () {
2017-02-28 09:35:09 +00:00
it('reads the relative file path', function () {
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 () {
var file = new File(dbFile({
2017-02-28 09:35:09 +00:00
File: {
FileModifyDate: '2017:01:27 14:38:29+05:00'
}
}))
should(file.date).eql(1485509909000)
2017-02-28 09:35:09 +00:00
})
it('can guess the media type for photos', function () {
var file = new File(dbFile({
File: {
MIMEType: 'image/jpeg'
}
}))
should(file.type).eql('image')
})
it('can guess the media type for videos', function () {
var file = new File(dbFile({
File: {
MIMEType: 'video/quicktime'
}
}))
should(file.type).eql('video')
2017-02-28 09:35:09 +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
})
function dbFile (data) {
// some required data
if (!data.SourceFile) data.SourceFile = 'photo.jpg'
if (!data.File) data.File = {}
if (!data.File.FileModifyDate) data.File.FileModifyDate = '1999:12:31 23:59:59+00:00'
return data
}