mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-06 22:40:14 -05:00
deps: ghost-gql@0.0.3
- adds test for nested null/not null query issue - make use of new findStatement tool
This commit is contained in:
parent
b64a0cc1f4
commit
a3bd00d978
3 changed files with 14 additions and 20 deletions
|
@ -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
|
||||
|
@ -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');
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
@ -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) {
|
||||
|
@ -148,10 +148,10 @@ 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');
|
||||
|
@ -159,7 +159,7 @@ describe('Filter Param Spec', function () {
|
|||
});
|
||||
|
||||
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');
|
||||
|
@ -167,7 +167,7 @@ describe('Filter Param Spec', function () {
|
|||
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);
|
||||
|
||||
|
|
|
@ -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",
|
||||
|
|
Loading…
Reference in a new issue