mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-23 19:02:29 +03:00
22e13acd65
- All var declarations are now const or let as per ES6 - All comma-separated lists / chained declarations are now one declaration per line - This is for clarity/readability but also made running the var-to-const/let switch smoother - ESLint rules updated to match How this was done: - npm install -g jscodeshift - git clone https://github.com/cpojer/js-codemod.git - git clone git@github.com:TryGhost/Ghost.git shallow-ghost - cd shallow-ghost - jscodeshift -t ../js-codemod/transforms/unchain-variables.js . -v=2 - jscodeshift -t ../js-codemod/transforms/no-vars.js . -v=2 - yarn - yarn test - yarn lint / fix various lint errors (almost all indent) by opening files and saving in vscode - grunt test-regression - sorted!
102 lines
3.2 KiB
JavaScript
102 lines
3.2 KiB
JavaScript
const should = require('should');
|
|
const sinon = require('sinon');
|
|
const Promise = require('bluebird');
|
|
const rssCache = require('../../../../core/frontend/services/rss/cache');
|
|
const renderer = require('../../../../core/frontend/services/rss/renderer');
|
|
|
|
describe('RSS: Renderer', function () {
|
|
let rssCacheStub;
|
|
let res;
|
|
let baseUrl;
|
|
|
|
beforeEach(function () {
|
|
rssCacheStub = sinon.stub(rssCache, 'getXML');
|
|
|
|
res = {
|
|
locals: {},
|
|
set: sinon.stub(),
|
|
send: sinon.spy()
|
|
};
|
|
|
|
baseUrl = '/rss/';
|
|
});
|
|
|
|
afterEach(function () {
|
|
sinon.restore();
|
|
});
|
|
|
|
it('calls the cache and attempts to render, even without data', function (done) {
|
|
rssCacheStub.returns(new Promise.resolve('dummyxml'));
|
|
|
|
renderer.render(res, baseUrl).then(function () {
|
|
rssCacheStub.calledOnce.should.be.true();
|
|
rssCacheStub.firstCall.args.should.eql(['/rss/', {}]);
|
|
|
|
res.set.calledOnce.should.be.true();
|
|
res.set.calledWith('Content-Type', 'text/xml; charset=UTF-8').should.be.true();
|
|
|
|
res.send.calledOnce.should.be.true();
|
|
res.send.calledWith('dummyxml').should.be.true();
|
|
|
|
done();
|
|
}).catch(done);
|
|
});
|
|
|
|
it('correctly merges locals into empty data before rendering', function (done) {
|
|
rssCacheStub.returns(new Promise.resolve('dummyxml'));
|
|
|
|
res.locals = {foo: 'bar'};
|
|
|
|
renderer.render(res, baseUrl).then(function () {
|
|
rssCacheStub.calledOnce.should.be.true();
|
|
rssCacheStub.firstCall.args.should.eql(['/rss/', {foo: 'bar'}]);
|
|
|
|
res.set.calledOnce.should.be.true();
|
|
res.set.calledWith('Content-Type', 'text/xml; charset=UTF-8').should.be.true();
|
|
|
|
res.send.calledOnce.should.be.true();
|
|
res.send.calledWith('dummyxml').should.be.true();
|
|
|
|
done();
|
|
}).catch(done);
|
|
});
|
|
|
|
it('correctly merges locals into non-empty data before rendering', function (done) {
|
|
rssCacheStub.returns(new Promise.resolve('dummyxml'));
|
|
|
|
res.locals = {foo: 'bar'};
|
|
const data = {foo: 'baz', fizz: 'buzz'};
|
|
|
|
renderer.render(res, baseUrl, data).then(function () {
|
|
rssCacheStub.calledOnce.should.be.true();
|
|
rssCacheStub.firstCall.args.should.eql(['/rss/', {foo: 'baz', fizz: 'buzz'}]);
|
|
|
|
res.set.calledOnce.should.be.true();
|
|
res.set.calledWith('Content-Type', 'text/xml; charset=UTF-8').should.be.true();
|
|
|
|
res.send.calledOnce.should.be.true();
|
|
res.send.calledWith('dummyxml').should.be.true();
|
|
|
|
done();
|
|
}).catch(done);
|
|
});
|
|
|
|
it('does nothing if it gets an error', function (done) {
|
|
rssCacheStub.returns(new Promise.reject(new Error('Fake Error')));
|
|
|
|
renderer.render(res, baseUrl).then(function () {
|
|
done('This should have errored');
|
|
}).catch(function (err) {
|
|
err.message.should.eql('Fake Error');
|
|
|
|
rssCacheStub.calledOnce.should.be.true();
|
|
rssCacheStub.firstCall.args.should.eql(['/rss/', {}]);
|
|
|
|
res.set.called.should.be.false();
|
|
res.send.called.should.be.false();
|
|
|
|
done();
|
|
});
|
|
});
|
|
});
|