Skip to content

Commit 87754dd

Browse files
author
troy.steuwer
committed
#62 adding failing tests for filtering
1 parent 01daf6d commit 87754dd

File tree

1 file changed

+49
-8
lines changed

1 file changed

+49
-8
lines changed

test/find.test.js

Lines changed: 49 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ describe('loopback json api component find methods', function () {
6868
});
6969
});
7070

71-
describe('self links', function () {
71+
describe('Self links', function () {
7272
beforeEach(function (done) {
7373
Post.create({
7474
title: 'my post',
@@ -141,7 +141,7 @@ describe('loopback json api component find methods', function () {
141141
});
142142
});
143143

144-
describe('empty responses', function () {
144+
describe('Empty responses', function () {
145145
it('GET /models should return an empty JSON API resource object when there are no results', function (done) {
146146
request(app).get('/posts')
147147
.expect(200)
@@ -163,7 +163,7 @@ describe('loopback json api component find methods', function () {
163163
});
164164
});
165165

166-
describe('non empty reponses', function () {
166+
describe('Non-empty reponses', function () {
167167
beforeEach(function (done) {
168168
Post.create({
169169
title: 'my post',
@@ -204,13 +204,54 @@ describe('loopback json api component find methods', function () {
204204
done();
205205
});
206206
});
207+
});
208+
209+
describe('Errors', function () {
210+
it('GET /models/doesnt/exist should return a general 400 error', function (done) {
211+
request(app).get('/posts/doesnt/exist')
212+
.expect(400)
213+
.end(done);
214+
});
215+
});
207216

208-
describe('errors', function () {
209-
it('GET /models/doesnt/exist should return a general 400 error', function (done) {
210-
request(app).get('/posts/doesnt/exist')
211-
.expect(400)
212-
.end(done);
217+
describe('Filtering should still be intact', function () {
218+
beforeEach(function (done) {
219+
Post.create({
220+
title: 'deer can jump',
221+
content: 'deer can jump really high in their natural habitat'
222+
}, function () {
223+
Post.create({
224+
title: 'pigs dont fly',
225+
content: 'contrary to the myth, pigs don\'t fly!'
226+
}, function () {
227+
Post.create({
228+
title: 'unicorns come from rainbows',
229+
content: 'at the end of a rainbow may be a pot of gold, but also a mythical unicorn'
230+
}, done);
231+
});
213232
});
214233
});
234+
235+
it('should filter only one', function (done) {
236+
request(app)
237+
.get('/posts?filter[title]=deer+can+jump')
238+
.expect(200)
239+
.end(function (err, res) {
240+
expect(err).to.equal(null);
241+
expect(res.body.data.length).to.equal(1);
242+
done();
243+
});
244+
});
245+
246+
it('should filter two', function (done) {
247+
request(app)
248+
.get('/posts?filter[title][like]=myth')
249+
.expect(200)
250+
.end(function (err, res) {
251+
expect(err).to.equal(null);
252+
expect(res.body.data.length).to.equal(2);
253+
done();
254+
});
255+
});
215256
});
216257
});

0 commit comments

Comments
 (0)