2017-03-21 11:24:11 +03:00
|
|
|
var should = require('should'),
|
|
|
|
sinon = require('sinon'),
|
|
|
|
rewire = require('rewire'),
|
|
|
|
_ = require('lodash'),
|
|
|
|
Promise = require('bluebird'),
|
|
|
|
testUtils = require('../utils'),
|
|
|
|
channelConfig = require('../../server/controllers/frontend/channel-config'),
|
|
|
|
api = require('../../server/api'),
|
|
|
|
settingsCache = require('../../server/settings/cache'),
|
|
|
|
rss = rewire('../../server/data/xml/rss'),
|
|
|
|
configUtils = require('../utils/configUtils'),
|
|
|
|
|
|
|
|
sandbox = sinon.sandbox.create();
|
2015-04-28 21:04:53 +03:00
|
|
|
|
|
|
|
// 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('RSS', function () {
|
2017-03-21 11:24:11 +03:00
|
|
|
var req, res, posts;
|
2015-04-28 21:04:53 +03:00
|
|
|
|
|
|
|
before(function () {
|
2016-04-03 01:16:20 +03:00
|
|
|
posts = _.cloneDeep(testUtils.DataGenerator.forKnex.posts);
|
|
|
|
posts = _.filter(posts, function filter(post) {
|
2015-04-28 21:04:53 +03:00
|
|
|
return post.status === 'published' && post.page === false;
|
|
|
|
});
|
|
|
|
|
✨ replace auto increment id's by object id (#7495)
* 🛠 bookshelf tarball, bson-objectid
* 🎨 schema changes
- change increment type to string
- add a default fallback for string length 191 (to avoid adding this logic to every single column which uses an ID)
- remove uuid, because ID now represents a global resource identifier
- keep uuid for post, because we are using this as preview id
- keep uuid for clients for now - we are using this param for Ghost-Auth
* ✨ base model: generate ObjectId on creating event
- each new resource get's a auto generate ObjectId
- this logic won't work for attached models, this commit comes later
* 🎨 centralised attach method
When attaching models there are two things important two know
1. To be able to attach an ObjectId, we need to register the `onCreating` event the fetched model!This is caused by the Bookshelf design in general. On this target model we are attaching the new model.
2. We need to manually fetch the target model, because Bookshelf has a weird behaviour (which is known as a bug, see see https://github.com/tgriesser/bookshelf/issues/629). The most important property when attaching a model is `parentFk`, which is the foreign key. This can be null when fetching the model with the option `withRelated`. To ensure quality and consistency, the custom attach wrapper always fetches the target model manual. By fetching the target model (again) is a little performance decrease, but it also has advantages: we can register the event, and directly unregister the event again. So very clean code.
Important: please only use the custom attach wrapper in the future.
* 🎨 token model had overriden the onCreating function because of the created_at field
- we need to ensure that the base onCreating hook get's triggered for ALL models
- if not, they don't get an ObjectId assigned
- in this case: be smart and check if the target model has a created_at field
* 🎨 we don't have a uuid field anymore, remove the usages
- no default uuid creation in models
- i am pretty sure we have some more definitions in our tests (for example in the export json files), but that is too much work to delete them all
* 🎨 do not parse ID to Number
- we had various occurances of parsing all ID's to numbers
- we don't need this behaviour anymore
- ID is string
- i will adapt the ID validation in the next commit
* 🎨 change ID regex for validation
- we only allow: ID as ObjectId, ID as 1 and ID as me
- we need to keep ID 1, because our whole software relies on ID 1 (permissions etc)
* 🎨 owner fixture
- roles: [4] does not work anymore
- 4 means -> static id 4
- this worked in an auto increment system (not even in a system with distributed writes)
- with ObjectId we generate each ID automatically (for static and dynamic resources)
- it is possible to define all id's for static resources still, but that means we need to know which ID is already used and for consistency we have to define ObjectId's for these static resources
- so no static id's anymore, except of: id 1 for owner and id 0 for external usage (because this is required from our permission system)
- NOTE: please read through the comment in the user model
* 🎨 tests: DataGenerator and test utils
First of all: we need to ensure using ObjectId's in the tests. When don't, we can't ensure that ObjectId's work properly.
This commit brings lot's of dynamic into all the static defined id's.
In one of the next commits, i will adapt all the tests.
* 🚨 remove counter in Notification API
- no need to add a counter
- we simply generate ObjectId's (they are auto incremental as well)
- our id validator does only allow ObjectId as id,1 and me
* 🎨 extend contextUser in Base Model
- remove isNumber check, because id's are no longer numbers, except of id 0/1
- use existing isExternalUser
- support id 0/1 as string or number
* ✨ Ghost Owner has id 1
- ensure we define this id in the fixtures.json
- doesn't matter if number or string
* 🎨 functional tests adaptions
- use dynamic id's
* 🎨 fix unit tests
* 🎨 integration tests adaptions
* 🎨 change importer utils
- all our export examples (test/fixtures/exports) contain id's as numbers
- fact: but we ignore them anyway when inserting into the database, see https://github.com/TryGhost/Ghost/blob/master/core/server/data/import/utils.js#L249
- in https://github.com/TryGhost/Ghost/pull/7495/commits/0e6ed957cd54dc02a25cf6fb1ab7d7e723295e2c#diff-70f514a06347c048648be464819503c4L67 i removed parsing id's to integers
- i realised that this ^ check just existed, because the userIdToMap was an object key and object keys are always strings!
- i think this logic is a little bit complicated, but i don't want to refactor this now
- this commit ensures when trying to find the user, the id comparison works again
- i've added more documentation to understand this logic ;)
- plus i renamed an attribute to improve readability
* 🎨 Data-Generator: add more defaults to createUser
- if i use the function DataGenerator.forKnex.createUser i would like to get a full set of defaults
* 🎨 test utils: change/extend function set for functional tests
- functional tests work a bit different
- they boot Ghost and seed the database
- some functional tests have mis-used the test setup
- the test setup needs two sections: integration/unit and functional tests
- any functional test is allowed to either add more data or change data in the existing Ghost db
- but what it should not do is: add test fixtures like roles or users from our DataGenerator and cross fingers it will work
- this commit adds a clean method for functional tests to add extra users
* 🎨 functional tests adaptions
- use last commit to insert users for functional tests clean
- tidy up usage of testUtils.setup or testUtils.doAuth
* 🐛 test utils: reset database before init
- ensure we don't have any left data from other tests in the database when starting ghost
* 🐛 fix test (unrelated to this PR)
- fixes a random failure
- return statement was missing
* 🎨 make changes for invites
2016-11-17 12:09:11 +03:00
|
|
|
_.each(posts, function (post, i) {
|
|
|
|
post.id = i;
|
2015-04-28 21:04:53 +03:00
|
|
|
post.url = '/' + post.slug + '/';
|
|
|
|
post.author = {name: 'Joe Bloggs'};
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(function () {
|
|
|
|
sandbox.restore();
|
|
|
|
rss = rewire('../../server/data/xml/rss');
|
2015-12-14 23:05:11 +03:00
|
|
|
configUtils.restore();
|
2015-04-28 21:04:53 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('Check XML', function () {
|
|
|
|
beforeEach(function () {
|
|
|
|
req = {
|
|
|
|
params: {},
|
|
|
|
originalUrl: '/rss/'
|
|
|
|
};
|
|
|
|
|
|
|
|
res = {
|
|
|
|
locals: {
|
|
|
|
safeVersion: '0.6'
|
|
|
|
},
|
|
|
|
set: sinon.stub()
|
|
|
|
};
|
|
|
|
|
2015-12-14 23:05:11 +03:00
|
|
|
configUtils.set({url: 'http://my-ghost-blog.com'});
|
2015-04-28 21:04:53 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should get the RSS tags correct', function (done) {
|
|
|
|
rss.__set__('getData', function () {
|
|
|
|
return Promise.resolve({
|
|
|
|
title: 'Test Title',
|
|
|
|
description: 'Testing Desc',
|
|
|
|
permalinks: '/:slug/',
|
|
|
|
results: {posts: [], meta: {pagination: {pages: 1}}}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
res.send = function send(xmlData) {
|
|
|
|
should.exist(xmlData);
|
2016-02-08 00:27:01 +03:00
|
|
|
res.set.calledWith('Content-Type', 'text/xml; charset=UTF-8').should.be.true();
|
2015-04-28 21:04:53 +03:00
|
|
|
|
|
|
|
// xml & rss tags
|
|
|
|
xmlData.should.match(/^<\?xml version="1.0" encoding="UTF-8"\?>/);
|
|
|
|
xmlData.should.match(/<rss/);
|
|
|
|
xmlData.should.match(/xmlns:dc="http:\/\/purl.org\/dc\/elements\/1.1\/"/);
|
|
|
|
xmlData.should.match(/xmlns:content="http:\/\/purl.org\/rss\/1.0\/modules\/content\/"/);
|
|
|
|
xmlData.should.match(/xmlns:atom="http:\/\/www.w3.org\/2005\/Atom"/);
|
|
|
|
xmlData.should.match(/version="2.0"/);
|
|
|
|
xmlData.should.match(/xmlns:media="http:\/\/search.yahoo.com\/mrss\/"/);
|
|
|
|
|
|
|
|
// channel tags
|
|
|
|
xmlData.should.match(/<channel><title><!\[CDATA\[Test Title\]\]><\/title>/);
|
|
|
|
xmlData.should.match(/<description><!\[CDATA\[Testing Desc\]\]><\/description>/);
|
|
|
|
xmlData.should.match(/<link>http:\/\/my-ghost-blog.com\/<\/link>/);
|
2017-04-11 14:54:52 +03:00
|
|
|
xmlData.should.match(/<image><url>http:\/\/my-ghost-blog.com\/favicon.png<\/url><title>Test Title<\/title><link>http:\/\/my-ghost-blog.com\/<\/link><\/image>/);
|
2015-04-28 21:04:53 +03:00
|
|
|
xmlData.should.match(/<generator>Ghost 0.6<\/generator>/);
|
|
|
|
xmlData.should.match(/<lastBuildDate>.*?<\/lastBuildDate>/);
|
|
|
|
xmlData.should.match(/<atom:link href="http:\/\/my-ghost-blog.com\/rss\/" rel="self"/);
|
|
|
|
xmlData.should.match(/type="application\/rss\+xml"\/><ttl>60<\/ttl>/);
|
|
|
|
xmlData.should.match(/<\/channel><\/rss>$/);
|
|
|
|
|
|
|
|
done();
|
|
|
|
};
|
|
|
|
|
2017-08-14 06:21:24 +03:00
|
|
|
res.locals.channel = channelConfig.get('index');
|
|
|
|
res.locals.channel.isRSS = true;
|
2015-04-28 21:04:53 +03:00
|
|
|
rss(req, res, failTest(done));
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should get the item tags correct', function (done) {
|
|
|
|
rss.__set__('getData', function () {
|
|
|
|
return Promise.resolve({
|
|
|
|
title: 'Test Title',
|
|
|
|
description: 'Testing Desc',
|
|
|
|
permalinks: '/:slug/',
|
|
|
|
results: {posts: posts, meta: {pagination: {pages: 1}}}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
res.send = function send(xmlData) {
|
|
|
|
should.exist(xmlData);
|
|
|
|
|
|
|
|
// item tags
|
|
|
|
xmlData.should.match(/<item><title><!\[CDATA\[HTML Ipsum\]\]><\/title>/);
|
|
|
|
xmlData.should.match(/<description><!\[CDATA\[<h1>HTML Ipsum Presents<\/h1>/);
|
|
|
|
xmlData.should.match(/<link>http:\/\/my-ghost-blog.com\/html-ipsum\/<\/link>/);
|
2017-04-11 14:54:52 +03:00
|
|
|
xmlData.should.match(/<image><url>http:\/\/my-ghost-blog.com\/favicon.png<\/url><title>Test Title<\/title><link>http:\/\/my-ghost-blog.com\/<\/link><\/image>/);
|
2015-04-28 21:04:53 +03:00
|
|
|
xmlData.should.match(/<guid isPermaLink="false">/);
|
|
|
|
xmlData.should.match(/<\/guid><dc:creator><!\[CDATA\[Joe Bloggs\]\]><\/dc:creator>/);
|
|
|
|
xmlData.should.match(/<pubDate>Thu, 01 Jan 2015/);
|
|
|
|
xmlData.should.match(/<content:encoded><!\[CDATA\[<h1>HTML Ipsum Presents<\/h1><p><strong>Pellentes/);
|
|
|
|
xmlData.should.match(/<\/code><\/pre>\]\]><\/content:encoded><\/item>/);
|
|
|
|
xmlData.should.not.match(/<author>/);
|
|
|
|
|
|
|
|
// basic structure check
|
|
|
|
var postEnd = '<\/code><\/pre>\]\]><\/content:encoded>',
|
|
|
|
firstIndex = xmlData.indexOf(postEnd);
|
|
|
|
|
|
|
|
// The first title should be before the first content
|
|
|
|
xmlData.indexOf('HTML Ipsum').should.be.below(firstIndex);
|
|
|
|
// The second title should be after the first content
|
|
|
|
xmlData.indexOf('Ghostly Kitchen Sink').should.be.above(firstIndex);
|
|
|
|
|
|
|
|
// done
|
|
|
|
done();
|
|
|
|
};
|
|
|
|
|
2017-08-14 06:21:24 +03:00
|
|
|
res.locals.channel = channelConfig.get('index');
|
|
|
|
res.locals.channel.isRSS = true;
|
2015-04-28 21:04:53 +03:00
|
|
|
rss(req, res, failTest(done));
|
|
|
|
});
|
|
|
|
|
2016-10-10 11:51:03 +03:00
|
|
|
it('should only return visible tags', function (done) {
|
2016-09-14 21:14:08 +03:00
|
|
|
var postWithTags = posts[2];
|
|
|
|
postWithTags.tags = [
|
|
|
|
{name: 'public', visibility: 'public'},
|
|
|
|
{name: 'internal', visibility: 'internal'},
|
|
|
|
{name: 'visibility'}
|
|
|
|
];
|
|
|
|
|
|
|
|
rss.__set__('getData', function () {
|
|
|
|
return Promise.resolve({
|
|
|
|
title: 'Test Title',
|
|
|
|
description: 'Testing Desc',
|
|
|
|
permalinks: '/:slug/',
|
|
|
|
results: {posts: [postWithTags], meta: {pagination: {pages: 1}}}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
res.send = function send(xmlData) {
|
|
|
|
should.exist(xmlData);
|
|
|
|
// item tags
|
|
|
|
xmlData.should.match(/<title><!\[CDATA\[Short and Sweet\]\]>/);
|
|
|
|
xmlData.should.match(/<description><!\[CDATA\[test stuff/);
|
2017-05-31 17:46:29 +03:00
|
|
|
xmlData.should.match(/<content:encoded><!\[CDATA\[<div class="kg-card-markdown"><h2 id="testing">testing<\/h2>\n/);
|
2016-09-14 21:14:08 +03:00
|
|
|
xmlData.should.match(/<img src="http:\/\/placekitten.com\/500\/200"/);
|
|
|
|
xmlData.should.match(/<media:content url="http:\/\/placekitten.com\/500\/200" medium="image"\/>/);
|
|
|
|
xmlData.should.match(/<category><!\[CDATA\[public\]\]/);
|
|
|
|
xmlData.should.match(/<category><!\[CDATA\[visibility\]\]/);
|
|
|
|
xmlData.should.not.match(/<category><!\[CDATA\[internal\]\]/);
|
|
|
|
done();
|
|
|
|
};
|
|
|
|
|
2017-08-14 06:21:24 +03:00
|
|
|
res.locals.channel = channelConfig.get('index');
|
|
|
|
res.locals.channel.isRSS = true;
|
2016-09-14 21:14:08 +03:00
|
|
|
rss(req, res, failTest(done));
|
|
|
|
});
|
|
|
|
|
2015-04-28 21:04:53 +03:00
|
|
|
it('should use meta_description and image where available', function (done) {
|
|
|
|
rss.__set__('getData', function () {
|
|
|
|
return Promise.resolve({
|
|
|
|
title: 'Test Title',
|
|
|
|
description: 'Testing Desc',
|
|
|
|
permalinks: '/:slug/',
|
|
|
|
results: {posts: [posts[2]], meta: {pagination: {pages: 1}}}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
res.send = function send(xmlData) {
|
|
|
|
should.exist(xmlData);
|
|
|
|
|
|
|
|
// special/optional tags
|
|
|
|
xmlData.should.match(/<title><!\[CDATA\[Short and Sweet\]\]>/);
|
|
|
|
xmlData.should.match(/<description><!\[CDATA\[test stuff/);
|
2017-05-31 17:46:29 +03:00
|
|
|
xmlData.should.match(/<content:encoded><!\[CDATA\[<div class="kg-card-markdown"><h2 id="testing">testing<\/h2>\n/);
|
2015-04-28 21:04:53 +03:00
|
|
|
xmlData.should.match(/<img src="http:\/\/placekitten.com\/500\/200"/);
|
|
|
|
xmlData.should.match(/<media:content url="http:\/\/placekitten.com\/500\/200" medium="image"\/>/);
|
|
|
|
|
|
|
|
done();
|
|
|
|
};
|
|
|
|
|
2017-08-14 06:21:24 +03:00
|
|
|
res.locals.channel = channelConfig.get('index');
|
|
|
|
res.locals.channel.isRSS = true;
|
2015-04-28 21:04:53 +03:00
|
|
|
rss(req, res, failTest(done));
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should process urls correctly', function (done) {
|
|
|
|
rss.__set__('getData', function () {
|
|
|
|
return Promise.resolve({
|
|
|
|
title: 'Test Title',
|
|
|
|
description: 'Testing Desc',
|
|
|
|
permalinks: '/:slug/',
|
|
|
|
results: {posts: [posts[3]], meta: {pagination: {pages: 1}}}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
res.send = function send(xmlData) {
|
|
|
|
should.exist(xmlData);
|
|
|
|
|
|
|
|
// anchor URL - <a href="#nowhere" title="Anchor URL">
|
|
|
|
xmlData.should.match(/<a href="http:\/\/my-ghost-blog.com\/not-so-short-bit-complex\/#nowhere" title="Anchor URL">/);
|
|
|
|
|
|
|
|
// relative URL - <a href="/about#nowhere" title="Relative URL">
|
|
|
|
xmlData.should.match(/<a href="http:\/\/my-ghost-blog.com\/about#nowhere" title="Relative URL">/);
|
|
|
|
|
2015-07-17 18:00:39 +03:00
|
|
|
// protocol relative URL - <a href="//somewhere.com/link#nowhere" title="Protocol Relative URL">
|
|
|
|
xmlData.should.match(/<a href="\/\/somewhere.com\/link#nowhere" title="Protocol Relative URL">/);
|
|
|
|
|
2015-04-28 21:04:53 +03:00
|
|
|
// absolute URL - <a href="http://somewhere.com/link#nowhere" title="Absolute URL">
|
|
|
|
xmlData.should.match(/<a href="http:\/\/somewhere.com\/link#nowhere" title="Absolute URL">/);
|
|
|
|
|
|
|
|
// done
|
|
|
|
done();
|
|
|
|
};
|
|
|
|
|
2017-08-14 06:21:24 +03:00
|
|
|
res.locals.channel = channelConfig.get('index');
|
|
|
|
res.locals.channel.isRSS = true;
|
2015-04-28 21:04:53 +03:00
|
|
|
rss(req, res, failTest(done));
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should process urls correctly with subdirectory', function (done) {
|
2015-12-14 23:05:11 +03:00
|
|
|
configUtils.set({url: 'http://my-ghost-blog.com/blog/'});
|
2015-04-28 21:04:53 +03:00
|
|
|
rss.__set__('getData', function () {
|
|
|
|
return Promise.resolve({
|
|
|
|
title: 'Test Title',
|
|
|
|
description: 'Testing Desc',
|
|
|
|
permalinks: '/:slug/',
|
|
|
|
results: {posts: [posts[3]], meta: {pagination: {pages: 1}}}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
res.send = function send(xmlData) {
|
|
|
|
should.exist(xmlData);
|
|
|
|
|
|
|
|
// anchor URL - <a href="#nowhere" title="Anchor URL">
|
|
|
|
xmlData.should.match(/<a href="http:\/\/my-ghost-blog.com\/blog\/not-so-short-bit-complex\/#nowhere" title="Anchor URL">/);
|
|
|
|
|
|
|
|
// relative URL - <a href="/about#nowhere" title="Relative URL">
|
|
|
|
xmlData.should.match(/<a href="http:\/\/my-ghost-blog.com\/blog\/about#nowhere" title="Relative URL">/);
|
|
|
|
|
|
|
|
// absolute URL - <a href="http://somewhere.com/link#nowhere" title="Absolute URL">
|
|
|
|
xmlData.should.match(/<a href="http:\/\/somewhere.com\/link#nowhere" title="Absolute URL">/);
|
|
|
|
|
|
|
|
// done
|
|
|
|
done();
|
|
|
|
};
|
|
|
|
|
2017-08-14 06:21:24 +03:00
|
|
|
res.locals.channel = channelConfig.get('index');
|
|
|
|
res.locals.channel.isRSS = true;
|
2015-04-28 21:04:53 +03:00
|
|
|
rss(req, res, failTest(done));
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('dataBuilder', function () {
|
2015-12-02 13:06:44 +03:00
|
|
|
var apiBrowseStub, apiTagStub, apiUserStub;
|
2017-02-03 16:15:11 +03:00
|
|
|
|
2015-04-28 21:04:53 +03:00
|
|
|
beforeEach(function () {
|
2015-10-25 23:00:29 +03:00
|
|
|
apiBrowseStub = sandbox.stub(api.posts, 'browse', function () {
|
|
|
|
return Promise.resolve({posts: [], meta: {pagination: {pages: 3}}});
|
|
|
|
});
|
|
|
|
|
|
|
|
apiTagStub = sandbox.stub(api.tags, 'read', function () {
|
|
|
|
return Promise.resolve({tags: [{name: 'Magic'}]});
|
|
|
|
});
|
|
|
|
|
|
|
|
apiUserStub = sandbox.stub(api.users, 'read', function () {
|
|
|
|
return Promise.resolve({users: [{name: 'Joe Blogs'}]});
|
|
|
|
});
|
|
|
|
|
2015-04-28 21:04:53 +03:00
|
|
|
req = {
|
|
|
|
params: {},
|
|
|
|
originalUrl: '/rss/'
|
|
|
|
};
|
|
|
|
|
|
|
|
res = {
|
|
|
|
locals: {
|
|
|
|
safeVersion: '0.6'
|
|
|
|
},
|
|
|
|
set: sinon.stub()
|
|
|
|
};
|
|
|
|
|
2017-02-27 18:53:04 +03:00
|
|
|
sandbox.stub(settingsCache, 'get', function (key) {
|
2017-02-03 16:15:11 +03:00
|
|
|
var obj = {
|
|
|
|
title: 'Test',
|
|
|
|
description: 'Some Text',
|
|
|
|
permalinks: '/:slug/'
|
|
|
|
};
|
|
|
|
|
|
|
|
return obj[key];
|
|
|
|
});
|
|
|
|
|
|
|
|
configUtils.set({
|
|
|
|
url: 'http://my-ghost-blog.com'
|
|
|
|
});
|
2015-04-28 21:04:53 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should process the data correctly for the index feed', function (done) {
|
|
|
|
res.send = function send(xmlData) {
|
2016-02-08 00:27:01 +03:00
|
|
|
apiBrowseStub.calledOnce.should.be.true();
|
2016-02-11 18:03:33 +03:00
|
|
|
apiBrowseStub.calledWith({page: 1, include: 'author,tags'}).should.be.true();
|
2015-04-28 21:04:53 +03:00
|
|
|
xmlData.should.match(/<channel><title><!\[CDATA\[Test\]\]><\/title>/);
|
|
|
|
done();
|
|
|
|
};
|
|
|
|
|
2017-08-14 06:21:24 +03:00
|
|
|
res.locals.channel = channelConfig.get('index');
|
|
|
|
res.locals.channel.isRSS = true;
|
2015-04-28 21:04:53 +03:00
|
|
|
rss(req, res, failTest(done));
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should process the data correctly for a tag feed', function (done) {
|
|
|
|
// setup
|
|
|
|
req.originalUrl = '/tag/magic/rss/';
|
|
|
|
req.params.slug = 'magic';
|
2017-08-14 06:21:24 +03:00
|
|
|
res.locals.channel = channelConfig.get('tag');
|
|
|
|
res.locals.channel.isRSS = true;
|
2015-04-28 21:04:53 +03:00
|
|
|
|
|
|
|
// test
|
|
|
|
res.send = function send(xmlData) {
|
2016-02-08 00:27:01 +03:00
|
|
|
apiBrowseStub.calledOnce.should.be.true();
|
2017-03-21 11:24:11 +03:00
|
|
|
apiBrowseStub.calledWith({
|
|
|
|
page: 1,
|
|
|
|
filter: 'tags:\'magic\'+tags.visibility:\'public\'',
|
|
|
|
include: 'author,tags'
|
|
|
|
}).should.be.true();
|
2016-02-08 00:27:01 +03:00
|
|
|
apiTagStub.calledOnce.should.be.true();
|
2015-04-28 21:04:53 +03:00
|
|
|
xmlData.should.match(/<channel><title><!\[CDATA\[Magic - Test\]\]><\/title>/);
|
|
|
|
done();
|
|
|
|
};
|
|
|
|
|
|
|
|
rss(req, res, failTest(done));
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should process the data correctly for an author feed', function (done) {
|
|
|
|
req.originalUrl = '/author/joe/rss/';
|
|
|
|
req.params.slug = 'joe';
|
2017-08-14 06:21:24 +03:00
|
|
|
res.locals.channel = channelConfig.get('author');
|
|
|
|
res.locals.channel.isRSS = true;
|
2015-04-28 21:04:53 +03:00
|
|
|
|
|
|
|
// test
|
|
|
|
res.send = function send(xmlData) {
|
2016-02-08 00:27:01 +03:00
|
|
|
apiBrowseStub.calledOnce.should.be.true();
|
2016-02-11 18:03:33 +03:00
|
|
|
apiBrowseStub.calledWith({page: 1, filter: 'author:\'joe\'', include: 'author,tags'}).should.be.true();
|
2016-02-08 00:27:01 +03:00
|
|
|
apiUserStub.calledOnce.should.be.true();
|
2015-04-28 21:04:53 +03:00
|
|
|
xmlData.should.match(/<channel><title><!\[CDATA\[Joe Blogs - Test\]\]><\/title>/);
|
|
|
|
done();
|
|
|
|
};
|
|
|
|
|
|
|
|
rss(req, res, failTest(done));
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('caching', function () {
|
|
|
|
beforeEach(function () {
|
|
|
|
req = {
|
|
|
|
params: {},
|
|
|
|
originalUrl: '/rss/'
|
|
|
|
};
|
|
|
|
|
|
|
|
res = {
|
|
|
|
locals: {
|
|
|
|
safeVersion: '0.6'
|
|
|
|
},
|
|
|
|
set: sinon.stub()
|
|
|
|
};
|
|
|
|
|
2015-12-14 23:05:11 +03:00
|
|
|
configUtils.set({url: 'http://my-ghost-blog.com'});
|
2015-04-28 21:04:53 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should not rebuild xml for same data and url', function (done) {
|
|
|
|
var xmlData;
|
|
|
|
rss.__set__('getData', function () {
|
|
|
|
return Promise.resolve({
|
|
|
|
title: 'Test Title',
|
|
|
|
description: 'Testing Desc',
|
|
|
|
permalinks: '/:slug/',
|
|
|
|
results: {posts: [], meta: {pagination: {pages: 1}}}
|
|
|
|
});
|
|
|
|
});
|
2017-08-14 06:21:24 +03:00
|
|
|
res.locals.channel = channelConfig.get('index');
|
|
|
|
res.locals.channel.isRSS = true;
|
2015-04-28 21:04:53 +03:00
|
|
|
|
|
|
|
function secondCall() {
|
|
|
|
res.send = function sendFirst(data) {
|
|
|
|
// The data should be identical, no changing lastBuildDate
|
|
|
|
data.should.equal(xmlData);
|
|
|
|
|
|
|
|
// Now call done!
|
|
|
|
done();
|
|
|
|
};
|
|
|
|
|
|
|
|
rss(req, res, failTest(done));
|
|
|
|
}
|
|
|
|
|
|
|
|
function firstCall() {
|
|
|
|
res.send = function sendFirst(data) {
|
|
|
|
xmlData = data;
|
|
|
|
|
|
|
|
// Call RSS again to check that we didn't rebuild
|
|
|
|
secondCall();
|
|
|
|
};
|
|
|
|
|
|
|
|
rss(req, res, failTest(done));
|
|
|
|
}
|
|
|
|
|
|
|
|
firstCall();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2015-12-10 18:00:02 +03:00
|
|
|
describe('pagination', function () {
|
2015-04-28 21:04:53 +03:00
|
|
|
beforeEach(function () {
|
|
|
|
res = {
|
|
|
|
locals: {version: ''},
|
|
|
|
redirect: sandbox.spy(),
|
|
|
|
render: sandbox.spy()
|
|
|
|
};
|
|
|
|
|
|
|
|
rss.__set__('getData', function () {
|
|
|
|
return Promise.resolve({
|
|
|
|
title: 'Test',
|
|
|
|
description: 'Testing',
|
|
|
|
permalinks: '/:slug/',
|
|
|
|
results: {posts: [], meta: {pagination: {pages: 3}}}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2015-12-10 18:00:02 +03:00
|
|
|
it('Should 404 if page number too big', function (done) {
|
2017-04-03 18:29:36 +03:00
|
|
|
configUtils.set({url: 'http://localhost:82832/'});
|
2015-04-28 21:04:53 +03:00
|
|
|
|
|
|
|
req = {params: {page: 4}, route: {path: '/rss/:page/'}};
|
|
|
|
req.originalUrl = req.route.path.replace(':page', req.params.page);
|
2017-08-14 06:21:24 +03:00
|
|
|
res.locals.channel = channelConfig.get('index');
|
|
|
|
res.locals.channel.isRSS = true;
|
2015-04-28 21:04:53 +03:00
|
|
|
|
2015-12-10 18:00:02 +03:00
|
|
|
rss(req, res, function (err) {
|
|
|
|
should.exist(err);
|
2016-02-17 17:51:57 +03:00
|
|
|
err.statusCode.should.eql(404);
|
2016-02-08 00:27:01 +03:00
|
|
|
res.redirect.called.should.be.false();
|
|
|
|
res.render.called.should.be.false();
|
2015-04-28 21:04:53 +03:00
|
|
|
done();
|
|
|
|
}).catch(done);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('Redirects to last page if page number too big with subdirectory', function (done) {
|
2017-04-03 18:29:36 +03:00
|
|
|
configUtils.set({url: 'http://localhost:82832/blog'});
|
2015-04-28 21:04:53 +03:00
|
|
|
|
|
|
|
req = {params: {page: 4}, route: {path: '/rss/:page/'}};
|
|
|
|
req.originalUrl = req.route.path.replace(':page', req.params.page);
|
2017-08-14 06:21:24 +03:00
|
|
|
res.locals.channel = channelConfig.get('index');
|
|
|
|
res.locals.channel.isRSS = true;
|
2015-04-28 21:04:53 +03:00
|
|
|
|
2015-12-10 18:00:02 +03:00
|
|
|
rss(req, res, function (err) {
|
|
|
|
should.exist(err);
|
2016-02-17 17:51:57 +03:00
|
|
|
err.statusCode.should.eql(404);
|
2016-02-08 00:27:01 +03:00
|
|
|
res.redirect.called.should.be.false();
|
|
|
|
res.render.called.should.be.false();
|
2015-04-28 21:04:53 +03:00
|
|
|
done();
|
|
|
|
}).catch(done);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|