mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-10 23:36:14 -05:00
- move all test files from core/test to test/ - updated all imports and other references - all code inside of core/ is then application code - tests are correctly at the root level - consistent with other repos/projects Co-authored-by: Kevin Ansfield <kevin@lookingsideways.co.uk>
77 lines
2.3 KiB
JavaScript
77 lines
2.3 KiB
JavaScript
const should = require('should'),
|
|
sinon = require('sinon'),
|
|
_ = require('lodash'),
|
|
testUtils = require('../../../../utils'),
|
|
common = require('../../../../../core/server/lib/common'),
|
|
security = require('../../../../../core/server/lib/security'),
|
|
settingsCache = require('../../../../../core/server/services/settings/cache'),
|
|
controllers = require('../../../../../core/frontend/services/routing/controllers'),
|
|
helpers = require('../../../../../core/frontend/services/routing/helpers'),
|
|
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, res, next, fetchDataStub, 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));
|
|
});
|
|
});
|