2017-05-25 11:43:03 +00:00
|
|
|
const should = require('should/as-function')
|
2017-07-24 11:40:03 +00:00
|
|
|
const output = require('../../src/model/output')
|
2017-05-25 11:43:03 +00:00
|
|
|
|
|
|
|
describe('Output paths', function () {
|
|
|
|
describe('Images', function () {
|
|
|
|
it('generates a thumbnail', function () {
|
2018-08-18 18:25:35 +00:00
|
|
|
const o = output.paths('holidays/beach.jpg', 'image', {})
|
2017-05-25 11:43:03 +00:00
|
|
|
should(o.thumbnail).eql({
|
|
|
|
path: 'media/thumbs/holidays/beach.jpg',
|
|
|
|
rel: 'photo:thumbnail'
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it('generates a large "web" version', function () {
|
2018-08-18 18:25:35 +00:00
|
|
|
const o = output.paths('holidays/beach.jpg', 'image', {})
|
2017-05-25 11:43:03 +00:00
|
|
|
should(o.large).eql({
|
|
|
|
path: 'media/large/holidays/beach.jpg',
|
|
|
|
rel: 'photo:large'
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it('can point downloads to the large version', function () {
|
2018-08-18 18:25:35 +00:00
|
|
|
const o = output.paths('holidays/beach.jpg', 'image', {
|
2019-02-07 21:08:38 +00:00
|
|
|
photoDownload: 'resize'
|
2017-05-25 11:43:03 +00:00
|
|
|
})
|
|
|
|
should(o.download).eql({
|
|
|
|
path: 'media/large/holidays/beach.jpg',
|
|
|
|
rel: 'photo:large'
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2019-02-07 21:08:38 +00:00
|
|
|
it('can point previews to a copy in the output folder', function () {
|
|
|
|
const o = output.paths('holidays/beach.jpg', 'image', {
|
|
|
|
photoPreview: 'copy'
|
|
|
|
})
|
|
|
|
should(o.large).eql({
|
|
|
|
path: 'media/original/holidays/beach.jpg',
|
|
|
|
rel: 'fs:copy'
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2017-05-25 11:43:03 +00:00
|
|
|
it('can point downloads to a copy in the output folder', function () {
|
2018-08-18 18:25:35 +00:00
|
|
|
const o = output.paths('holidays/beach.jpg', 'image', {
|
2019-02-07 21:08:38 +00:00
|
|
|
photoDownload: 'copy'
|
2017-05-25 11:43:03 +00:00
|
|
|
})
|
|
|
|
should(o.download).eql({
|
|
|
|
path: 'media/original/holidays/beach.jpg',
|
|
|
|
rel: 'fs:copy'
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it('can point downloads to a symlink to the originals', function () {
|
2018-08-18 18:25:35 +00:00
|
|
|
const o = output.paths('holidays/beach.jpg', 'image', {
|
2019-02-07 21:08:38 +00:00
|
|
|
photoDownload: 'symlink'
|
2017-05-25 11:43:03 +00:00
|
|
|
})
|
|
|
|
should(o.download).eql({
|
|
|
|
path: 'media/original/holidays/beach.jpg',
|
|
|
|
rel: 'fs:symlink'
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it('can point downloads to an existing link', function () {
|
2018-08-18 18:25:35 +00:00
|
|
|
const o = output.paths('holidays/beach.jpg', 'image', {
|
2019-02-07 21:08:38 +00:00
|
|
|
photoDownload: 'link',
|
|
|
|
linkPrefix: '../myphotos'
|
2017-05-25 11:43:03 +00:00
|
|
|
})
|
|
|
|
should(o.download).eql({
|
|
|
|
path: '../myphotos/holidays/beach.jpg',
|
|
|
|
rel: 'fs:link'
|
|
|
|
})
|
|
|
|
})
|
2018-06-07 22:27:44 +00:00
|
|
|
|
|
|
|
it('keeps the original image format if the browser supports it', function () {
|
2018-06-07 22:49:03 +00:00
|
|
|
['jpg', 'JPG', 'jpeg', 'JPEG', 'png', 'PNG', 'gif', 'GIF'].forEach(ext => {
|
2018-08-18 18:25:35 +00:00
|
|
|
const o = output.paths(`holidays/beach.${ext}`, 'image', {})
|
2018-06-07 22:27:44 +00:00
|
|
|
should(o.thumbnail.path).eql(`media/thumbs/holidays/beach.${ext}`)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it('converts images to JPEG if not supported', function () {
|
|
|
|
// some of these formats are supported on certain browser, but we aim for maximum compatibility
|
|
|
|
['bmp', 'tiff', 'webp'].forEach(ext => {
|
2018-08-18 18:25:35 +00:00
|
|
|
const o = output.paths(`holidays/beach.${ext}`, 'image', {})
|
2018-06-07 22:27:44 +00:00
|
|
|
should(o.thumbnail.path).eql(`media/thumbs/holidays/beach.jpg`)
|
|
|
|
})
|
|
|
|
})
|
2017-05-25 11:43:03 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
describe('Videos', function () {
|
|
|
|
it('generates a thumbnail', function () {
|
2018-08-18 18:25:35 +00:00
|
|
|
const o = output.paths('holidays/seagull.mp4', 'video', {})
|
2017-05-25 11:43:03 +00:00
|
|
|
should(o.thumbnail).eql({
|
|
|
|
path: 'media/thumbs/holidays/seagull.jpg',
|
|
|
|
rel: 'video:thumbnail'
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it('generates a poster image', function () {
|
2018-08-18 18:25:35 +00:00
|
|
|
const o = output.paths('holidays/seagull.mp4', 'video', {})
|
2017-05-25 11:43:03 +00:00
|
|
|
should(o.large).eql({
|
|
|
|
path: 'media/large/holidays/seagull.jpg',
|
|
|
|
rel: 'video:poster'
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it('generates a resized "web" video', function () {
|
2019-01-07 20:48:44 +00:00
|
|
|
const o = output.paths('holidays/seagull.mp4', 'video', { videoFormat: 'mp4' })
|
2017-05-25 11:43:03 +00:00
|
|
|
should(o.video).eql({
|
|
|
|
path: 'media/large/holidays/seagull.mp4',
|
|
|
|
rel: 'video:resized'
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it('can point downloads to the large version', function () {
|
2018-08-18 18:25:35 +00:00
|
|
|
const o = output.paths('holidays/seagull.mp4', 'video', {
|
2019-02-07 21:08:38 +00:00
|
|
|
videoDownload: 'resize',
|
2019-01-07 20:48:44 +00:00
|
|
|
videoFormat: 'mp4'
|
2017-05-25 11:43:03 +00:00
|
|
|
})
|
|
|
|
should(o.download).eql({
|
|
|
|
path: 'media/large/holidays/seagull.mp4',
|
|
|
|
rel: 'video:resized'
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it('can point downloads to a copy in the output folder', function () {
|
2018-08-18 18:25:35 +00:00
|
|
|
const o = output.paths('holidays/seagull.mp4', 'video', {
|
2019-02-07 21:08:38 +00:00
|
|
|
videoDownload: 'copy'
|
2017-05-25 11:43:03 +00:00
|
|
|
})
|
|
|
|
should(o.download).eql({
|
|
|
|
path: 'media/original/holidays/seagull.mp4',
|
|
|
|
rel: 'fs:copy'
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2019-02-07 21:08:38 +00:00
|
|
|
it('can point previews to a copy in the output folder', function () {
|
|
|
|
const o = output.paths('holidays/seagull.mp4', 'video', {
|
|
|
|
videoPreview: 'copy'
|
|
|
|
})
|
|
|
|
should(o.video).eql({
|
|
|
|
path: 'media/original/holidays/seagull.mp4',
|
|
|
|
rel: 'fs:copy'
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2017-05-25 11:43:03 +00:00
|
|
|
it('can point downloads to a symlink to the originals', function () {
|
2018-08-18 18:25:35 +00:00
|
|
|
const o = output.paths('holidays/seagull.mp4', 'video', {
|
2019-02-07 21:08:38 +00:00
|
|
|
videoDownload: 'symlink'
|
2017-05-25 11:43:03 +00:00
|
|
|
})
|
|
|
|
should(o.download).eql({
|
|
|
|
path: 'media/original/holidays/seagull.mp4',
|
|
|
|
rel: 'fs:symlink'
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it('can point downloads to an existing link', function () {
|
2018-08-18 18:25:35 +00:00
|
|
|
const o = output.paths('holidays/seagull.mp4', 'video', {
|
2019-02-07 21:08:38 +00:00
|
|
|
videoDownload: 'link',
|
|
|
|
linkPrefix: '../myphotos'
|
2017-05-25 11:43:03 +00:00
|
|
|
})
|
|
|
|
should(o.download).eql({
|
|
|
|
path: '../myphotos/holidays/seagull.mp4',
|
|
|
|
rel: 'fs:link'
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('Download links', function () {
|
|
|
|
it('can use a relative link prefix', function () {
|
2018-08-18 18:25:35 +00:00
|
|
|
const o = output.paths('holidays/beach.jpg', 'image', {
|
2019-02-07 21:08:38 +00:00
|
|
|
photoDownload: 'link',
|
|
|
|
linkPrefix: '../myphotos'
|
2017-05-25 11:43:03 +00:00
|
|
|
})
|
|
|
|
should(o.download).eql({
|
|
|
|
path: '../myphotos/holidays/beach.jpg',
|
|
|
|
rel: 'fs:link'
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it('can use a relative link prefix ending with a slash', function () {
|
2018-08-18 18:25:35 +00:00
|
|
|
const o = output.paths('holidays/beach.jpg', 'image', {
|
2019-02-07 21:08:38 +00:00
|
|
|
photoDownload: 'link',
|
|
|
|
linkPrefix: '../myphotos/'
|
2017-05-25 11:43:03 +00:00
|
|
|
})
|
|
|
|
should(o.download).eql({
|
|
|
|
path: '../myphotos/holidays/beach.jpg',
|
|
|
|
rel: 'fs:link'
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it('can use an absolute link prefix', function () {
|
2018-08-18 18:25:35 +00:00
|
|
|
const o = output.paths('holidays/beach.jpg', 'image', {
|
2019-02-07 21:08:38 +00:00
|
|
|
photoDownload: 'link',
|
|
|
|
linkPrefix: '/Photos'
|
2017-05-25 11:43:03 +00:00
|
|
|
})
|
|
|
|
should(o.download).eql({
|
|
|
|
path: '/Photos/holidays/beach.jpg',
|
|
|
|
rel: 'fs:link'
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it('can use an absolute link prefix ending with a slash', function () {
|
2018-08-18 18:25:35 +00:00
|
|
|
const o = output.paths('holidays/beach.jpg', 'image', {
|
2019-02-07 21:08:38 +00:00
|
|
|
photoDownload: 'link',
|
|
|
|
linkPrefix: '/Photos/'
|
2017-05-25 11:43:03 +00:00
|
|
|
})
|
|
|
|
should(o.download).eql({
|
|
|
|
path: '/Photos/holidays/beach.jpg',
|
|
|
|
rel: 'fs:link'
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it('can use a URL prefix', function () {
|
2018-08-18 18:25:35 +00:00
|
|
|
const o = output.paths('holidays/beach.jpg', 'image', {
|
2019-02-07 21:08:38 +00:00
|
|
|
photoDownload: 'link',
|
|
|
|
linkPrefix: 'http://mygallery.com/photos'
|
2017-05-25 11:43:03 +00:00
|
|
|
})
|
|
|
|
should(o.download).eql({
|
|
|
|
path: 'http://mygallery.com/photos/holidays/beach.jpg',
|
|
|
|
rel: 'fs:link'
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it('can use a URL prefix ending with a slash', function () {
|
2018-08-18 18:25:35 +00:00
|
|
|
const o = output.paths('holidays/beach.jpg', 'image', {
|
2019-02-07 21:08:38 +00:00
|
|
|
photoDownload: 'link',
|
|
|
|
linkPrefix: 'http://mygallery.com/photos/'
|
2017-05-25 11:43:03 +00:00
|
|
|
})
|
|
|
|
should(o.download).eql({
|
|
|
|
path: 'http://mygallery.com/photos/holidays/beach.jpg',
|
|
|
|
rel: 'fs:link'
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
2019-02-13 21:18:54 +00:00
|
|
|
|
|
|
|
describe('Output structure', function () {
|
|
|
|
it('defaults to the <folders> structure', function () {
|
|
|
|
const o = output.paths('holidays/beach.jpg', 'image', {})
|
|
|
|
should(o.download).eql({
|
|
|
|
path: 'media/large/holidays/beach.jpg',
|
|
|
|
rel: 'photo:large'
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it('can explicitely choose the <folders> structure', function () {
|
|
|
|
const o = output.paths('holidays/beach.jpg', 'image', {
|
|
|
|
outputStructure: 'folders'
|
|
|
|
})
|
|
|
|
should(o.download).eql({
|
|
|
|
path: 'media/large/holidays/beach.jpg',
|
|
|
|
rel: 'photo:large'
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it('can choose the <suffix> structure', function () {
|
|
|
|
const o = output.paths('holidays/beach.jpg', 'image', {
|
|
|
|
outputStructure: 'suffix'
|
|
|
|
})
|
|
|
|
should(o.download).eql({
|
|
|
|
path: 'media/holidays/beach_jpg_large.jpg',
|
|
|
|
rel: 'photo:large'
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it('throws an error for invalid values', function () {
|
|
|
|
should.throws(function () {
|
|
|
|
output.paths('holidays/beach.jpg', 'image', {
|
|
|
|
outputStructure: 'unknown'
|
|
|
|
})
|
|
|
|
}, /Invalid output structure: unknown/)
|
|
|
|
})
|
|
|
|
})
|
2017-05-25 11:43:03 +00:00
|
|
|
})
|