0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-02-10 23:36:14 -05:00
ghost/test/unit/services/routing/controllers/rss.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

78 lines
2.2 KiB
JavaScript

const sinon = require('sinon');
const testUtils = require('../../../../utils');
const security = require('@tryghost/security');
const settingsCache = require('../../../../../core/shared/settings-cache');
const controllers = require('../../../../../core/frontend/services/routing/controllers');
const helpers = require('../../../../../core/frontend/services/routing/helpers');
const rssService = require('../../../../../core/frontend/services/rss');
// Helper function to prevent unit tests
// from failing via timeout when they
// should just immediately fail
function failTest(done) {
return function (err) {
done(err);
};
}
describe('Unit - services/routing/controllers/rss', function () {
let req;
let res;
let next;
let fetchDataStub;
let posts;
beforeEach(function () {
posts = [
testUtils.DataGenerator.forKnex.createPost(),
testUtils.DataGenerator.forKnex.createPost()
];
req = {
params: {},
originalUrl: '/rss/'
};
res = {
routerOptions: {},
locals: {
safeVersion: '0.6'
}
};
next = sinon.stub();
fetchDataStub = sinon.stub();
sinon.stub(helpers, 'fetchData').get(function () {
return fetchDataStub;
});
sinon.stub(security.string, 'safe').returns('safe');
sinon.stub(rssService, 'render');
sinon.stub(settingsCache, 'get');
settingsCache.get.withArgs('title').returns('Ghost');
settingsCache.get.withArgs('description').returns('Ghost is cool!');
});
afterEach(function () {
sinon.restore();
});
it('should fetch data and attempt to send XML', function (done) {
fetchDataStub.withArgs({page: 1, slug: undefined}).resolves({
posts: posts
});
rssService.render.callsFake(function (_res, baseUrl, data) {
baseUrl.should.eql('/rss/');
data.posts.should.eql(posts);
data.title.should.eql('Ghost');
data.description.should.eql('Ghost is cool!');
done();
});
controllers.rss(req, res, failTest(done));
});
});