2020-04-29 18:44:27 +03:00
|
|
|
const should = require('should');
|
|
|
|
const sinon = require('sinon');
|
|
|
|
const rewire = require('rewire');
|
|
|
|
const configUtils = require('../../../utils/configUtils');
|
|
|
|
const rssCache = rewire('../../../../core/frontend/services/rss/cache');
|
2017-11-07 23:00:03 +03:00
|
|
|
|
|
|
|
describe('RSS: Cache', function () {
|
2020-04-29 18:44:27 +03:00
|
|
|
let generateSpy;
|
|
|
|
let generateFeedReset;
|
2017-11-07 23:00:03 +03:00
|
|
|
|
|
|
|
afterEach(function () {
|
|
|
|
configUtils.restore();
|
2019-01-21 19:53:44 +03:00
|
|
|
sinon.restore();
|
2017-11-07 23:00:03 +03:00
|
|
|
generateFeedReset();
|
|
|
|
});
|
|
|
|
|
|
|
|
beforeEach(function () {
|
|
|
|
configUtils.set({url: 'http://my-ghost-blog.com'});
|
|
|
|
|
2019-01-21 19:53:44 +03:00
|
|
|
generateSpy = sinon.spy(rssCache.__get__('generateFeed'));
|
2017-11-07 23:00:03 +03:00
|
|
|
generateFeedReset = rssCache.__set__('generateFeed', generateSpy);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should not rebuild xml for same data and url', function (done) {
|
2020-04-29 18:44:27 +03:00
|
|
|
const data = {
|
|
|
|
title: 'Test Title',
|
|
|
|
description: 'Testing Desc',
|
|
|
|
posts: [],
|
|
|
|
meta: {pagination: {pages: 1}}
|
|
|
|
};
|
|
|
|
let xmlData1;
|
2017-11-07 23:00:03 +03:00
|
|
|
|
|
|
|
rssCache.getXML('/rss/', data)
|
|
|
|
.then(function (_xmlData) {
|
|
|
|
xmlData1 = _xmlData;
|
|
|
|
|
|
|
|
// We should have called generateFeed
|
|
|
|
generateSpy.callCount.should.eql(1);
|
|
|
|
|
|
|
|
// Call RSS again to check that we didn't rebuild
|
|
|
|
return rssCache.getXML('/rss/', data);
|
|
|
|
})
|
|
|
|
.then(function (xmlData2) {
|
|
|
|
// Assertions
|
|
|
|
|
|
|
|
// We should not have called generateFeed again
|
|
|
|
generateSpy.callCount.should.eql(1);
|
|
|
|
|
|
|
|
// The data should be identical, no changing lastBuildDate
|
|
|
|
xmlData1.should.equal(xmlData2);
|
|
|
|
|
|
|
|
done();
|
|
|
|
})
|
|
|
|
.catch(done);
|
|
|
|
});
|
|
|
|
});
|