mirror of
https://github.com/typicode/json-server.git
synced 2025-08-02 11:32:47 +08:00
Add global search
This commit is contained in:
@ -13,6 +13,12 @@ describe('Server', function() {
|
||||
{id: 2, body: 'bar'}
|
||||
]
|
||||
|
||||
low.db.tags = [
|
||||
{id: 1, body: 'Technology'},
|
||||
{id: 2, body: 'Photography'},
|
||||
{id: 3, body: 'photo'}
|
||||
]
|
||||
|
||||
low.db.comments = [
|
||||
{id: 1, published: true, postId: 1},
|
||||
{id: 2, published: false, postId: 1},
|
||||
@ -55,6 +61,32 @@ describe('Server', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('GET /:resource?q=value', function() {
|
||||
it('should respond with json and filter all begin of fields of resources', function(done) {
|
||||
request(server)
|
||||
.get('/tags?q=photo')
|
||||
.expect('Content-Type', /json/)
|
||||
.expect([low.db.tags[1], low.db.tags[2]])
|
||||
.expect(200, done)
|
||||
})
|
||||
|
||||
it('should respond with json and filter everywhere of all fields of resources', function(done) {
|
||||
request(server)
|
||||
.get('/tags?q=t')
|
||||
.expect('Content-Type', /json/)
|
||||
.expect(low.db.tags)
|
||||
.expect(200, done)
|
||||
})
|
||||
|
||||
it('should not respond anything when the query does not many any data', function(done) {
|
||||
request(server)
|
||||
.get('/tags?q=nope')
|
||||
.expect('Content-Type', /json/)
|
||||
.expect([])
|
||||
.expect(200, done)
|
||||
})
|
||||
})
|
||||
|
||||
describe('GET /:resource?_start=&_end=', function() {
|
||||
it('should respond with sliced array', function(done) {
|
||||
request(server)
|
||||
@ -171,4 +203,4 @@ describe('Server', function() {
|
||||
});
|
||||
|
||||
})
|
||||
})
|
||||
})
|
||||
|
Reference in New Issue
Block a user