2017-03-21 11:24:11 +03:00
|
|
|
var should = require('should'),
|
|
|
|
sinon = require('sinon'),
|
2019-06-18 16:13:55 +03:00
|
|
|
rewire = require('rewire'),
|
2017-03-21 11:24:11 +03:00
|
|
|
Promise = require('bluebird'),
|
|
|
|
_ = require('lodash'),
|
2017-05-23 19:18:13 +03:00
|
|
|
testUtils = require('../../../utils'),
|
2017-03-21 11:24:11 +03:00
|
|
|
moment = require('moment'),
|
|
|
|
path = require('path'),
|
2020-03-30 18:26:47 +03:00
|
|
|
common = require('../../../../core/server/lib/common'),
|
2014-12-11 00:50:00 +03:00
|
|
|
|
|
|
|
// Stuff we are testing
|
2020-03-30 18:26:47 +03:00
|
|
|
ImportManager = require('../../../../core/server/data/importer'),
|
|
|
|
JSONHandler = require('../../../../core/server/data/importer/handlers/json'),
|
|
|
|
ImageHandler = rewire('../../../../core/server/data/importer/handlers/image'),
|
|
|
|
MarkdownHandler = require('../../../../core/server/data/importer/handlers/markdown'),
|
|
|
|
DataImporter = require('../../../../core/server/data/importer/importers/data'),
|
|
|
|
ImageImporter = require('../../../../core/server/data/importer/importers/image'),
|
2014-12-11 00:50:00 +03:00
|
|
|
|
2020-03-30 18:26:47 +03:00
|
|
|
storage = require('../../../../core/server/adapters/storage'),
|
2015-12-14 23:05:11 +03:00
|
|
|
|
2019-06-18 16:13:55 +03:00
|
|
|
urlUtils = require('../../../utils/urlUtils');
|
2014-12-11 00:50:00 +03:00
|
|
|
|
|
|
|
describe('Importer', function () {
|
|
|
|
afterEach(function () {
|
2019-01-21 19:53:44 +03:00
|
|
|
sinon.restore();
|
2020-03-30 18:26:47 +03:00
|
|
|
ImageHandler = rewire('../../../../core/server/data/importer/handlers/image');
|
2014-12-11 00:50:00 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('ImportManager', function () {
|
|
|
|
it('has the correct interface', function () {
|
2014-12-21 02:48:13 +03:00
|
|
|
ImportManager.handlers.should.be.instanceof(Array).and.have.lengthOf(3);
|
2014-12-14 14:31:00 +03:00
|
|
|
ImportManager.importers.should.be.instanceof(Array).and.have.lengthOf(2);
|
2014-12-11 00:50:00 +03:00
|
|
|
ImportManager.loadFile.should.be.instanceof(Function);
|
|
|
|
ImportManager.preProcess.should.be.instanceof(Function);
|
|
|
|
ImportManager.doImport.should.be.instanceof(Function);
|
|
|
|
ImportManager.generateReport.should.be.instanceof(Function);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('gets the correct extensions', function () {
|
2019-07-01 09:29:24 +03:00
|
|
|
ImportManager.getExtensions().should.be.instanceof(Array).and.have.lengthOf(11);
|
2014-12-11 00:50:00 +03:00
|
|
|
ImportManager.getExtensions().should.containEql('.json');
|
|
|
|
ImportManager.getExtensions().should.containEql('.zip');
|
2014-12-14 14:31:00 +03:00
|
|
|
ImportManager.getExtensions().should.containEql('.jpg');
|
2014-12-21 02:48:13 +03:00
|
|
|
ImportManager.getExtensions().should.containEql('.md');
|
2014-12-11 00:50:00 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
it('gets the correct types', function () {
|
2019-07-01 09:29:24 +03:00
|
|
|
ImportManager.getContentTypes().should.be.instanceof(Array).and.have.lengthOf(12);
|
2016-08-18 22:25:51 +03:00
|
|
|
ImportManager.getContentTypes().should.containEql('application/octet-stream');
|
|
|
|
ImportManager.getContentTypes().should.containEql('application/json');
|
|
|
|
ImportManager.getContentTypes().should.containEql('application/zip');
|
|
|
|
ImportManager.getContentTypes().should.containEql('application/x-zip-compressed');
|
|
|
|
ImportManager.getContentTypes().should.containEql('text/plain');
|
2014-12-11 00:50:00 +03:00
|
|
|
});
|
|
|
|
|
2014-12-29 21:33:47 +03:00
|
|
|
it('gets the correct directories', function () {
|
|
|
|
ImportManager.getDirectories().should.be.instanceof(Array).and.have.lengthOf(2);
|
|
|
|
ImportManager.getDirectories().should.containEql('images');
|
|
|
|
ImportManager.getDirectories().should.containEql('content');
|
|
|
|
});
|
|
|
|
|
2014-12-11 00:50:00 +03:00
|
|
|
it('globs extensions correctly', function () {
|
2014-12-21 02:48:13 +03:00
|
|
|
ImportManager.getGlobPattern(ImportManager.getExtensions())
|
2019-07-01 09:29:24 +03:00
|
|
|
.should.equal('+(.jpg|.jpeg|.gif|.png|.svg|.svgz|.ico|.json|.md|.markdown|.zip)');
|
2014-12-21 02:48:13 +03:00
|
|
|
ImportManager.getGlobPattern(ImportManager.getDirectories())
|
|
|
|
.should.equal('+(images|content)');
|
|
|
|
ImportManager.getGlobPattern(JSONHandler.extensions)
|
|
|
|
.should.equal('+(.json)');
|
|
|
|
ImportManager.getGlobPattern(ImageHandler.extensions)
|
2019-07-01 09:29:24 +03:00
|
|
|
.should.equal('+(.jpg|.jpeg|.gif|.png|.svg|.svgz|.ico)');
|
2014-12-21 02:48:13 +03:00
|
|
|
ImportManager.getExtensionGlob(ImportManager.getExtensions())
|
2019-07-01 09:29:24 +03:00
|
|
|
.should.equal('*+(.jpg|.jpeg|.gif|.png|.svg|.svgz|.ico|.json|.md|.markdown|.zip)');
|
2014-12-21 02:48:13 +03:00
|
|
|
ImportManager.getDirectoryGlob(ImportManager.getDirectories())
|
|
|
|
.should.equal('+(images|content)');
|
|
|
|
ImportManager.getExtensionGlob(ImportManager.getExtensions(), 0)
|
2019-07-01 09:29:24 +03:00
|
|
|
.should.equal('*+(.jpg|.jpeg|.gif|.png|.svg|.svgz|.ico|.json|.md|.markdown|.zip)');
|
2014-12-21 02:48:13 +03:00
|
|
|
ImportManager.getDirectoryGlob(ImportManager.getDirectories(), 0)
|
|
|
|
.should.equal('+(images|content)');
|
|
|
|
ImportManager.getExtensionGlob(ImportManager.getExtensions(), 1)
|
2019-07-01 09:29:24 +03:00
|
|
|
.should.equal('{*/*,*}+(.jpg|.jpeg|.gif|.png|.svg|.svgz|.ico|.json|.md|.markdown|.zip)');
|
2014-12-21 02:48:13 +03:00
|
|
|
ImportManager.getDirectoryGlob(ImportManager.getDirectories(), 1)
|
|
|
|
.should.equal('{*/,}+(images|content)');
|
|
|
|
ImportManager.getExtensionGlob(ImportManager.getExtensions(), 2)
|
2019-07-01 09:29:24 +03:00
|
|
|
.should.equal('**/*+(.jpg|.jpeg|.gif|.png|.svg|.svgz|.ico|.json|.md|.markdown|.zip)');
|
2014-12-21 02:48:13 +03:00
|
|
|
ImportManager.getDirectoryGlob(ImportManager.getDirectories(), 2)
|
|
|
|
.should.equal('**/+(images|content)');
|
2014-12-11 00:50:00 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
// Step 1 of importing is loadFile
|
|
|
|
describe('loadFile', function () {
|
|
|
|
it('knows when to process a file', function (done) {
|
|
|
|
var testFile = {name: 'myFile.json', path: '/my/path/myFile.json'},
|
2019-01-21 19:53:44 +03:00
|
|
|
zipSpy = sinon.stub(ImportManager, 'processZip').returns(Promise.resolve()),
|
|
|
|
fileSpy = sinon.stub(ImportManager, 'processFile').returns(Promise.resolve());
|
2014-12-11 00:50:00 +03:00
|
|
|
|
|
|
|
ImportManager.loadFile(testFile).then(function () {
|
2016-02-08 00:27:01 +03:00
|
|
|
zipSpy.calledOnce.should.be.false();
|
|
|
|
fileSpy.calledOnce.should.be.true();
|
2014-12-11 00:50:00 +03:00
|
|
|
done();
|
2015-01-04 00:11:40 +03:00
|
|
|
}).catch(done);
|
2014-12-11 00:50:00 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
// We need to make sure we don't actually extract a zip and leave temporary files everywhere!
|
|
|
|
it('knows when to process a zip', function (done) {
|
|
|
|
var testZip = {name: 'myFile.zip', path: '/my/path/myFile.zip'},
|
2019-01-21 19:53:44 +03:00
|
|
|
zipSpy = sinon.stub(ImportManager, 'processZip').returns(Promise.resolve()),
|
|
|
|
fileSpy = sinon.stub(ImportManager, 'processFile').returns(Promise.resolve());
|
2014-12-11 00:50:00 +03:00
|
|
|
|
|
|
|
ImportManager.loadFile(testZip).then(function () {
|
2016-02-08 00:27:01 +03:00
|
|
|
zipSpy.calledOnce.should.be.true();
|
|
|
|
fileSpy.calledOnce.should.be.false();
|
2014-12-11 00:50:00 +03:00
|
|
|
done();
|
2015-01-04 00:11:40 +03:00
|
|
|
}).catch(done);
|
2014-12-11 00:50:00 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
it('has same result for zips and files', function (done) {
|
|
|
|
var testFile = {name: 'myFile.json', path: '/my/path/myFile.json'},
|
|
|
|
testZip = {name: 'myFile.zip', path: '/my/path/myFile.zip'},
|
|
|
|
// need to stub out the extract and glob function for zip
|
2019-01-21 19:53:44 +03:00
|
|
|
extractSpy = sinon.stub(ImportManager, 'extractZip').returns(Promise.resolve('/tmp/dir/')),
|
|
|
|
validSpy = sinon.stub(ImportManager, 'isValidZip').returns(true),
|
|
|
|
baseDirSpy = sinon.stub(ImportManager, 'getBaseDirectory').returns(),
|
|
|
|
getFileSpy = sinon.stub(ImportManager, 'getFilesFromZip'),
|
|
|
|
jsonSpy = sinon.stub(JSONHandler, 'loadFile').returns(Promise.resolve({posts: []})),
|
|
|
|
imageSpy = sinon.stub(ImageHandler, 'loadFile'),
|
|
|
|
mdSpy = sinon.stub(MarkdownHandler, 'loadFile');
|
2014-12-11 00:50:00 +03:00
|
|
|
|
2019-06-18 16:13:55 +03:00
|
|
|
getFileSpy.returns([]);
|
2014-12-14 14:31:00 +03:00
|
|
|
getFileSpy.withArgs(JSONHandler).returns(['/tmp/dir/myFile.json']);
|
|
|
|
|
2014-12-11 00:50:00 +03:00
|
|
|
ImportManager.processZip(testZip).then(function (zipResult) {
|
2016-02-08 00:27:01 +03:00
|
|
|
extractSpy.calledOnce.should.be.true();
|
|
|
|
validSpy.calledOnce.should.be.true();
|
|
|
|
baseDirSpy.calledOnce.should.be.true();
|
|
|
|
getFileSpy.calledThrice.should.be.true();
|
|
|
|
jsonSpy.calledOnce.should.be.true();
|
|
|
|
imageSpy.called.should.be.false();
|
|
|
|
mdSpy.called.should.be.false();
|
2014-12-11 00:50:00 +03:00
|
|
|
|
|
|
|
ImportManager.processFile(testFile, '.json').then(function (fileResult) {
|
2016-02-08 00:27:01 +03:00
|
|
|
jsonSpy.calledTwice.should.be.true();
|
2014-12-11 00:50:00 +03:00
|
|
|
|
|
|
|
// They should both have data keys, and they should be equivalent
|
|
|
|
zipResult.should.have.property('data');
|
|
|
|
fileResult.should.have.property('data');
|
|
|
|
zipResult.should.eql(fileResult);
|
|
|
|
done();
|
|
|
|
});
|
2015-01-04 00:11:40 +03:00
|
|
|
}).catch(done);
|
2014-12-11 00:50:00 +03:00
|
|
|
});
|
2014-12-29 21:33:47 +03:00
|
|
|
|
|
|
|
describe('Validate Zip', function () {
|
2015-01-04 00:11:40 +03:00
|
|
|
it('accepts a zip with a base directory', function () {
|
2020-03-30 18:26:47 +03:00
|
|
|
var testDir = path.resolve('test/utils/fixtures/import/zips/zip-with-base-dir');
|
2015-01-04 00:11:40 +03:00
|
|
|
|
2016-02-08 00:27:01 +03:00
|
|
|
ImportManager.isValidZip(testDir).should.be.ok();
|
2014-12-29 21:33:47 +03:00
|
|
|
});
|
|
|
|
|
2015-01-04 00:11:40 +03:00
|
|
|
it('accepts a zip without a base directory', function () {
|
2020-03-30 18:26:47 +03:00
|
|
|
var testDir = path.resolve('test/utils/fixtures/import/zips/zip-without-base-dir');
|
2015-01-04 00:11:40 +03:00
|
|
|
|
2016-02-08 00:27:01 +03:00
|
|
|
ImportManager.isValidZip(testDir).should.be.ok();
|
2014-12-29 21:33:47 +03:00
|
|
|
});
|
|
|
|
|
2015-01-04 00:11:40 +03:00
|
|
|
it('accepts a zip with an image directory', function () {
|
2020-03-30 18:26:47 +03:00
|
|
|
var testDir = path.resolve('test/utils/fixtures/import/zips/zip-image-dir');
|
2015-01-04 00:11:40 +03:00
|
|
|
|
2016-02-08 00:27:01 +03:00
|
|
|
ImportManager.isValidZip(testDir).should.be.ok();
|
2014-12-29 21:33:47 +03:00
|
|
|
});
|
|
|
|
|
2015-01-04 00:11:40 +03:00
|
|
|
it('fails a zip with two base directories', function () {
|
2020-03-30 18:26:47 +03:00
|
|
|
var testDir = path.resolve('test/utils/fixtures/import/zips/zip-with-double-base-dir');
|
2015-01-04 00:11:40 +03:00
|
|
|
|
2017-12-12 00:47:46 +03:00
|
|
|
ImportManager.isValidZip.bind(ImportManager, testDir).should.throw(common.errors.UnsupportedMediaTypeError);
|
2014-12-29 21:33:47 +03:00
|
|
|
});
|
|
|
|
|
2015-01-04 00:11:40 +03:00
|
|
|
it('fails a zip with no content', function () {
|
2020-03-30 18:26:47 +03:00
|
|
|
var testDir = path.resolve('test/utils/fixtures/import/zips/zip-invalid');
|
2015-01-04 00:11:40 +03:00
|
|
|
|
2017-12-12 00:47:46 +03:00
|
|
|
ImportManager.isValidZip.bind(ImportManager, testDir).should.throw(common.errors.UnsupportedMediaTypeError);
|
2014-12-29 21:33:47 +03:00
|
|
|
});
|
2014-12-21 02:48:13 +03:00
|
|
|
|
|
|
|
it('shows a special error for old Roon exports', function () {
|
2020-03-30 18:26:47 +03:00
|
|
|
var testDir = path.resolve('test/utils/fixtures/import/zips/zip-old-roon-export'),
|
2014-12-21 02:48:13 +03:00
|
|
|
msg = 'Your zip file looks like an old format Roon export, ' +
|
|
|
|
'please re-export your Roon blog and try again.';
|
|
|
|
|
2017-12-12 00:47:46 +03:00
|
|
|
ImportManager.isValidZip.bind(ImportManager, testDir).should.throw(common.errors.UnsupportedMediaTypeError);
|
2014-12-21 02:48:13 +03:00
|
|
|
ImportManager.isValidZip.bind(ImportManager, testDir).should.throw(msg);
|
|
|
|
});
|
2014-12-29 21:33:47 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('Get Base Dir', function () {
|
2015-01-04 00:11:40 +03:00
|
|
|
it('returns string for base directory', function () {
|
2020-03-30 18:26:47 +03:00
|
|
|
var testDir = path.resolve('test/utils/fixtures/import/zips/zip-with-base-dir');
|
2015-01-04 00:11:40 +03:00
|
|
|
|
|
|
|
ImportManager.getBaseDirectory(testDir).should.equal('basedir');
|
2014-12-29 21:33:47 +03:00
|
|
|
});
|
|
|
|
|
2015-01-04 00:11:40 +03:00
|
|
|
it('returns empty for no base directory', function () {
|
2020-03-30 18:26:47 +03:00
|
|
|
var testDir = path.resolve('test/utils/fixtures/import/zips/zip-without-base-dir');
|
2015-01-04 00:11:40 +03:00
|
|
|
|
|
|
|
should.not.exist(ImportManager.getBaseDirectory(testDir));
|
2014-12-29 21:33:47 +03:00
|
|
|
});
|
|
|
|
});
|
2020-04-15 15:23:45 +03:00
|
|
|
|
|
|
|
describe('Zip behaviour', function () {
|
|
|
|
it('can call extract and error correctly', function () {
|
|
|
|
return ImportManager
|
|
|
|
// Deliberately pass something that can't be extracted just to check this method signature is working
|
|
|
|
.extractZip('test/utils/fixtures/import/zips/zip-with-base-dir')
|
|
|
|
.then((res) => {
|
|
|
|
throw new Error('should have failed');
|
|
|
|
})
|
|
|
|
.catch((err) => {
|
|
|
|
err.message.should.match(/EISDIR/);
|
|
|
|
err.code.should.match(/EISDIR/);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2014-12-11 00:50:00 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
// Step 2 of importing is preProcess
|
|
|
|
describe('preProcess', function () {
|
|
|
|
// preProcess can modify the data prior to importing
|
|
|
|
it('calls the DataImporter preProcess method', function (done) {
|
|
|
|
var input = {data: {}, images: []},
|
|
|
|
// pass a copy so that input doesn't get modified
|
|
|
|
inputCopy = _.cloneDeep(input),
|
2019-01-21 19:53:44 +03:00
|
|
|
dataSpy = sinon.spy(DataImporter, 'preProcess'),
|
|
|
|
imageSpy = sinon.spy(ImageImporter, 'preProcess');
|
2014-12-11 00:50:00 +03:00
|
|
|
|
|
|
|
ImportManager.preProcess(inputCopy).then(function (output) {
|
2016-02-08 00:27:01 +03:00
|
|
|
dataSpy.calledOnce.should.be.true();
|
|
|
|
dataSpy.calledWith(inputCopy).should.be.true();
|
|
|
|
imageSpy.calledOnce.should.be.true();
|
|
|
|
imageSpy.calledWith(inputCopy).should.be.true();
|
2014-12-11 00:50:00 +03:00
|
|
|
// eql checks for equality
|
|
|
|
// equal checks the references are for the same object
|
|
|
|
output.should.not.equal(input);
|
|
|
|
output.should.have.property('preProcessedByData', true);
|
2014-12-29 21:33:47 +03:00
|
|
|
output.should.have.property('preProcessedByImage', true);
|
2014-12-11 00:50:00 +03:00
|
|
|
done();
|
2015-01-04 00:11:40 +03:00
|
|
|
}).catch(done);
|
2014-12-11 00:50:00 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
// Step 3 of importing is doImport
|
|
|
|
describe('doImport', function () {
|
|
|
|
// doImport calls the real importers and has an effect on the DB. We don't want any of those calls to be made,
|
|
|
|
// but to test that the right calls would be made
|
|
|
|
it('calls the DataImporter doImport method with the data object', function (done) {
|
|
|
|
var input = {data: {posts: []}, images: []},
|
|
|
|
// pass a copy so that input doesn't get modified
|
|
|
|
inputCopy = _.cloneDeep(input),
|
2019-01-21 19:53:44 +03:00
|
|
|
dataSpy = sinon.stub(DataImporter, 'doImport').callsFake(function (i) {
|
2014-12-11 00:50:00 +03:00
|
|
|
return Promise.resolve(i);
|
|
|
|
}),
|
2019-01-21 19:53:44 +03:00
|
|
|
imageSpy = sinon.stub(ImageImporter, 'doImport').callsFake(function (i) {
|
2014-12-14 14:31:00 +03:00
|
|
|
return Promise.resolve(i);
|
|
|
|
}),
|
2014-12-11 00:50:00 +03:00
|
|
|
|
|
|
|
// The data importer should get the data object
|
2014-12-14 14:31:00 +03:00
|
|
|
expectedData = input.data,
|
|
|
|
expectedImages = input.images;
|
2014-12-11 00:50:00 +03:00
|
|
|
|
|
|
|
ImportManager.doImport(inputCopy).then(function (output) {
|
|
|
|
// eql checks for equality
|
|
|
|
// equal checks the references are for the same object
|
2016-02-08 00:27:01 +03:00
|
|
|
dataSpy.calledOnce.should.be.true();
|
|
|
|
imageSpy.calledOnce.should.be.true();
|
2014-12-14 14:31:00 +03:00
|
|
|
dataSpy.getCall(0).args[0].should.eql(expectedData);
|
|
|
|
imageSpy.getCall(0).args[0].should.eql(expectedImages);
|
|
|
|
|
2014-12-11 00:50:00 +03:00
|
|
|
// we stubbed this as a noop but ImportManager calls with sequence, so we should get an array
|
2014-12-14 14:31:00 +03:00
|
|
|
output.should.eql([expectedImages, expectedData]);
|
2014-12-11 00:50:00 +03:00
|
|
|
done();
|
2015-01-04 00:11:40 +03:00
|
|
|
}).catch(done);
|
2014-12-11 00:50:00 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
// Step 4 of importing is generateReport
|
|
|
|
describe('generateReport', function () {
|
|
|
|
// generateReport is intended to create a message to show to the user about what has been imported
|
|
|
|
// it is currently a noop
|
|
|
|
it('is currently a noop', function (done) {
|
|
|
|
var input = {data: {}, images: []};
|
|
|
|
ImportManager.generateReport(input).then(function (output) {
|
|
|
|
output.should.equal(input);
|
|
|
|
done();
|
2015-01-04 00:11:40 +03:00
|
|
|
}).catch(done);
|
2014-12-11 00:50:00 +03:00
|
|
|
});
|
|
|
|
});
|
2014-12-29 21:33:47 +03:00
|
|
|
|
|
|
|
describe('importFromFile', function () {
|
|
|
|
it('does the import steps in order', function (done) {
|
2019-01-21 19:53:44 +03:00
|
|
|
var loadFileSpy = sinon.stub(ImportManager, 'loadFile').returns(Promise.resolve()),
|
|
|
|
preProcessSpy = sinon.stub(ImportManager, 'preProcess').returns(Promise.resolve()),
|
|
|
|
doImportSpy = sinon.stub(ImportManager, 'doImport').returns(Promise.resolve()),
|
|
|
|
generateReportSpy = sinon.stub(ImportManager, 'generateReport').returns(Promise.resolve()),
|
|
|
|
cleanupSpy = sinon.stub(ImportManager, 'cleanUp').returns({});
|
2014-12-29 21:33:47 +03:00
|
|
|
|
|
|
|
ImportManager.importFromFile({}).then(function () {
|
2016-02-08 00:27:01 +03:00
|
|
|
loadFileSpy.calledOnce.should.be.true();
|
|
|
|
preProcessSpy.calledOnce.should.be.true();
|
|
|
|
doImportSpy.calledOnce.should.be.true();
|
|
|
|
generateReportSpy.calledOnce.should.be.true();
|
|
|
|
cleanupSpy.calledOnce.should.be.true();
|
2014-12-29 21:33:47 +03:00
|
|
|
sinon.assert.callOrder(loadFileSpy, preProcessSpy, doImportSpy, generateReportSpy, cleanupSpy);
|
|
|
|
|
|
|
|
done();
|
2015-01-04 00:11:40 +03:00
|
|
|
}).catch(done);
|
2014-12-29 21:33:47 +03:00
|
|
|
});
|
|
|
|
});
|
2014-12-11 00:50:00 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('JSONHandler', function () {
|
|
|
|
it('has the correct interface', function () {
|
|
|
|
JSONHandler.type.should.eql('data');
|
|
|
|
JSONHandler.extensions.should.be.instanceof(Array).and.have.lengthOf(1);
|
|
|
|
JSONHandler.extensions.should.containEql('.json');
|
2016-08-18 22:25:51 +03:00
|
|
|
JSONHandler.contentTypes.should.be.instanceof(Array).and.have.lengthOf(2);
|
|
|
|
JSONHandler.contentTypes.should.containEql('application/octet-stream');
|
|
|
|
JSONHandler.contentTypes.should.containEql('application/json');
|
2014-12-11 00:50:00 +03:00
|
|
|
JSONHandler.loadFile.should.be.instanceof(Function);
|
|
|
|
});
|
2014-12-11 18:50:10 +03:00
|
|
|
|
|
|
|
it('correctly handles a valid db api wrapper', function (done) {
|
|
|
|
var file = [{
|
2018-07-19 13:26:47 +03:00
|
|
|
path: testUtils.fixtures.getExportFixturePath('valid'),
|
|
|
|
name: 'valid.json'
|
2014-12-11 18:50:10 +03:00
|
|
|
}];
|
|
|
|
JSONHandler.loadFile(file).then(function (result) {
|
|
|
|
_.keys(result).should.containEql('meta');
|
|
|
|
_.keys(result).should.containEql('data');
|
|
|
|
done();
|
2015-01-04 00:11:40 +03:00
|
|
|
}).catch(done);
|
2014-12-11 18:50:10 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
it('correctly errors when given a bad db api wrapper', function (done) {
|
|
|
|
var file = [{
|
2018-07-19 13:26:47 +03:00
|
|
|
path: testUtils.fixtures.getExportFixturePath('broken'),
|
|
|
|
name: 'broken.json'
|
2014-12-11 18:50:10 +03:00
|
|
|
}];
|
|
|
|
|
|
|
|
JSONHandler.loadFile(file).then(function () {
|
|
|
|
done(new Error('Didn\'t error for bad db api wrapper'));
|
|
|
|
}).catch(function (response) {
|
2015-04-22 23:29:45 +03:00
|
|
|
response.errorType.should.equal('BadRequestError');
|
2014-12-11 18:50:10 +03:00
|
|
|
done();
|
2015-01-04 00:11:40 +03:00
|
|
|
}).catch(done);
|
2014-12-11 18:50:10 +03:00
|
|
|
});
|
2014-12-11 00:50:00 +03:00
|
|
|
});
|
|
|
|
|
2014-12-14 14:31:00 +03:00
|
|
|
describe('ImageHandler', function () {
|
2015-12-14 23:05:11 +03:00
|
|
|
var store = storage.getStorage();
|
2014-12-14 14:31:00 +03:00
|
|
|
|
|
|
|
it('has the correct interface', function () {
|
|
|
|
ImageHandler.type.should.eql('images');
|
2019-07-01 09:29:24 +03:00
|
|
|
ImageHandler.extensions.should.be.instanceof(Array).and.have.lengthOf(7);
|
2014-12-14 14:31:00 +03:00
|
|
|
ImageHandler.extensions.should.containEql('.jpg');
|
|
|
|
ImageHandler.extensions.should.containEql('.jpeg');
|
|
|
|
ImageHandler.extensions.should.containEql('.gif');
|
|
|
|
ImageHandler.extensions.should.containEql('.png');
|
|
|
|
ImageHandler.extensions.should.containEql('.svg');
|
|
|
|
ImageHandler.extensions.should.containEql('.svgz');
|
2019-07-01 09:29:24 +03:00
|
|
|
ImageHandler.extensions.should.containEql('.ico');
|
|
|
|
ImageHandler.contentTypes.should.be.instanceof(Array).and.have.lengthOf(6);
|
2016-08-18 22:25:51 +03:00
|
|
|
ImageHandler.contentTypes.should.containEql('image/jpeg');
|
|
|
|
ImageHandler.contentTypes.should.containEql('image/png');
|
|
|
|
ImageHandler.contentTypes.should.containEql('image/gif');
|
|
|
|
ImageHandler.contentTypes.should.containEql('image/svg+xml');
|
2019-07-01 09:29:24 +03:00
|
|
|
ImageHandler.contentTypes.should.containEql('image/x-icon');
|
|
|
|
ImageHandler.contentTypes.should.containEql('image/vnd.microsoft.icon');
|
2014-12-14 14:31:00 +03:00
|
|
|
ImageHandler.loadFile.should.be.instanceof(Function);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('can load a single file', function (done) {
|
|
|
|
var filename = 'test-image.jpeg',
|
|
|
|
file = [{
|
|
|
|
path: '/my/test/' + filename,
|
|
|
|
name: filename
|
|
|
|
}],
|
2019-01-21 19:53:44 +03:00
|
|
|
storeSpy = sinon.spy(store, 'getUniqueFileName'),
|
|
|
|
storageSpy = sinon.spy(storage, 'getStorage');
|
2014-12-14 14:31:00 +03:00
|
|
|
|
|
|
|
ImageHandler.loadFile(_.clone(file)).then(function () {
|
2016-02-08 00:27:01 +03:00
|
|
|
storageSpy.calledOnce.should.be.true();
|
|
|
|
storeSpy.calledOnce.should.be.true();
|
😱 🎨 Refactor storage adapter (#8229)
refs #7687
There are four main changes in this PR:
we have outsourced the base storage adapter to npm, because for storage developers it's annoying to inherit from a script within Ghost
we hacked theme storage handling into the default local storage adapter - this was reverted, instead we have added a static theme storage here
use classes instead of prototyping
optimise the storage adapter in general - everything is explained in each commit
----
* rename local-file-store to LocalFileStorage
I would like to keep the name pattern i have used for scheduling.
If a file is a class, the file name reflects the class name.
We can discuss this, if concerns are raised.
* Transform LocalFileStorage to class and inherit from new base
- inherit from npm ghost-storage-base
- rewrite to class
- no further refactoring, happens later
* Rename core/test/unit/storage/local-file-store_spec.js -> core/test/unit/storage/LocalFileStorage_spec.js
* Fix wrong require in core/test/unit/storage/LocalFileStorage_spec.js
* remove base storage and test
- see https://github.com/kirrg001/Ghost-Storage-Base
- the test has moved to this repo as well
* Use npm ghost-storage-base in storage/index.js
* remove the concept of getStorage('themes')
This concept was added when we added themes as a feature.
Back then, we have changed the local storage adapter to support images and themes.
This has added some hacks into the local storage adapters.
We want to revert this change and add a simple static theme storage.
Will adapt the api/themes layer in the next commits.
* Revert LocalFileStorage
- revert serve
- revert delete
* add storagePath as property to LocalFileStorage
- define one property which holds the storage path
- could be considered to pass from outside, but found that not helpful, as other storage adapters do not need this property
- IMPORTANT: save has no longer a targetDir option, because this was used to pass the alternative theme storage path
- IMPORTANT: exists has now an alternative targetDir, this makes sense, because
- you can either ask the storage exists('my-file') and it will look in the base storage path
- or you pass a specific path where to look exists('my-file', /path/to/dir)
* LocalFileStorage: get rid of store pattern
- getUniqueFileName(THIS)
- this doesn't make sense, instances always have access to this by default
* Add static theme storage
- inherits from the local file storage, because they both operate on the file system
- IMPORTANT: added a TODO to consider a merge of themes/loader and themes/storage
- but will be definitely not part of this PR
* Use new static theme storage in api/themes
- storage functions are simplified!
* Add https://github.com/kirrg001/Ghost-Storage-Base as dependency
- tarball for now, as i am still testing
- will release if PR review get's accepted
* Adapt tests and jscs/jshint
* 🐛 fix storage.read in favicon utility
- wrong implementation of error handling
* 🎨 optimise error messages for custom storage adapter errors
* little renaming in the storage utlity
- purpose is to have access to the custom storage instance and to the custom storage class
- see next commit why
* optimise instanceof base storage
- instanceof is always tricky in javascript
- if multiple modules exist, it can happen that instanceof is false
* fix getTargetDir
- the importer uses the `targetDir` option to ensure that images land in the correct folder
* ghost-storage-base@0.0.1 package.json dependency
2017-04-05 17:10:34 +03:00
|
|
|
storeSpy.firstCall.args[0].originalPath.should.equal('test-image.jpeg');
|
|
|
|
storeSpy.firstCall.args[0].targetDir.should.match(/(\/|\\)content(\/|\\)images$/);
|
|
|
|
storeSpy.firstCall.args[0].newPath.should.eql('/content/images/test-image.jpeg');
|
2014-12-14 14:31:00 +03:00
|
|
|
|
|
|
|
done();
|
2015-01-04 00:11:40 +03:00
|
|
|
}).catch(done);
|
2014-12-14 14:31:00 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
it('can load a single file, maintaining structure', function (done) {
|
|
|
|
var filename = 'photos/my-cat.jpeg',
|
|
|
|
file = [{
|
|
|
|
path: '/my/test/' + filename,
|
|
|
|
name: filename
|
|
|
|
}],
|
2019-01-21 19:53:44 +03:00
|
|
|
storeSpy = sinon.spy(store, 'getUniqueFileName'),
|
|
|
|
storageSpy = sinon.spy(storage, 'getStorage');
|
2014-12-14 14:31:00 +03:00
|
|
|
|
|
|
|
ImageHandler.loadFile(_.clone(file)).then(function () {
|
2016-02-08 00:27:01 +03:00
|
|
|
storageSpy.calledOnce.should.be.true();
|
|
|
|
storeSpy.calledOnce.should.be.true();
|
😱 🎨 Refactor storage adapter (#8229)
refs #7687
There are four main changes in this PR:
we have outsourced the base storage adapter to npm, because for storage developers it's annoying to inherit from a script within Ghost
we hacked theme storage handling into the default local storage adapter - this was reverted, instead we have added a static theme storage here
use classes instead of prototyping
optimise the storage adapter in general - everything is explained in each commit
----
* rename local-file-store to LocalFileStorage
I would like to keep the name pattern i have used for scheduling.
If a file is a class, the file name reflects the class name.
We can discuss this, if concerns are raised.
* Transform LocalFileStorage to class and inherit from new base
- inherit from npm ghost-storage-base
- rewrite to class
- no further refactoring, happens later
* Rename core/test/unit/storage/local-file-store_spec.js -> core/test/unit/storage/LocalFileStorage_spec.js
* Fix wrong require in core/test/unit/storage/LocalFileStorage_spec.js
* remove base storage and test
- see https://github.com/kirrg001/Ghost-Storage-Base
- the test has moved to this repo as well
* Use npm ghost-storage-base in storage/index.js
* remove the concept of getStorage('themes')
This concept was added when we added themes as a feature.
Back then, we have changed the local storage adapter to support images and themes.
This has added some hacks into the local storage adapters.
We want to revert this change and add a simple static theme storage.
Will adapt the api/themes layer in the next commits.
* Revert LocalFileStorage
- revert serve
- revert delete
* add storagePath as property to LocalFileStorage
- define one property which holds the storage path
- could be considered to pass from outside, but found that not helpful, as other storage adapters do not need this property
- IMPORTANT: save has no longer a targetDir option, because this was used to pass the alternative theme storage path
- IMPORTANT: exists has now an alternative targetDir, this makes sense, because
- you can either ask the storage exists('my-file') and it will look in the base storage path
- or you pass a specific path where to look exists('my-file', /path/to/dir)
* LocalFileStorage: get rid of store pattern
- getUniqueFileName(THIS)
- this doesn't make sense, instances always have access to this by default
* Add static theme storage
- inherits from the local file storage, because they both operate on the file system
- IMPORTANT: added a TODO to consider a merge of themes/loader and themes/storage
- but will be definitely not part of this PR
* Use new static theme storage in api/themes
- storage functions are simplified!
* Add https://github.com/kirrg001/Ghost-Storage-Base as dependency
- tarball for now, as i am still testing
- will release if PR review get's accepted
* Adapt tests and jscs/jshint
* 🐛 fix storage.read in favicon utility
- wrong implementation of error handling
* 🎨 optimise error messages for custom storage adapter errors
* little renaming in the storage utlity
- purpose is to have access to the custom storage instance and to the custom storage class
- see next commit why
* optimise instanceof base storage
- instanceof is always tricky in javascript
- if multiple modules exist, it can happen that instanceof is false
* fix getTargetDir
- the importer uses the `targetDir` option to ensure that images land in the correct folder
* ghost-storage-base@0.0.1 package.json dependency
2017-04-05 17:10:34 +03:00
|
|
|
storeSpy.firstCall.args[0].originalPath.should.equal('photos/my-cat.jpeg');
|
|
|
|
storeSpy.firstCall.args[0].targetDir.should.match(/(\/|\\)content(\/|\\)images(\/|\\)photos$/);
|
|
|
|
storeSpy.firstCall.args[0].newPath.should.eql('/content/images/photos/my-cat.jpeg');
|
2014-12-14 14:31:00 +03:00
|
|
|
|
|
|
|
done();
|
2015-01-04 00:11:40 +03:00
|
|
|
}).catch(done);
|
2014-12-14 14:31:00 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
it('can load a single file, removing ghost dirs', function (done) {
|
|
|
|
var filename = 'content/images/my-cat.jpeg',
|
|
|
|
file = [{
|
|
|
|
path: '/my/test/content/images/' + filename,
|
|
|
|
name: filename
|
|
|
|
}],
|
2019-01-21 19:53:44 +03:00
|
|
|
storeSpy = sinon.spy(store, 'getUniqueFileName'),
|
|
|
|
storageSpy = sinon.spy(storage, 'getStorage');
|
2014-12-14 14:31:00 +03:00
|
|
|
|
|
|
|
ImageHandler.loadFile(_.clone(file)).then(function () {
|
2016-02-08 00:27:01 +03:00
|
|
|
storageSpy.calledOnce.should.be.true();
|
|
|
|
storeSpy.calledOnce.should.be.true();
|
😱 🎨 Refactor storage adapter (#8229)
refs #7687
There are four main changes in this PR:
we have outsourced the base storage adapter to npm, because for storage developers it's annoying to inherit from a script within Ghost
we hacked theme storage handling into the default local storage adapter - this was reverted, instead we have added a static theme storage here
use classes instead of prototyping
optimise the storage adapter in general - everything is explained in each commit
----
* rename local-file-store to LocalFileStorage
I would like to keep the name pattern i have used for scheduling.
If a file is a class, the file name reflects the class name.
We can discuss this, if concerns are raised.
* Transform LocalFileStorage to class and inherit from new base
- inherit from npm ghost-storage-base
- rewrite to class
- no further refactoring, happens later
* Rename core/test/unit/storage/local-file-store_spec.js -> core/test/unit/storage/LocalFileStorage_spec.js
* Fix wrong require in core/test/unit/storage/LocalFileStorage_spec.js
* remove base storage and test
- see https://github.com/kirrg001/Ghost-Storage-Base
- the test has moved to this repo as well
* Use npm ghost-storage-base in storage/index.js
* remove the concept of getStorage('themes')
This concept was added when we added themes as a feature.
Back then, we have changed the local storage adapter to support images and themes.
This has added some hacks into the local storage adapters.
We want to revert this change and add a simple static theme storage.
Will adapt the api/themes layer in the next commits.
* Revert LocalFileStorage
- revert serve
- revert delete
* add storagePath as property to LocalFileStorage
- define one property which holds the storage path
- could be considered to pass from outside, but found that not helpful, as other storage adapters do not need this property
- IMPORTANT: save has no longer a targetDir option, because this was used to pass the alternative theme storage path
- IMPORTANT: exists has now an alternative targetDir, this makes sense, because
- you can either ask the storage exists('my-file') and it will look in the base storage path
- or you pass a specific path where to look exists('my-file', /path/to/dir)
* LocalFileStorage: get rid of store pattern
- getUniqueFileName(THIS)
- this doesn't make sense, instances always have access to this by default
* Add static theme storage
- inherits from the local file storage, because they both operate on the file system
- IMPORTANT: added a TODO to consider a merge of themes/loader and themes/storage
- but will be definitely not part of this PR
* Use new static theme storage in api/themes
- storage functions are simplified!
* Add https://github.com/kirrg001/Ghost-Storage-Base as dependency
- tarball for now, as i am still testing
- will release if PR review get's accepted
* Adapt tests and jscs/jshint
* 🐛 fix storage.read in favicon utility
- wrong implementation of error handling
* 🎨 optimise error messages for custom storage adapter errors
* little renaming in the storage utlity
- purpose is to have access to the custom storage instance and to the custom storage class
- see next commit why
* optimise instanceof base storage
- instanceof is always tricky in javascript
- if multiple modules exist, it can happen that instanceof is false
* fix getTargetDir
- the importer uses the `targetDir` option to ensure that images land in the correct folder
* ghost-storage-base@0.0.1 package.json dependency
2017-04-05 17:10:34 +03:00
|
|
|
storeSpy.firstCall.args[0].originalPath.should.equal('content/images/my-cat.jpeg');
|
|
|
|
storeSpy.firstCall.args[0].targetDir.should.match(/(\/|\\)content(\/|\\)images$/);
|
|
|
|
storeSpy.firstCall.args[0].newPath.should.eql('/content/images/my-cat.jpeg');
|
2014-12-14 14:31:00 +03:00
|
|
|
|
|
|
|
done();
|
2015-01-04 00:11:40 +03:00
|
|
|
}).catch(done);
|
2014-12-14 14:31:00 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
it('can load a file (subdirectory)', function (done) {
|
2019-08-12 11:31:42 +03:00
|
|
|
ImageHandler.__set__('urlUtils', urlUtils.getInstance({url: 'http://localhost:65535/subdir'}));
|
2014-12-14 14:31:00 +03:00
|
|
|
|
|
|
|
var filename = 'test-image.jpeg',
|
|
|
|
file = [{
|
|
|
|
path: '/my/test/' + filename,
|
|
|
|
name: filename
|
|
|
|
}],
|
2019-01-21 19:53:44 +03:00
|
|
|
storeSpy = sinon.spy(store, 'getUniqueFileName'),
|
|
|
|
storageSpy = sinon.spy(storage, 'getStorage');
|
2014-12-14 14:31:00 +03:00
|
|
|
|
|
|
|
ImageHandler.loadFile(_.clone(file)).then(function () {
|
2016-02-08 00:27:01 +03:00
|
|
|
storageSpy.calledOnce.should.be.true();
|
|
|
|
storeSpy.calledOnce.should.be.true();
|
😱 🎨 Refactor storage adapter (#8229)
refs #7687
There are four main changes in this PR:
we have outsourced the base storage adapter to npm, because for storage developers it's annoying to inherit from a script within Ghost
we hacked theme storage handling into the default local storage adapter - this was reverted, instead we have added a static theme storage here
use classes instead of prototyping
optimise the storage adapter in general - everything is explained in each commit
----
* rename local-file-store to LocalFileStorage
I would like to keep the name pattern i have used for scheduling.
If a file is a class, the file name reflects the class name.
We can discuss this, if concerns are raised.
* Transform LocalFileStorage to class and inherit from new base
- inherit from npm ghost-storage-base
- rewrite to class
- no further refactoring, happens later
* Rename core/test/unit/storage/local-file-store_spec.js -> core/test/unit/storage/LocalFileStorage_spec.js
* Fix wrong require in core/test/unit/storage/LocalFileStorage_spec.js
* remove base storage and test
- see https://github.com/kirrg001/Ghost-Storage-Base
- the test has moved to this repo as well
* Use npm ghost-storage-base in storage/index.js
* remove the concept of getStorage('themes')
This concept was added when we added themes as a feature.
Back then, we have changed the local storage adapter to support images and themes.
This has added some hacks into the local storage adapters.
We want to revert this change and add a simple static theme storage.
Will adapt the api/themes layer in the next commits.
* Revert LocalFileStorage
- revert serve
- revert delete
* add storagePath as property to LocalFileStorage
- define one property which holds the storage path
- could be considered to pass from outside, but found that not helpful, as other storage adapters do not need this property
- IMPORTANT: save has no longer a targetDir option, because this was used to pass the alternative theme storage path
- IMPORTANT: exists has now an alternative targetDir, this makes sense, because
- you can either ask the storage exists('my-file') and it will look in the base storage path
- or you pass a specific path where to look exists('my-file', /path/to/dir)
* LocalFileStorage: get rid of store pattern
- getUniqueFileName(THIS)
- this doesn't make sense, instances always have access to this by default
* Add static theme storage
- inherits from the local file storage, because they both operate on the file system
- IMPORTANT: added a TODO to consider a merge of themes/loader and themes/storage
- but will be definitely not part of this PR
* Use new static theme storage in api/themes
- storage functions are simplified!
* Add https://github.com/kirrg001/Ghost-Storage-Base as dependency
- tarball for now, as i am still testing
- will release if PR review get's accepted
* Adapt tests and jscs/jshint
* 🐛 fix storage.read in favicon utility
- wrong implementation of error handling
* 🎨 optimise error messages for custom storage adapter errors
* little renaming in the storage utlity
- purpose is to have access to the custom storage instance and to the custom storage class
- see next commit why
* optimise instanceof base storage
- instanceof is always tricky in javascript
- if multiple modules exist, it can happen that instanceof is false
* fix getTargetDir
- the importer uses the `targetDir` option to ensure that images land in the correct folder
* ghost-storage-base@0.0.1 package.json dependency
2017-04-05 17:10:34 +03:00
|
|
|
storeSpy.firstCall.args[0].originalPath.should.equal('test-image.jpeg');
|
|
|
|
storeSpy.firstCall.args[0].targetDir.should.match(/(\/|\\)content(\/|\\)images$/);
|
|
|
|
storeSpy.firstCall.args[0].newPath.should.eql('/subdir/content/images/test-image.jpeg');
|
2014-12-14 14:31:00 +03:00
|
|
|
|
|
|
|
done();
|
2015-01-04 00:11:40 +03:00
|
|
|
}).catch(done);
|
2014-12-14 14:31:00 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
it('can load multiple files', function (done) {
|
|
|
|
var files = [{
|
|
|
|
path: '/my/test/testing.png',
|
|
|
|
name: 'testing.png'
|
|
|
|
},
|
2019-08-19 14:41:09 +03:00
|
|
|
{
|
|
|
|
path: '/my/test/photo/kitten.jpg',
|
|
|
|
name: 'photo/kitten.jpg'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
path: '/my/test/content/images/animated/bunny.gif',
|
|
|
|
name: 'content/images/animated/bunny.gif'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
path: '/my/test/images/puppy.jpg',
|
|
|
|
name: 'images/puppy.jpg'
|
|
|
|
}],
|
2019-01-21 19:53:44 +03:00
|
|
|
storeSpy = sinon.spy(store, 'getUniqueFileName'),
|
|
|
|
storageSpy = sinon.spy(storage, 'getStorage');
|
2014-12-14 14:31:00 +03:00
|
|
|
|
|
|
|
ImageHandler.loadFile(_.clone(files)).then(function () {
|
2016-02-08 00:27:01 +03:00
|
|
|
storageSpy.calledOnce.should.be.true();
|
2014-12-14 14:31:00 +03:00
|
|
|
storeSpy.callCount.should.eql(4);
|
😱 🎨 Refactor storage adapter (#8229)
refs #7687
There are four main changes in this PR:
we have outsourced the base storage adapter to npm, because for storage developers it's annoying to inherit from a script within Ghost
we hacked theme storage handling into the default local storage adapter - this was reverted, instead we have added a static theme storage here
use classes instead of prototyping
optimise the storage adapter in general - everything is explained in each commit
----
* rename local-file-store to LocalFileStorage
I would like to keep the name pattern i have used for scheduling.
If a file is a class, the file name reflects the class name.
We can discuss this, if concerns are raised.
* Transform LocalFileStorage to class and inherit from new base
- inherit from npm ghost-storage-base
- rewrite to class
- no further refactoring, happens later
* Rename core/test/unit/storage/local-file-store_spec.js -> core/test/unit/storage/LocalFileStorage_spec.js
* Fix wrong require in core/test/unit/storage/LocalFileStorage_spec.js
* remove base storage and test
- see https://github.com/kirrg001/Ghost-Storage-Base
- the test has moved to this repo as well
* Use npm ghost-storage-base in storage/index.js
* remove the concept of getStorage('themes')
This concept was added when we added themes as a feature.
Back then, we have changed the local storage adapter to support images and themes.
This has added some hacks into the local storage adapters.
We want to revert this change and add a simple static theme storage.
Will adapt the api/themes layer in the next commits.
* Revert LocalFileStorage
- revert serve
- revert delete
* add storagePath as property to LocalFileStorage
- define one property which holds the storage path
- could be considered to pass from outside, but found that not helpful, as other storage adapters do not need this property
- IMPORTANT: save has no longer a targetDir option, because this was used to pass the alternative theme storage path
- IMPORTANT: exists has now an alternative targetDir, this makes sense, because
- you can either ask the storage exists('my-file') and it will look in the base storage path
- or you pass a specific path where to look exists('my-file', /path/to/dir)
* LocalFileStorage: get rid of store pattern
- getUniqueFileName(THIS)
- this doesn't make sense, instances always have access to this by default
* Add static theme storage
- inherits from the local file storage, because they both operate on the file system
- IMPORTANT: added a TODO to consider a merge of themes/loader and themes/storage
- but will be definitely not part of this PR
* Use new static theme storage in api/themes
- storage functions are simplified!
* Add https://github.com/kirrg001/Ghost-Storage-Base as dependency
- tarball for now, as i am still testing
- will release if PR review get's accepted
* Adapt tests and jscs/jshint
* 🐛 fix storage.read in favicon utility
- wrong implementation of error handling
* 🎨 optimise error messages for custom storage adapter errors
* little renaming in the storage utlity
- purpose is to have access to the custom storage instance and to the custom storage class
- see next commit why
* optimise instanceof base storage
- instanceof is always tricky in javascript
- if multiple modules exist, it can happen that instanceof is false
* fix getTargetDir
- the importer uses the `targetDir` option to ensure that images land in the correct folder
* ghost-storage-base@0.0.1 package.json dependency
2017-04-05 17:10:34 +03:00
|
|
|
storeSpy.firstCall.args[0].originalPath.should.equal('testing.png');
|
|
|
|
storeSpy.firstCall.args[0].targetDir.should.match(/(\/|\\)content(\/|\\)images$/);
|
|
|
|
storeSpy.firstCall.args[0].newPath.should.eql('/content/images/testing.png');
|
|
|
|
storeSpy.secondCall.args[0].originalPath.should.equal('photo/kitten.jpg');
|
|
|
|
storeSpy.secondCall.args[0].targetDir.should.match(/(\/|\\)content(\/|\\)images(\/|\\)photo$/);
|
|
|
|
storeSpy.secondCall.args[0].newPath.should.eql('/content/images/photo/kitten.jpg');
|
|
|
|
storeSpy.thirdCall.args[0].originalPath.should.equal('content/images/animated/bunny.gif');
|
|
|
|
storeSpy.thirdCall.args[0].targetDir.should.match(/(\/|\\)content(\/|\\)images(\/|\\)animated$/);
|
|
|
|
storeSpy.thirdCall.args[0].newPath.should.eql('/content/images/animated/bunny.gif');
|
|
|
|
storeSpy.lastCall.args[0].originalPath.should.equal('images/puppy.jpg');
|
|
|
|
storeSpy.lastCall.args[0].targetDir.should.match(/(\/|\\)content(\/|\\)images$/);
|
|
|
|
storeSpy.lastCall.args[0].newPath.should.eql('/content/images/puppy.jpg');
|
2014-12-14 14:31:00 +03:00
|
|
|
|
2014-12-21 02:48:13 +03:00
|
|
|
done();
|
2015-01-18 23:24:41 +03:00
|
|
|
}).catch(done);
|
2014-12-21 02:48:13 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('MarkdownHandler', function () {
|
|
|
|
it('has the correct interface', function () {
|
|
|
|
MarkdownHandler.type.should.eql('data');
|
|
|
|
MarkdownHandler.extensions.should.be.instanceof(Array).and.have.lengthOf(2);
|
|
|
|
MarkdownHandler.extensions.should.containEql('.md');
|
|
|
|
MarkdownHandler.extensions.should.containEql('.markdown');
|
2016-08-18 22:25:51 +03:00
|
|
|
MarkdownHandler.contentTypes.should.be.instanceof(Array).and.have.lengthOf(2);
|
|
|
|
MarkdownHandler.contentTypes.should.containEql('application/octet-stream');
|
|
|
|
MarkdownHandler.contentTypes.should.containEql('text/plain');
|
2014-12-21 02:48:13 +03:00
|
|
|
MarkdownHandler.loadFile.should.be.instanceof(Function);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('does convert a markdown file into a post object', function (done) {
|
|
|
|
var filename = 'draft-2014-12-19-test-1.md',
|
|
|
|
file = [{
|
|
|
|
path: testUtils.fixtures.getImportFixturePath(filename),
|
|
|
|
name: filename
|
|
|
|
}];
|
|
|
|
|
|
|
|
MarkdownHandler.loadFile(file).then(function (result) {
|
|
|
|
result.data.posts[0].markdown.should.eql('You\'re live! Nice.');
|
|
|
|
result.data.posts[0].status.should.eql('draft');
|
|
|
|
result.data.posts[0].slug.should.eql('test-1');
|
|
|
|
result.data.posts[0].title.should.eql('test-1');
|
|
|
|
result.data.posts[0].created_at.should.eql(1418990400000);
|
2015-01-18 23:24:41 +03:00
|
|
|
moment.utc(result.data.posts[0].created_at).format('DD MM YY HH:mm').should.eql('19 12 14 12:00');
|
2014-12-21 02:48:13 +03:00
|
|
|
result.data.posts[0].should.not.have.property('image');
|
|
|
|
|
|
|
|
done();
|
2015-01-18 23:24:41 +03:00
|
|
|
}).catch(done);
|
2014-12-21 02:48:13 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
it('can parse a title from a markdown file', function (done) {
|
|
|
|
var filename = 'draft-2014-12-19-test-2.md',
|
|
|
|
file = [{
|
|
|
|
path: testUtils.fixtures.getImportFixturePath(filename),
|
|
|
|
name: filename
|
|
|
|
}];
|
|
|
|
|
|
|
|
MarkdownHandler.loadFile(file).then(function (result) {
|
|
|
|
result.data.posts[0].markdown.should.eql('You\'re live! Nice.');
|
|
|
|
result.data.posts[0].status.should.eql('draft');
|
|
|
|
result.data.posts[0].slug.should.eql('test-2');
|
|
|
|
result.data.posts[0].title.should.eql('Welcome to Ghost');
|
|
|
|
result.data.posts[0].created_at.should.eql(1418990400000);
|
|
|
|
result.data.posts[0].should.not.have.property('image');
|
|
|
|
|
|
|
|
done();
|
2015-01-18 23:24:41 +03:00
|
|
|
}).catch(done);
|
2014-12-21 02:48:13 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
it('can parse a featured image from a markdown file if there is a title', function (done) {
|
|
|
|
var filename = 'draft-2014-12-19-test-3.md',
|
|
|
|
file = [{
|
|
|
|
path: testUtils.fixtures.getImportFixturePath(filename),
|
|
|
|
name: filename
|
|
|
|
}];
|
|
|
|
|
|
|
|
MarkdownHandler.loadFile(file).then(function (result) {
|
|
|
|
result.data.posts[0].markdown.should.eql('You\'re live! Nice.');
|
|
|
|
result.data.posts[0].status.should.eql('draft');
|
|
|
|
result.data.posts[0].slug.should.eql('test-3');
|
|
|
|
result.data.posts[0].title.should.eql('Welcome to Ghost');
|
|
|
|
result.data.posts[0].created_at.should.eql(1418990400000);
|
|
|
|
result.data.posts[0].image.should.eql('/images/kitten.jpg');
|
|
|
|
|
|
|
|
done();
|
2015-01-18 23:24:41 +03:00
|
|
|
}).catch(done);
|
2014-12-21 02:48:13 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
it('can import a published post', function (done) {
|
|
|
|
var filename = 'published-2014-12-19-test-1.md',
|
|
|
|
file = [{
|
|
|
|
path: testUtils.fixtures.getImportFixturePath(filename),
|
|
|
|
name: filename
|
|
|
|
}];
|
|
|
|
|
|
|
|
MarkdownHandler.loadFile(file).then(function (result) {
|
|
|
|
result.data.posts[0].markdown.should.eql('You\'re live! Nice.');
|
|
|
|
result.data.posts[0].status.should.eql('published');
|
|
|
|
result.data.posts[0].slug.should.eql('test-1');
|
|
|
|
result.data.posts[0].title.should.eql('Welcome to Ghost');
|
|
|
|
result.data.posts[0].published_at.should.eql(1418990400000);
|
2015-01-18 23:24:41 +03:00
|
|
|
moment.utc(result.data.posts[0].published_at).format('DD MM YY HH:mm').should.eql('19 12 14 12:00');
|
2014-12-21 02:48:13 +03:00
|
|
|
result.data.posts[0].should.not.have.property('image');
|
|
|
|
|
|
|
|
done();
|
2015-01-18 23:24:41 +03:00
|
|
|
}).catch(done);
|
2014-12-21 02:48:13 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
it('does not import deleted posts', function (done) {
|
|
|
|
var filename = 'deleted-2014-12-19-test-1.md',
|
|
|
|
file = [{
|
|
|
|
path: testUtils.fixtures.getImportFixturePath(filename),
|
|
|
|
name: filename
|
|
|
|
}];
|
|
|
|
|
|
|
|
MarkdownHandler.loadFile(file).then(function (result) {
|
2016-02-08 00:27:01 +03:00
|
|
|
result.data.posts.should.be.empty();
|
2014-12-21 02:48:13 +03:00
|
|
|
|
|
|
|
done();
|
2015-01-18 23:24:41 +03:00
|
|
|
}).catch(done);
|
2014-12-21 02:48:13 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
it('can import multiple files', function (done) {
|
|
|
|
var files = [{
|
2017-03-21 11:24:11 +03:00
|
|
|
path: testUtils.fixtures.getImportFixturePath('deleted-2014-12-19-test-1.md'),
|
|
|
|
name: 'deleted-2014-12-19-test-1.md'
|
|
|
|
}, {
|
|
|
|
path: testUtils.fixtures.getImportFixturePath('published-2014-12-19-test-1.md'),
|
|
|
|
name: 'published-2014-12-19-test-1.md'
|
|
|
|
}, {
|
|
|
|
path: testUtils.fixtures.getImportFixturePath('draft-2014-12-19-test-3.md'),
|
|
|
|
name: 'draft-2014-12-19-test-3.md'
|
|
|
|
}];
|
2014-12-21 02:48:13 +03:00
|
|
|
|
|
|
|
MarkdownHandler.loadFile(files).then(function (result) {
|
|
|
|
// deleted-2014-12-19-test-1.md
|
|
|
|
// doesn't get imported ;)
|
|
|
|
|
2015-01-13 19:39:03 +03:00
|
|
|
// loadFile doesn't guarantee order of results
|
|
|
|
var one = result.data.posts[0].status === 'published' ? 0 : 1,
|
|
|
|
two = one === 0 ? 1 : 0;
|
|
|
|
|
2014-12-21 02:48:13 +03:00
|
|
|
// published-2014-12-19-test-1.md
|
2015-01-13 19:39:03 +03:00
|
|
|
result.data.posts[one].markdown.should.eql('You\'re live! Nice.');
|
|
|
|
result.data.posts[one].status.should.eql('published');
|
|
|
|
result.data.posts[one].slug.should.eql('test-1');
|
|
|
|
result.data.posts[one].title.should.eql('Welcome to Ghost');
|
|
|
|
result.data.posts[one].published_at.should.eql(1418990400000);
|
2015-01-18 23:24:41 +03:00
|
|
|
moment.utc(result.data.posts[one].published_at).format('DD MM YY HH:mm').should.eql('19 12 14 12:00');
|
2015-01-13 19:39:03 +03:00
|
|
|
result.data.posts[one].should.not.have.property('image');
|
2014-12-21 02:48:13 +03:00
|
|
|
|
|
|
|
// draft-2014-12-19-test-3.md
|
2015-01-13 19:39:03 +03:00
|
|
|
result.data.posts[two].markdown.should.eql('You\'re live! Nice.');
|
|
|
|
result.data.posts[two].status.should.eql('draft');
|
|
|
|
result.data.posts[two].slug.should.eql('test-3');
|
|
|
|
result.data.posts[two].title.should.eql('Welcome to Ghost');
|
|
|
|
result.data.posts[two].created_at.should.eql(1418990400000);
|
|
|
|
result.data.posts[two].image.should.eql('/images/kitten.jpg');
|
2014-12-21 02:48:13 +03:00
|
|
|
|
2014-12-14 14:31:00 +03:00
|
|
|
done();
|
2015-01-04 00:11:40 +03:00
|
|
|
}).catch(done);
|
2014-12-14 14:31:00 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2014-12-11 00:50:00 +03:00
|
|
|
describe('DataImporter', function () {
|
|
|
|
it('has the correct interface', function () {
|
|
|
|
DataImporter.type.should.eql('data');
|
|
|
|
DataImporter.preProcess.should.be.instanceof(Function);
|
|
|
|
DataImporter.doImport.should.be.instanceof(Function);
|
|
|
|
});
|
2014-12-29 21:33:47 +03:00
|
|
|
|
|
|
|
it('does preprocess posts, users and tags correctly', function () {
|
2017-05-23 19:18:13 +03:00
|
|
|
var inputData = require('../../../utils/fixtures/import/import-data-1.json'),
|
2014-12-29 21:33:47 +03:00
|
|
|
outputData = DataImporter.preProcess(_.cloneDeep(inputData));
|
|
|
|
|
|
|
|
// Data preprocess is a noop
|
|
|
|
inputData.data.data.posts[0].should.eql(outputData.data.data.posts[0]);
|
|
|
|
inputData.data.data.tags[0].should.eql(outputData.data.data.tags[0]);
|
|
|
|
inputData.data.data.users[0].should.eql(outputData.data.data.users[0]);
|
|
|
|
});
|
2014-12-11 00:50:00 +03:00
|
|
|
});
|
2014-12-14 14:31:00 +03:00
|
|
|
|
|
|
|
describe('ImageImporter', function () {
|
|
|
|
it('has the correct interface', function () {
|
|
|
|
ImageImporter.type.should.eql('images');
|
|
|
|
ImageImporter.preProcess.should.be.instanceof(Function);
|
|
|
|
ImageImporter.doImport.should.be.instanceof(Function);
|
|
|
|
});
|
|
|
|
|
2014-12-29 21:33:47 +03:00
|
|
|
it('does preprocess posts, users and tags correctly', function () {
|
2017-05-23 19:18:13 +03:00
|
|
|
var inputData = require('../../../utils/fixtures/import/import-data-1.json'),
|
2014-12-14 14:31:00 +03:00
|
|
|
outputData = ImageImporter.preProcess(_.cloneDeep(inputData));
|
|
|
|
|
2014-12-29 21:33:47 +03:00
|
|
|
inputData = inputData.data.data;
|
|
|
|
outputData = outputData.data.data;
|
|
|
|
|
|
|
|
inputData.posts[0].markdown.should.not.containEql('/content/images/my-image.png');
|
|
|
|
inputData.posts[0].html.should.not.containEql('/content/images/my-image.png');
|
|
|
|
outputData.posts[0].markdown.should.containEql('/content/images/my-image.png');
|
|
|
|
outputData.posts[0].html.should.containEql('/content/images/my-image.png');
|
|
|
|
|
|
|
|
inputData.posts[0].markdown.should.not.containEql('/content/images/photos/cat.jpg');
|
|
|
|
inputData.posts[0].html.should.not.containEql('/content/images/photos/cat.jpg');
|
|
|
|
outputData.posts[0].markdown.should.containEql('/content/images/photos/cat.jpg');
|
|
|
|
outputData.posts[0].html.should.containEql('/content/images/photos/cat.jpg');
|
|
|
|
|
2017-04-24 20:21:47 +03:00
|
|
|
inputData.posts[0].feature_image.should.eql('/images/my-image.png');
|
|
|
|
outputData.posts[0].feature_image.should.eql('/content/images/my-image.png');
|
2014-12-14 14:31:00 +03:00
|
|
|
|
2017-04-24 20:21:47 +03:00
|
|
|
inputData.tags[0].feature_image.should.eql('/images/my-image.png');
|
|
|
|
outputData.tags[0].feature_image.should.eql('/content/images/my-image.png');
|
2014-12-14 14:31:00 +03:00
|
|
|
|
2017-04-24 20:21:47 +03:00
|
|
|
inputData.users[0].profile_image.should.eql('/images/my-image.png');
|
|
|
|
inputData.users[0].cover_image.should.eql('/images/photos/cat.jpg');
|
|
|
|
outputData.users[0].profile_image.should.eql('/content/images/my-image.png');
|
|
|
|
outputData.users[0].cover_image.should.eql('/content/images/photos/cat.jpg');
|
2014-12-14 14:31:00 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
it('does import the images correctly', function () {
|
2017-05-23 19:18:13 +03:00
|
|
|
var inputData = require('../../../utils/fixtures/import/import-data-1.json'),
|
2014-12-14 14:31:00 +03:00
|
|
|
storageApi = {
|
2019-01-21 19:53:44 +03:00
|
|
|
save: sinon.stub().returns(Promise.resolve())
|
2014-12-14 14:31:00 +03:00
|
|
|
},
|
2019-01-21 19:53:44 +03:00
|
|
|
storageSpy = sinon.stub(storage, 'getStorage').callsFake(function () {
|
2014-12-14 14:31:00 +03:00
|
|
|
return storageApi;
|
|
|
|
});
|
|
|
|
|
|
|
|
ImageImporter.doImport(inputData.images).then(function () {
|
2016-02-08 00:27:01 +03:00
|
|
|
storageSpy.calledOnce.should.be.true();
|
|
|
|
storageApi.save.calledTwice.should.be.true();
|
2014-12-14 14:31:00 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2014-12-11 00:50:00 +03:00
|
|
|
});
|