mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-03 23:00:14 -05:00
7f1d3ebc07
- move all test files from core/test to test/ - updated all imports and other references - all code inside of core/ is then application code - tests are correctly at the root level - consistent with other repos/projects Co-authored-by: Kevin Ansfield <kevin@lookingsideways.co.uk>
81 lines
2.4 KiB
JavaScript
81 lines
2.4 KiB
JavaScript
const should = require('should');
|
|
const sinon = require('sinon');
|
|
const configUtils = require('../../../../utils/configUtils');
|
|
const imageTransform = require('@tryghost/image-transform');
|
|
const {logging} = require('../../../../../core/server/lib/common');
|
|
const normalize = require('../../../../../core/server/web/shared/middlewares/image/normalize');
|
|
|
|
describe('normalize', function () {
|
|
let res, req;
|
|
|
|
beforeEach(function () {
|
|
req = {
|
|
file: {
|
|
name: 'test',
|
|
path: '/test/path',
|
|
ext: '.jpg'
|
|
}
|
|
};
|
|
|
|
sinon.stub(imageTransform, 'resizeFromPath');
|
|
sinon.stub(logging, 'error');
|
|
});
|
|
|
|
afterEach(function () {
|
|
sinon.restore();
|
|
configUtils.restore();
|
|
});
|
|
|
|
it('should do manipulation by default', function (done) {
|
|
imageTransform.resizeFromPath.resolves();
|
|
|
|
normalize(req, res, function () {
|
|
imageTransform.resizeFromPath.calledOnce.should.be.true();
|
|
done();
|
|
});
|
|
});
|
|
|
|
it('should add files array to request object with original and resized files', function (done) {
|
|
imageTransform.resizeFromPath.resolves();
|
|
|
|
normalize(req, res, function () {
|
|
req.files.length.should.be.equal(2);
|
|
done();
|
|
});
|
|
});
|
|
|
|
it('should not do manipulation without resize flag set', function (done) {
|
|
configUtils.set({
|
|
imageOptimization: {
|
|
resize: false
|
|
}
|
|
});
|
|
|
|
normalize(req, res, function () {
|
|
imageTransform.resizeFromPath.called.should.be.false();
|
|
done();
|
|
});
|
|
});
|
|
|
|
it('should not create files array when resizing fails', function (done) {
|
|
imageTransform.resizeFromPath.rejects();
|
|
|
|
normalize(req, res, () => {
|
|
logging.error.calledOnce.should.be.true();
|
|
req.file.should.not.be.equal(undefined);
|
|
should.not.exist(req.files);
|
|
done();
|
|
});
|
|
});
|
|
|
|
['.gif', '.svg', '.svgz'].forEach(function (extension) {
|
|
it(`should skip resizing when file extension is ${extension}`, function (done) {
|
|
req.file.ext = extension;
|
|
normalize(req, res, function () {
|
|
req.file.should.not.be.equal(undefined);
|
|
should.not.exist(req.files);
|
|
done();
|
|
});
|
|
});
|
|
});
|
|
});
|