mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-20 17:32:15 +03:00
c487b12518
refs https://github.com/TryGhost/Toolbox/issues/523
- The reverted fix did not take into account the "original path" of the
files would be truncated. This path has to be full relative to the root
of the zip to later be used during importer url substitution logic.
- This reverts commit 831a76505c
.
93 lines
3.4 KiB
JavaScript
93 lines
3.4 KiB
JavaScript
const assert = require('assert');
|
|
const ImporterContentFileHandler = require('../index');
|
|
|
|
describe('ImporterContentFileHandler', function () {
|
|
it('creates an instance', function () {
|
|
const contentFileImporter = new ImporterContentFileHandler({
|
|
type: 'media',
|
|
storage: {},
|
|
config: {},
|
|
urlUtils: {}
|
|
});
|
|
|
|
assert.ok(contentFileImporter);
|
|
assert.equal(contentFileImporter.type, 'media');
|
|
});
|
|
|
|
it('returns configured extensions', function () {
|
|
const contentFileImporter = new ImporterContentFileHandler({
|
|
storage: {},
|
|
extensions: ['mp4'],
|
|
urlUtils: {}
|
|
});
|
|
|
|
assert.deepEqual(contentFileImporter.extensions, ['mp4']);
|
|
});
|
|
|
|
it('returns configured contentTypes', function () {
|
|
const contentFileImporter = new ImporterContentFileHandler({
|
|
storage: {},
|
|
contentTypes: ['video/mp4'],
|
|
urlUtils: {}
|
|
});
|
|
|
|
assert.deepEqual(contentFileImporter.contentTypes, ['video/mp4']);
|
|
});
|
|
|
|
// @NOTE: below tests need more work, they are just covering the basics
|
|
// the cases are based on a fact that the implementation was a copy
|
|
// from the image importer and the tests were adapted to the media importer
|
|
describe('loadFile', function () {
|
|
it('loads files and decorates them with newPath with subdirectory', async function () {
|
|
const contentFileImporter = new ImporterContentFileHandler({
|
|
storage: {
|
|
staticFileURLPrefix: 'content/media',
|
|
getUniqueFileName: (file, targetDir) => Promise.resolve(targetDir + '/' + file.name)
|
|
},
|
|
contentPath: '/var/www/ghost/content/media',
|
|
urlUtils: {
|
|
getSubdir: () => 'blog',
|
|
urlJoin: (...args) => args.join('/')
|
|
}
|
|
});
|
|
|
|
const files = [{
|
|
name: 'content/media/1.mp4'
|
|
}];
|
|
const subDir = 'blog';
|
|
|
|
await contentFileImporter.loadFile(files, subDir);
|
|
|
|
assert.equal(files[0].name, '1.mp4');
|
|
assert.equal(files[0].originalPath, 'content/media/1.mp4');
|
|
assert.equal(files[0].targetDir, '/var/www/ghost/content/media');
|
|
assert.equal(files[0].newPath, '//blog/content/media/1.mp4');
|
|
});
|
|
|
|
it('loads files and decorates them with newPath with NO subdirectory', async function () {
|
|
const contentFileImporter = new ImporterContentFileHandler({
|
|
storage: {
|
|
staticFileURLPrefix: 'content/media',
|
|
getUniqueFileName: (file, targetDir) => Promise.resolve(targetDir + '/' + file.name)
|
|
},
|
|
contentPath: '/var/www/ghost/content/media',
|
|
urlUtils: {
|
|
getSubdir: () => 'blog',
|
|
urlJoin: (...args) => args.join('/')
|
|
}
|
|
});
|
|
|
|
const files = [{
|
|
name: 'content/media/1.mp4'
|
|
}];
|
|
|
|
await contentFileImporter.loadFile(files);
|
|
|
|
assert.equal(files[0].name, '1.mp4');
|
|
assert.equal(files[0].originalPath, 'content/media/1.mp4');
|
|
assert.equal(files[0].targetDir, '/var/www/ghost/content/media');
|
|
assert.equal(files[0].newPath, '//blog/content/media/1.mp4');
|
|
});
|
|
});
|
|
});
|