2017-03-21 11:24:11 +03:00
|
|
|
var should = require('should'),
|
|
|
|
sinon = require('sinon'),
|
|
|
|
Promise = require('bluebird'),
|
2015-06-27 18:42:10 +03:00
|
|
|
|
2017-06-08 22:34:20 +03:00
|
|
|
// Stuff we are testing
|
2017-03-21 11:24:11 +03:00
|
|
|
helpers = require('../../../server/helpers'),
|
2017-06-08 22:34:20 +03:00
|
|
|
models = require('../../../server/models'),
|
2017-03-21 11:24:11 +03:00
|
|
|
api = require('../../../server/api'),
|
2015-10-22 13:12:21 +03:00
|
|
|
|
2017-12-14 05:01:23 +03:00
|
|
|
labs = require('../../../server/services/labs'),
|
2015-11-03 22:17:24 +03:00
|
|
|
|
2015-10-22 13:12:21 +03:00
|
|
|
sandbox = sinon.sandbox.create();
|
2015-06-27 18:42:10 +03:00
|
|
|
|
|
|
|
describe('{{#get}} helper', function () {
|
2017-03-23 22:00:58 +03:00
|
|
|
var fn, inverse, labsStub;
|
2018-10-17 10:23:59 +03:00
|
|
|
let locals = {};
|
2015-06-27 18:42:10 +03:00
|
|
|
|
2017-06-08 22:34:20 +03:00
|
|
|
before(function () {
|
|
|
|
models.init();
|
|
|
|
});
|
|
|
|
|
2015-06-27 18:42:10 +03:00
|
|
|
beforeEach(function () {
|
2015-10-22 13:12:21 +03:00
|
|
|
fn = sandbox.spy();
|
|
|
|
inverse = sandbox.spy();
|
2017-03-23 22:00:58 +03:00
|
|
|
labsStub = sandbox.stub(labs, 'isSet').returns(true);
|
2018-10-17 10:23:59 +03:00
|
|
|
|
|
|
|
locals = {root: {_locals: {apiVersion: 'v0.1'}}};
|
2015-06-27 18:42:10 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(function () {
|
|
|
|
sandbox.restore();
|
|
|
|
});
|
|
|
|
|
2017-03-23 22:00:58 +03:00
|
|
|
it('errors correctly if labs flag not set', function (done) {
|
|
|
|
labsStub.returns(false);
|
|
|
|
|
|
|
|
helpers.get.call(
|
|
|
|
{},
|
|
|
|
'posts',
|
|
|
|
{hash: {}, fn: fn, inverse: inverse}
|
|
|
|
).then(function (result) {
|
|
|
|
labsStub.calledOnce.should.be.true();
|
|
|
|
fn.called.should.be.false();
|
|
|
|
inverse.called.should.be.false();
|
|
|
|
|
|
|
|
should.exist(result);
|
|
|
|
result.should.be.a.Function();
|
|
|
|
result().should.be.an.Object().with.property(
|
|
|
|
'string',
|
|
|
|
'<script>console.error("The {{get}} helper is not available. ' +
|
2017-08-15 11:50:36 +03:00
|
|
|
'The Public API flag must be enabled in labs if you wish to use the {{get}} helper. ' +
|
2017-06-08 22:34:20 +03:00
|
|
|
'See https://help.ghost.org/hc/en-us/articles/115000301672-Public-API-Beta");</script>'
|
2017-03-23 22:00:58 +03:00
|
|
|
);
|
|
|
|
|
|
|
|
done();
|
|
|
|
}).catch(done);
|
2015-06-27 18:42:10 +03:00
|
|
|
});
|
|
|
|
|
2018-11-06 16:08:13 +03:00
|
|
|
describe('posts v0.1', function () {
|
2015-10-24 23:39:47 +03:00
|
|
|
var browsePostsStub, readPostsStub, readTagsStub, readUsersStub, testPostsArr = [
|
2017-03-21 11:24:11 +03:00
|
|
|
{id: 1, title: 'Test Post 1', author: {slug: 'cameron'}},
|
|
|
|
{id: 2, title: 'Test Post 2', author: {slug: 'cameron'}, featured: true},
|
|
|
|
{id: 3, title: 'Test Post 3', tags: [{slug: 'test'}]},
|
|
|
|
{id: 4, title: 'Test Post 4'}
|
|
|
|
],
|
2015-10-22 13:12:21 +03:00
|
|
|
meta = {pagination: {}};
|
2017-03-23 22:00:58 +03:00
|
|
|
|
2015-06-27 18:42:10 +03:00
|
|
|
beforeEach(function () {
|
2018-10-17 10:23:59 +03:00
|
|
|
browsePostsStub = sandbox.stub(api["v0.1"].posts, 'browse');
|
|
|
|
readPostsStub = sandbox.stub(api["v0.1"].posts, 'read');
|
|
|
|
readTagsStub = sandbox.stub(api["v0.1"].tags, 'read').returns(new Promise.resolve({tags: []}));
|
|
|
|
readUsersStub = sandbox.stub(api["v0.1"].users, 'read').returns(new Promise.resolve({users: []}));
|
2015-10-24 23:39:47 +03:00
|
|
|
|
2015-12-14 16:19:38 +03:00
|
|
|
browsePostsStub.returns(new Promise.resolve({posts: testPostsArr, meta: meta}));
|
2017-03-21 11:24:11 +03:00
|
|
|
browsePostsStub.withArgs({limit: '3'}).returns(new Promise.resolve({
|
|
|
|
posts: testPostsArr.slice(0, 3),
|
|
|
|
meta: meta
|
|
|
|
}));
|
2015-10-24 23:39:47 +03:00
|
|
|
browsePostsStub.withArgs({limit: '1'}).returns(new Promise.resolve({posts: testPostsArr.slice(0, 1)}));
|
|
|
|
browsePostsStub.withArgs({filter: 'tags:test'}).returns(new Promise.resolve({posts: testPostsArr.slice(2, 3)}));
|
|
|
|
browsePostsStub.withArgs({filter: 'tags:none'}).returns(new Promise.resolve({posts: []}));
|
|
|
|
browsePostsStub.withArgs({filter: 'author:cameron'}).returns(new Promise.resolve({posts: testPostsArr.slice(0, 2)}));
|
|
|
|
browsePostsStub.withArgs({filter: 'featured:true'}).returns(new Promise.resolve({posts: testPostsArr.slice(2, 3)}));
|
|
|
|
readPostsStub.withArgs({id: '2'}).returns(new Promise.resolve({posts: testPostsArr.slice(1, 2)}));
|
2015-06-27 18:42:10 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should handle default browse posts call', function (done) {
|
|
|
|
helpers.get.call(
|
|
|
|
{},
|
|
|
|
'posts',
|
2018-10-17 10:23:59 +03:00
|
|
|
{hash: {}, data: locals, fn: fn, inverse: inverse}
|
2015-06-27 18:42:10 +03:00
|
|
|
).then(function () {
|
2017-03-23 22:00:58 +03:00
|
|
|
labsStub.calledOnce.should.be.true();
|
|
|
|
|
2016-02-08 00:27:01 +03:00
|
|
|
fn.called.should.be.true();
|
|
|
|
fn.firstCall.args[0].should.be.an.Object().with.property('posts');
|
2015-06-27 18:42:10 +03:00
|
|
|
fn.firstCall.args[0].posts.should.eql(testPostsArr);
|
|
|
|
fn.firstCall.args[0].posts.should.have.lengthOf(4);
|
2016-02-08 00:27:01 +03:00
|
|
|
inverse.called.should.be.false();
|
2015-06-27 18:42:10 +03:00
|
|
|
|
|
|
|
done();
|
|
|
|
}).catch(done);
|
|
|
|
});
|
|
|
|
|
2015-12-14 16:19:38 +03:00
|
|
|
it('should return pagination and meta pagination with default browse posts call', function (done) {
|
|
|
|
helpers.get.call(
|
|
|
|
{},
|
|
|
|
'posts',
|
2018-10-17 10:23:59 +03:00
|
|
|
{hash: {}, data: locals, fn: fn, inverse: inverse}
|
2015-12-14 16:19:38 +03:00
|
|
|
).then(function () {
|
2016-02-08 00:27:01 +03:00
|
|
|
fn.firstCall.args[0].pagination.should.be.an.Object();
|
|
|
|
fn.firstCall.args[0].meta.should.be.an.Object();
|
|
|
|
fn.firstCall.args[0].meta.pagination.should.be.an.Object();
|
|
|
|
inverse.called.should.be.false();
|
2015-12-14 16:19:38 +03:00
|
|
|
|
|
|
|
done();
|
|
|
|
}).catch(done);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should not return pagination if meta pagination does not exist', function (done) {
|
|
|
|
helpers.get.call(
|
|
|
|
{},
|
|
|
|
'posts',
|
2018-10-17 10:23:59 +03:00
|
|
|
{hash: {limit: '1'}, data: locals, fn: fn, inverse: inverse}
|
2015-12-14 16:19:38 +03:00
|
|
|
).then(function () {
|
|
|
|
should.not.exist(fn.firstCall.args[0].pagination);
|
|
|
|
should.not.exist(fn.firstCall.args[0].meta);
|
2016-02-08 00:27:01 +03:00
|
|
|
inverse.called.should.be.false();
|
2015-12-14 16:19:38 +03:00
|
|
|
|
|
|
|
done();
|
|
|
|
}).catch(done);
|
|
|
|
});
|
|
|
|
|
2015-06-27 18:42:10 +03:00
|
|
|
it('should handle browse posts call with limit 3', function (done) {
|
|
|
|
helpers.get.call(
|
|
|
|
{},
|
|
|
|
'posts',
|
2018-10-17 10:23:59 +03:00
|
|
|
{hash: {limit: '3'}, data: locals, fn: fn, inverse: inverse}
|
2015-06-27 18:42:10 +03:00
|
|
|
).then(function () {
|
2017-03-21 11:24:11 +03:00
|
|
|
fn.calledOnce.should.be.true();
|
|
|
|
fn.firstCall.args[0].should.be.an.Object().with.property('posts');
|
|
|
|
fn.firstCall.args[0].posts.should.have.lengthOf(3);
|
|
|
|
fn.firstCall.args[0].posts.should.eql(testPostsArr.slice(0, 3));
|
|
|
|
inverse.called.should.be.false();
|
|
|
|
|
|
|
|
done();
|
|
|
|
}).catch(done);
|
2015-06-27 18:42:10 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should handle browse posts call with limit 1', function (done) {
|
|
|
|
helpers.get.call(
|
|
|
|
{},
|
|
|
|
'posts',
|
2018-10-17 10:23:59 +03:00
|
|
|
{hash: {limit: '1'}, data: locals, fn: fn, inverse: inverse}
|
2015-06-27 18:42:10 +03:00
|
|
|
).then(function () {
|
2017-03-21 11:24:11 +03:00
|
|
|
fn.calledOnce.should.be.true();
|
|
|
|
fn.firstCall.args[0].should.be.an.Object().with.property('posts');
|
|
|
|
fn.firstCall.args[0].posts.should.have.lengthOf(1);
|
|
|
|
fn.firstCall.args[0].posts.should.eql(testPostsArr.slice(0, 1));
|
|
|
|
inverse.called.should.be.false();
|
|
|
|
|
|
|
|
done();
|
|
|
|
}).catch(done);
|
2015-06-27 18:42:10 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should handle browse posts call with limit 1', function (done) {
|
|
|
|
helpers.get.call(
|
|
|
|
{},
|
|
|
|
'posts',
|
2018-10-17 10:23:59 +03:00
|
|
|
{hash: {limit: '1'}, data: locals, fn: fn, inverse: inverse}
|
2015-06-27 18:42:10 +03:00
|
|
|
).then(function () {
|
2017-03-21 11:24:11 +03:00
|
|
|
fn.calledOnce.should.be.true();
|
|
|
|
fn.firstCall.args[0].should.be.an.Object().with.property('posts');
|
|
|
|
fn.firstCall.args[0].posts.should.have.lengthOf(1);
|
|
|
|
fn.firstCall.args[0].posts.should.eql(testPostsArr.slice(0, 1));
|
|
|
|
inverse.called.should.be.false();
|
|
|
|
|
|
|
|
done();
|
|
|
|
}).catch(done);
|
2015-06-27 18:42:10 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should handle browse post call with explicit tag', function (done) {
|
|
|
|
helpers.get.call(
|
|
|
|
{},
|
|
|
|
'posts',
|
2018-10-17 10:23:59 +03:00
|
|
|
{hash: {filter: 'tags:test'}, data: locals, fn: fn, inverse: inverse}
|
2015-06-27 18:42:10 +03:00
|
|
|
).then(function () {
|
2016-02-08 00:27:01 +03:00
|
|
|
fn.calledOnce.should.be.true();
|
|
|
|
fn.firstCall.args[0].should.be.an.Object().with.property('posts');
|
2015-06-27 18:42:10 +03:00
|
|
|
fn.firstCall.args[0].posts.should.have.lengthOf(1);
|
|
|
|
fn.firstCall.args[0].posts.should.eql(testPostsArr.slice(2, 3));
|
2016-02-08 00:27:01 +03:00
|
|
|
inverse.called.should.be.false();
|
2015-06-27 18:42:10 +03:00
|
|
|
done();
|
|
|
|
}).catch(done);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should handle browse post call with explicit author', function (done) {
|
|
|
|
helpers.get.call(
|
|
|
|
{},
|
|
|
|
'posts',
|
2018-10-17 10:23:59 +03:00
|
|
|
{hash: {filter: 'author:cameron'}, data: locals, fn: fn, inverse: inverse}
|
2015-06-27 18:42:10 +03:00
|
|
|
).then(function () {
|
2016-02-08 00:27:01 +03:00
|
|
|
fn.calledOnce.should.be.true();
|
|
|
|
fn.firstCall.args[0].should.be.an.Object().with.property('posts');
|
2015-06-27 18:42:10 +03:00
|
|
|
fn.firstCall.args[0].posts.should.have.lengthOf(2);
|
|
|
|
fn.firstCall.args[0].posts.should.eql(testPostsArr.slice(0, 2));
|
2016-02-08 00:27:01 +03:00
|
|
|
inverse.called.should.be.false();
|
2015-06-27 18:42:10 +03:00
|
|
|
done();
|
|
|
|
}).catch(done);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should handle browse post call with featured:true', function (done) {
|
|
|
|
helpers.get.call(
|
|
|
|
{},
|
|
|
|
'posts',
|
2018-10-17 10:23:59 +03:00
|
|
|
{hash: {filter: 'featured:true'}, data: locals, fn: fn, inverse: inverse}
|
2015-06-27 18:42:10 +03:00
|
|
|
).then(function () {
|
2016-02-08 00:27:01 +03:00
|
|
|
fn.calledOnce.should.be.true();
|
|
|
|
fn.firstCall.args[0].should.be.an.Object().with.property('posts');
|
2015-06-27 18:42:10 +03:00
|
|
|
fn.firstCall.args[0].posts.should.have.lengthOf(1);
|
|
|
|
fn.firstCall.args[0].posts.should.eql(testPostsArr.slice(2, 3));
|
2016-02-08 00:27:01 +03:00
|
|
|
inverse.called.should.be.false();
|
2015-06-27 18:42:10 +03:00
|
|
|
done();
|
|
|
|
}).catch(done);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should handle read post by id call', function (done) {
|
|
|
|
helpers.get.call(
|
|
|
|
{},
|
|
|
|
'posts',
|
2018-10-17 10:23:59 +03:00
|
|
|
{hash: {id: '2'}, data: locals, fn: fn, inverse: inverse}
|
2015-06-27 18:42:10 +03:00
|
|
|
).then(function () {
|
2016-02-08 00:27:01 +03:00
|
|
|
fn.calledOnce.should.be.true();
|
|
|
|
fn.firstCall.args[0].should.be.an.Object().with.property('posts');
|
2015-06-27 18:42:10 +03:00
|
|
|
fn.firstCall.args[0].posts.should.have.lengthOf(1);
|
|
|
|
fn.firstCall.args[0].posts.should.eql(testPostsArr.slice(1, 2));
|
2016-02-08 00:27:01 +03:00
|
|
|
inverse.called.should.be.false();
|
2015-06-27 18:42:10 +03:00
|
|
|
|
|
|
|
done();
|
|
|
|
}).catch(done);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should handle empty result set', function (done) {
|
|
|
|
helpers.get.call(
|
|
|
|
{},
|
|
|
|
'posts',
|
2018-10-17 10:23:59 +03:00
|
|
|
{hash: {filter: 'tags:none'}, data: locals, fn: fn, inverse: inverse}
|
2015-06-27 18:42:10 +03:00
|
|
|
).then(function () {
|
2017-03-14 19:44:52 +03:00
|
|
|
fn.calledOnce.should.be.true();
|
|
|
|
fn.firstCall.args[0].should.be.an.Object().with.property('posts');
|
|
|
|
fn.firstCall.args[0].posts.should.have.lengthOf(0);
|
|
|
|
inverse.called.should.be.false();
|
2015-06-27 18:42:10 +03:00
|
|
|
|
|
|
|
done();
|
|
|
|
}).catch(done);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-11-06 16:08:13 +03:00
|
|
|
describe('users v0.1', function () {
|
|
|
|
let browseUsersStub;
|
|
|
|
const meta = {pagination: {}};
|
|
|
|
|
|
|
|
beforeEach(function () {
|
|
|
|
browseUsersStub = sandbox.stub(api["v0.1"].users, 'browse');
|
|
|
|
browseUsersStub.returns(new Promise.resolve({users: [], meta: meta}));
|
|
|
|
});
|
|
|
|
|
|
|
|
it('browse users v0.1', function (done) {
|
|
|
|
helpers.get.call(
|
|
|
|
{},
|
|
|
|
'users',
|
|
|
|
{hash: {}, data: locals, fn: fn, inverse: inverse}
|
|
|
|
).then(function () {
|
|
|
|
labsStub.calledOnce.should.be.true();
|
|
|
|
|
|
|
|
fn.called.should.be.true();
|
|
|
|
fn.firstCall.args[0].should.be.an.Object().with.property('users');
|
|
|
|
fn.firstCall.args[0].users.should.eql([]);
|
|
|
|
inverse.called.should.be.false();
|
|
|
|
|
|
|
|
done();
|
|
|
|
}).catch(done);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('users v2', function () {
|
|
|
|
let browseUsersStub;
|
|
|
|
const meta = {pagination: {}};
|
|
|
|
|
|
|
|
beforeEach(function () {
|
|
|
|
locals = {root: {_locals: {apiVersion: 'v2'}}};
|
|
|
|
|
|
|
|
browseUsersStub = sandbox.stub(api["v2"], 'users').get(() => {
|
|
|
|
return {
|
|
|
|
browse: sandbox.stub().resolves({users: [], meta: meta})
|
|
|
|
};
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('browse users', function (done) {
|
|
|
|
helpers.get.call(
|
|
|
|
{},
|
|
|
|
'users',
|
|
|
|
{hash: {}, data: locals, fn: fn, inverse: inverse}
|
|
|
|
).then(function () {
|
|
|
|
labsStub.calledOnce.should.be.true();
|
|
|
|
|
|
|
|
fn.called.should.be.true();
|
|
|
|
fn.firstCall.args[0].should.be.an.Object().with.property('users');
|
|
|
|
fn.firstCall.args[0].users.should.eql([]);
|
|
|
|
inverse.called.should.be.false();
|
|
|
|
|
|
|
|
done();
|
|
|
|
}).catch(done);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2015-06-27 18:42:10 +03:00
|
|
|
describe('general error handling', function () {
|
|
|
|
it('should return an error for an unknown resource', function (done) {
|
|
|
|
helpers.get.call(
|
|
|
|
{},
|
|
|
|
'magic',
|
2018-10-17 10:23:59 +03:00
|
|
|
{hash: {}, data: locals, fn: fn, inverse: inverse}
|
2015-06-27 18:42:10 +03:00
|
|
|
).then(function () {
|
2016-02-08 00:27:01 +03:00
|
|
|
fn.called.should.be.false();
|
|
|
|
inverse.calledOnce.should.be.true();
|
|
|
|
inverse.firstCall.args[1].should.be.an.Object().and.have.property('data');
|
|
|
|
inverse.firstCall.args[1].data.should.be.an.Object().and.have.property('error');
|
2015-06-27 18:42:10 +03:00
|
|
|
inverse.firstCall.args[1].data.error.should.eql('Invalid resource given to get helper');
|
|
|
|
|
|
|
|
done();
|
|
|
|
}).catch(done);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should handle error from the API', function (done) {
|
|
|
|
helpers.get.call(
|
|
|
|
{},
|
|
|
|
'posts',
|
2018-10-17 10:23:59 +03:00
|
|
|
{hash: {status: 'thing!'}, data: locals, fn: fn, inverse: inverse}
|
2015-06-27 18:42:10 +03:00
|
|
|
).then(function () {
|
2016-02-08 00:27:01 +03:00
|
|
|
fn.called.should.be.false();
|
|
|
|
inverse.calledOnce.should.be.true();
|
|
|
|
inverse.firstCall.args[1].should.be.an.Object().and.have.property('data');
|
|
|
|
inverse.firstCall.args[1].data.should.be.an.Object().and.have.property('error');
|
2015-06-27 18:42:10 +03:00
|
|
|
inverse.firstCall.args[1].data.error.should.match(/^Validation/);
|
|
|
|
|
|
|
|
done();
|
|
|
|
}).catch(done);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should show warning for call without any options', function (done) {
|
|
|
|
helpers.get.call(
|
|
|
|
{},
|
2018-10-17 10:23:59 +03:00
|
|
|
'posts',
|
|
|
|
{data: locals}
|
2015-06-27 18:42:10 +03:00
|
|
|
).then(function () {
|
2016-02-08 00:27:01 +03:00
|
|
|
fn.called.should.be.false();
|
|
|
|
inverse.called.should.be.false();
|
2015-06-27 18:42:10 +03:00
|
|
|
|
|
|
|
done();
|
|
|
|
}).catch(done);
|
|
|
|
});
|
|
|
|
});
|
2015-10-22 13:12:21 +03:00
|
|
|
|
|
|
|
describe('path resolution', function () {
|
2018-02-14 20:33:07 +03:00
|
|
|
var browseStub, readStub,
|
|
|
|
pubDate = new Date(),
|
2018-10-17 10:23:59 +03:00
|
|
|
resource = {
|
2018-02-14 20:33:07 +03:00
|
|
|
post: {id: 3, title: 'Test 3', author: {slug: 'cameron'}, tags: [{slug: 'test'}, {slug: 'magic'}], published_at: pubDate}
|
|
|
|
};
|
2015-10-22 13:12:21 +03:00
|
|
|
|
|
|
|
beforeEach(function () {
|
2018-10-17 10:23:59 +03:00
|
|
|
browseStub = sandbox.stub(api["v0.1"].posts, 'browse').returns(new Promise.resolve());
|
|
|
|
readStub = sandbox.stub(api["v0.1"].posts, 'read').returns(new Promise.resolve());
|
2015-10-22 13:12:21 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should resolve post.tags alias', function (done) {
|
|
|
|
helpers.get.call(
|
2018-10-17 10:23:59 +03:00
|
|
|
resource,
|
2015-10-22 13:12:21 +03:00
|
|
|
'posts',
|
2018-10-17 10:23:59 +03:00
|
|
|
{hash: {filter: 'tags:[{{post.tags}}]'}, data: locals, fn: fn, inverse: inverse}
|
2015-10-22 13:12:21 +03:00
|
|
|
).then(function () {
|
2016-02-08 00:27:01 +03:00
|
|
|
browseStub.firstCall.args.should.be.an.Array().with.lengthOf(1);
|
|
|
|
browseStub.firstCall.args[0].should.be.an.Object().with.property('filter');
|
2015-10-22 13:12:21 +03:00
|
|
|
browseStub.firstCall.args[0].filter.should.eql('tags:[test,magic]');
|
|
|
|
|
|
|
|
done();
|
|
|
|
}).catch(done);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should resolve post.author alias', function (done) {
|
|
|
|
helpers.get.call(
|
2018-10-17 10:23:59 +03:00
|
|
|
resource,
|
2015-10-22 13:12:21 +03:00
|
|
|
'posts',
|
2018-10-17 10:23:59 +03:00
|
|
|
{hash: {filter: 'author:{{post.author}}'}, data: locals, fn: fn, inverse: inverse}
|
2015-10-22 13:12:21 +03:00
|
|
|
).then(function () {
|
2016-02-08 00:27:01 +03:00
|
|
|
browseStub.firstCall.args.should.be.an.Array().with.lengthOf(1);
|
|
|
|
browseStub.firstCall.args[0].should.be.an.Object().with.property('filter');
|
2015-10-22 13:12:21 +03:00
|
|
|
browseStub.firstCall.args[0].filter.should.eql('author:cameron');
|
|
|
|
|
|
|
|
done();
|
|
|
|
}).catch(done);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should resolve basic path', function (done) {
|
|
|
|
helpers.get.call(
|
2018-10-17 10:23:59 +03:00
|
|
|
resource,
|
2015-10-22 13:12:21 +03:00
|
|
|
'posts',
|
2018-10-17 10:23:59 +03:00
|
|
|
{hash: {filter: 'id:-{{post.id}}'}, data: locals, fn: fn, inverse: inverse}
|
2015-10-22 13:12:21 +03:00
|
|
|
).then(function () {
|
2017-03-21 11:24:11 +03:00
|
|
|
browseStub.firstCall.args.should.be.an.Array().with.lengthOf(1);
|
|
|
|
browseStub.firstCall.args[0].should.be.an.Object().with.property('filter');
|
|
|
|
browseStub.firstCall.args[0].filter.should.eql('id:-3');
|
2015-10-22 13:12:21 +03:00
|
|
|
|
2017-03-21 11:24:11 +03:00
|
|
|
done();
|
|
|
|
}).catch(done);
|
2015-10-22 13:12:21 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should handle arrays the same as handlebars', function (done) {
|
|
|
|
helpers.get.call(
|
2018-10-17 10:23:59 +03:00
|
|
|
resource,
|
2015-10-22 13:12:21 +03:00
|
|
|
'posts',
|
2018-10-17 10:23:59 +03:00
|
|
|
{hash: {filter: 'tags:{{post.tags.[0].slug}}'}, data: locals, fn: fn, inverse: inverse}
|
2015-10-22 13:12:21 +03:00
|
|
|
).then(function () {
|
2016-02-08 00:27:01 +03:00
|
|
|
browseStub.firstCall.args.should.be.an.Array().with.lengthOf(1);
|
|
|
|
browseStub.firstCall.args[0].should.be.an.Object().with.property('filter');
|
2017-03-23 22:00:58 +03:00
|
|
|
browseStub.firstCall.args[0].filter.should.eql('tags:test');
|
2015-10-22 13:12:21 +03:00
|
|
|
|
|
|
|
done();
|
|
|
|
}).catch(done);
|
|
|
|
});
|
|
|
|
|
2018-02-14 20:33:07 +03:00
|
|
|
it('should handle dates', function (done) {
|
|
|
|
helpers.get.call(
|
2018-10-17 10:23:59 +03:00
|
|
|
resource,
|
2018-02-14 20:33:07 +03:00
|
|
|
'posts',
|
2018-10-17 10:23:59 +03:00
|
|
|
{hash: {filter: "published_at:<='{{post.published_at}}'"}, data: locals, fn: fn, inverse: inverse}
|
2018-02-14 20:33:07 +03:00
|
|
|
).then(function () {
|
|
|
|
browseStub.firstCall.args.should.be.an.Array().with.lengthOf(1);
|
|
|
|
browseStub.firstCall.args[0].should.be.an.Object().with.property('filter');
|
|
|
|
browseStub.firstCall.args[0].filter.should.eql(`published_at:<='${pubDate.toISOString()}'`);
|
|
|
|
|
|
|
|
done();
|
|
|
|
}).catch(done);
|
|
|
|
});
|
|
|
|
|
2015-10-22 13:12:21 +03:00
|
|
|
it('should output nothing if path does not resolve', function (done) {
|
|
|
|
helpers.get.call(
|
2018-10-17 10:23:59 +03:00
|
|
|
resource,
|
2015-10-22 13:12:21 +03:00
|
|
|
'posts',
|
2018-10-17 10:23:59 +03:00
|
|
|
{hash: {filter: 'id:{{post.thing}}'}, data: locals, fn: fn, inverse: inverse}
|
2015-10-22 13:12:21 +03:00
|
|
|
).then(function () {
|
2017-03-21 11:24:11 +03:00
|
|
|
browseStub.firstCall.args.should.be.an.Array().with.lengthOf(1);
|
|
|
|
browseStub.firstCall.args[0].should.be.an.Object().with.property('filter');
|
|
|
|
browseStub.firstCall.args[0].filter.should.eql('id:');
|
2015-10-22 13:12:21 +03:00
|
|
|
|
2017-03-21 11:24:11 +03:00
|
|
|
done();
|
|
|
|
}).catch(done);
|
2015-10-22 13:12:21 +03:00
|
|
|
});
|
|
|
|
});
|
2015-06-27 18:42:10 +03:00
|
|
|
});
|