Ghost/test/unit/services/rss/cache.test.js
Hannah Wolfe f08a55c21f
Renamed tests to .test.js & updated commands
refs: https://github.com/TryGhost/Team/issues/856
refs: https://github.com/TryGhost/Team/issues/756

- The .test.js extension is better than _spec.js as it's more obvious that it's an extension
- It also meaans we can use the --extension parameter in mocha, which should result in a better default behaviour for `yarn test`
- It also highlights that some of our tests were named incorrectly and were not (and still will not be) run (see https://github.com/TryGhost/Team/issues/856)
- Note: even with this change, `yarn test` is throwing errors, I believe because of this issue https://github.com/TryGhost/Team/issues/756
2021-07-06 20:45:01 +01:00

57 lines
1.7 KiB
JavaScript

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');
describe('RSS: Cache', function () {
let generateSpy;
let generateFeedReset;
afterEach(function () {
configUtils.restore();
sinon.restore();
generateFeedReset();
});
beforeEach(function () {
configUtils.set({url: 'http://my-ghost-blog.com'});
generateSpy = sinon.spy(rssCache.__get__('generateFeed'));
generateFeedReset = rssCache.__set__('generateFeed', generateSpy);
});
it('should not rebuild xml for same data and url', function (done) {
const data = {
title: 'Test Title',
description: 'Testing Desc',
posts: [],
meta: {pagination: {pages: 1}}
};
let xmlData1;
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);
});
});