2018-12-13 16:25:24 +03:00
|
|
|
const should = require('should');
|
2020-04-21 17:42:22 +03:00
|
|
|
const handleImageSizes = require('../../../../../core/server/web/site/middleware/handle-image-sizes.js');
|
2018-12-13 16:25:24 +03:00
|
|
|
|
|
|
|
// @TODO make these tests lovely and non specific to implementation
|
|
|
|
describe('handleImageSizes middleware', function () {
|
|
|
|
it('calls next immediately if the url does not match /size/something/', function (done) {
|
|
|
|
const fakeReq = {
|
|
|
|
url: '/size/something'
|
|
|
|
};
|
|
|
|
// CASE: second thing middleware does is try to match to a regex
|
|
|
|
fakeReq.url.match = function () {
|
|
|
|
throw new Error('Should have exited immediately');
|
|
|
|
};
|
|
|
|
handleImageSizes(fakeReq, {}, function next() {
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('calls next immediately if the url does not match /size/something/', function (done) {
|
|
|
|
const fakeReq = {
|
|
|
|
url: '/url/whatever/'
|
|
|
|
};
|
|
|
|
// CASE: second thing middleware does is try to match to a regex
|
|
|
|
fakeReq.url.match = function () {
|
|
|
|
throw new Error('Should have exited immediately');
|
|
|
|
};
|
|
|
|
handleImageSizes(fakeReq, {}, function next() {
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('calls next immediately if the url does not match /size/something/', function (done) {
|
|
|
|
const fakeReq = {
|
|
|
|
url: '/size//'
|
|
|
|
};
|
|
|
|
// CASE: second thing middleware does is try to match to a regex
|
|
|
|
fakeReq.url.match = function () {
|
|
|
|
throw new Error('Should have exited immediately');
|
|
|
|
};
|
|
|
|
handleImageSizes(fakeReq, {}, function next() {
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|