Merge pull request #6083 from ErisDS/filter-missing

Add filter param for tags & users
This commit is contained in:
Sebastian Gierlinger 2015-11-17 08:33:56 +01:00
commit 6b31f362a2
4 changed files with 99 additions and 7 deletions

View File

@ -79,7 +79,7 @@ Tag = ghostBookshelf.Model.extend({
// whitelists for the `options` hash argument on methods, by method name.
// these are the only options that can be passed to Bookshelf / Knex.
validOptions = {
findPage: ['page', 'limit', 'columns', 'order']
findPage: ['page', 'limit', 'columns', 'filter', 'order']
};
if (validOptions[methodName]) {

View File

@ -228,7 +228,7 @@ User = ghostBookshelf.Model.extend({
findOne: ['withRelated', 'status'],
setup: ['id'],
edit: ['withRelated', 'id'],
findPage: ['page', 'limit', 'columns', 'order', 'status']
findPage: ['page', 'limit', 'columns', 'filter', 'order', 'status']
};
if (validOptions[methodName]) {

View File

@ -178,7 +178,7 @@ describe('Filter Param Spec', function () {
describe('5. Users - filter="posts.tags:photo" order="posts.count DESC" limit="3"', function () {
it('Will fetch the 3 most prolific users who write posts with the tag `photo` ordered by most posts.', function (done) {
UserAPI.browse({filter: 'posts.tags:photo', order: 'posts.count DESC', limit: 3}).then(function (result) {
UserAPI.browse({filter: 'posts.tags:special', order: 'posts.count DESC', limit: 3}).then(function (result) {
var ids;
// 1. Result should have the correct base structure
should.exist(result);
@ -230,6 +230,79 @@ describe('Filter Param Spec', function () {
}).catch(done);
});
});
describe('7. Users filter: "website:-null", order: "website"', function () {
it('Will fetch users that have a website and order them by website', function (done) {
UserAPI.browse({filter: 'website:-null', order: 'website ASC'}).then(function (result) {
var ids;
// 1. Result should have the correct base structure
should.exist(result);
result.should.have.property('users');
result.should.have.property('meta');
// 2. The data part of the response should be correct
// We should have 2 matching items
result.users.should.be.an.Array.with.lengthOf(2);
ids = _.pluck(result.users, 'id');
ids.should.eql([2, 1]);
should.exist(result.users[0].website);
should.exist(result.users[1].website);
// 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(2);
should.equal(result.meta.pagination.next, null);
should.equal(result.meta.pagination.prev, null);
done();
}).catch(done);
});
});
describe('8. Tags filter: "image:-null+description:-null"', function () {
it('Will fetch tags which have an image and a description', function (done) {
TagAPI.browse({filter: 'image:-null+description:-null', order: 'name ASC'}).then(function (result) {
var ids;
// 1. Result should have the correct base structure
should.exist(result);
result.should.have.property('tags');
result.should.have.property('meta');
// 2. The data part of the response should be correct
// We should have 3 matching items
result.tags.should.be.an.Array.with.lengthOf(3);
ids = _.pluck(result.tags, 'id');
ids.should.eql([4, 3, 2]);
should.exist(result.tags[0].image);
should.exist(result.tags[1].image);
should.exist(result.tags[2].image);
should.exist(result.tags[0].description);
should.exist(result.tags[1].description);
should.exist(result.tags[2].description);
// 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(3);
should.equal(result.meta.pagination.next, null);
should.equal(result.meta.pagination.prev, null);
done();
}).catch(done);
});
});
});
describe.skip('Count capabilities', function () {

View File

@ -14,22 +14,33 @@ data.tags = [
{
name: 'photo',
slug: 'photo',
image: 'some/image/path.jpg',
description: 'Photo posts',
created_by: 2
},
{
name: 'Video',
slug: 'video',
image: 'some/image/path.jpg',
description: 'Video posts',
created_by: 1
},
{
name: 'Audio',
slug: 'audio',
image: 'some/image/path.jpg',
description: 'Audio posts',
created_by: 1
},
{
name: 'No Posts',
slug: 'no-posts',
created_by: 2
},
{
name: 'Special',
slug: 'special',
created_by: 2
}
];
@ -39,12 +50,20 @@ data.users = [
name: 'Leslie Jones',
slug: 'leslie',
email: 'ljones@nothere.com',
password: '$2a$10$.pZeeBE0gHXd0PTnbT/ph.GEKgd0Wd3q2pWna3ynTGBkPKnGIKZL6'
password: '$2a$10$.pZeeBE0gHXd0PTnbT/ph.GEKgd0Wd3q2pWna3ynTGBkPKnGIKZL6',
website: 'http://twitter.com/ljonestestuser'
},
{
name: 'Pat Smith',
slug: 'pat-smith',
email: 'pat-smith@nothere.com',
password: '$2a$10$.pZeeBE0gHXd0PTnbT/ph.GEKgd0Wd3q2pWna3ynTGBkPKnGIKZL6',
website: 'http://github.com/patsmithtestuser'
},
{
name: 'Cameron Howe',
slug: 'camhowe',
email: 'camhowe@c-e-is-real.com',
password: '$2a$10$.pZeeBE0gHXd0PTnbT/ph.GEKgd0Wd3q2pWna3ynTGBkPKnGIKZL6'
}
];
@ -64,7 +83,7 @@ data.posts = [
markdown: 'Hello World!',
featured: false,
author_id: 2,
tags: [2, 3, 4]
tags: [2, 3, 4, 6]
},
{
title: 'Third Post',
@ -88,7 +107,7 @@ data.posts = [
markdown: 'Hello World!',
featured: true,
author_id: 2,
tags: []
tags: [6]
},
{
title: 'Sixth Post',
@ -97,7 +116,7 @@ data.posts = [
featured: false,
author_id: 2,
image: 'some/image/path.jpg',
tags: [1, 4]
tags: [1, 4, 6]
},
{
title: 'Seventh Post',