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 () {
|
2018-08-18 18:25:35 +00:00
|
|
|
const file = new File(dbFile({
|
2017-03-06 11:16:36 +00:00
|
|
|
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 () {
|
2018-08-18 18:25:35 +00:00
|
|
|
const 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 () {
|
2018-08-18 18:25:35 +00:00
|
|
|
const 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 () {
|
2018-08-18 18:25:35 +00:00
|
|
|
const 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 () {
|
2018-08-18 18:25:35 +00:00
|
|
|
const file = new File(dbFile({
|
2017-07-24 11:40:03 +00:00
|
|
|
File: {
|
|
|
|
MIMEType: 'text/html'
|
|
|
|
}
|
|
|
|
}))
|
|
|
|
should(file.type).eql('unknown')
|
|
|
|
})
|
|
|
|
|
|
|
|
it('has a boolean flag for videos to simplify templates', function () {
|
2018-12-11 22:11:03 +00:00
|
|
|
const photo = new File(dbFile({ File: { MIMEType: 'image/jpeg' } }))
|
2017-07-24 11:40:03 +00:00
|
|
|
should(photo.isVideo).eql(false)
|
2018-12-11 22:11:03 +00:00
|
|
|
const video = new File(dbFile({ File: { MIMEType: 'video/quicktime' } }))
|
2017-07-24 11:40:03 +00:00
|
|
|
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
|
|
|
|
}
|