Skip to content

Commit

Permalink
deps: ghost-gql@0.0.3
Browse files Browse the repository at this point in the history
- adds test for nested null/not null query issue
- make use of new findStatement tool
  • Loading branch information
ErisDS committed Nov 16, 2015
1 parent b64a0cc commit a3bd00d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 20 deletions.
14 changes: 4 additions & 10 deletions core/server/models/base/utils.js
Expand Up @@ -2,13 +2,13 @@
* # Utils
* Parts of the model code which can be split out and unit tested
*/
var _ = require('lodash'),
var _ = require('lodash'),
gql = require('ghost-gql'),
processGQLResult,
tagUpdate;

processGQLResult = function processGQLResult(itemCollection, options) {
var joinTables = options.filter.joins,
tagsHasIn = false;
var joinTables = options.filter.joins;

if (joinTables && joinTables.indexOf('tags') > -1) {
// We need to use leftOuterJoin to insure we still include posts which don't have tags in the result
Expand All @@ -21,13 +21,7 @@ processGQLResult = function processGQLResult(itemCollection, options) {
// TODO move the order handling to the query building that is currently inside pagination
// TODO make the order handling in pagination handle orderByRaw
// TODO extend this handling to all joins
_.each(options.filter.statements, function (statement) {
if (statement.op === 'IN' && statement.prop.match(/tags/)) {
tagsHasIn = true;
}
});

if (tagsHasIn) {
if (gql.json.findStatement(options.filter.statements, {prop: /^tags/, op: 'IN'})) {
// TODO make this count the number of MATCHING tags, not just the number of tags
itemCollection.query('orderByRaw', 'count(tags.id) DESC');
}
Expand Down
18 changes: 9 additions & 9 deletions core/test/integration/api/advanced_browse_spec.js
Expand Up @@ -126,10 +126,10 @@ describe('Filter Param Spec', function () {
});
});

describe('4. Posts - filter="author:[leslie,pat]+(featured:true,tag:audio)"', function () {
describe('4. Posts - filter="author:[leslie,pat]+(tag:audio,image:-null)"', function () {
// Note that `pat` doesn't exist (it's `pat-smith`)
it('Will fetch posts by the author `leslie` or `pat` which are either featured or have tag `audio`.', function (done) {
PostAPI.browse({filter: 'author:[leslie,pat]+(featured:true,tag:audio)', include: 'author,tags'}).then(function (result) {
it('Will fetch posts by the author `leslie` or `pat` which are either have tag `audio` or an image.', function (done) {
PostAPI.browse({filter: 'author:[leslie,pat]+(tag:audio,image:-null)', include: 'author,tags'}).then(function (result) {
var ids, authors;
// 1. Result should have the correct base structure
should.exist(result);
Expand All @@ -138,7 +138,7 @@ describe('Filter Param Spec', function () {

// 2. The data part of the response should be correct
// We should have 2 matching items
result.posts.should.be.an.Array.with.lengthOf(4);
result.posts.should.be.an.Array.with.lengthOf(6);

// Each post must either have the author 'leslie' or 'pat'
authors = _.map(result.posts, function (post) {
Expand All @@ -148,26 +148,26 @@ describe('Filter Param Spec', function () {

// Each post must either be featured or have the tag 'audio'
_.each(result.posts, function (post) {
var tags;
var tags = _.pluck(post.tags, 'slug');
// This construct ensures we get an assertion or a failure
if (post.featured === 'true') {
post.featured.should.be.true;
if (!_.isEmpty(post.image)) {
post.image.should.not.be.empty;
} else {
tags = _.pluck(post.tags, 'slug');
tags.should.containEql('audio');
}
});

ids = _.pluck(result.posts, 'id');
ids.should.eql([14, 12, 9, 8]);
ids.should.eql([14, 12, 11, 9, 8, 7]);

// 3. The meta object should contain the right details
result.meta.should.have.property('pagination');
result.meta.pagination.should.be.an.Object.with.properties(['page', 'limit', 'pages', 'total', 'next', 'prev']);
result.meta.pagination.page.should.eql(1);
result.meta.pagination.limit.should.eql(15);
result.meta.pagination.pages.should.eql(1);
result.meta.pagination.total.should.eql(4);
result.meta.pagination.total.should.eql(6);
should.equal(result.meta.pagination.next, null);
should.equal(result.meta.pagination.prev, null);

Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -41,7 +41,7 @@
"express-hbs": "0.8.4",
"extract-zip": "1.1.1",
"fs-extra": "0.24.0",
"ghost-gql": "0.0.2",
"ghost-gql": "0.0.3",
"glob": "5.0.15",
"html-to-text": "1.3.2",
"intl": "1.0.0",
Expand Down

0 comments on commit a3bd00d

Please sign in to comment.