-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from rjlopezdev/feat/usage-methods
Usage methods [v1.0.1]
- Loading branch information
Showing
3 changed files
with
111 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
import express = require('express'); | ||
import request = require('supertest'); | ||
import bodyParser = require('body-parser'); | ||
import { QueryBuilder } from '../../../src/query-builder'; | ||
import { Like } from 'typeorm'; | ||
|
||
|
@@ -9,19 +10,69 @@ describe('Test Express integration', () => { | |
|
||
beforeAll((done) => { | ||
let app = express(); | ||
app.get('/foo', (req, res) => { | ||
app.use(bodyParser.json()); | ||
app.use(bodyParser.urlencoded({extended: true})); | ||
app.get('/get', (req, res) => { | ||
const queryBuilder = new QueryBuilder(req.query); | ||
const built = queryBuilder.build(); | ||
res.send(built); | ||
}); | ||
app.post('/post_urlquery', (req, res) => { | ||
const queryBuilder = new QueryBuilder(req.query); | ||
const built = queryBuilder.build(); | ||
res.send(built); | ||
}); | ||
app.post('/post_body', (req, res) => { | ||
const queryBuilder = new QueryBuilder(req.body); | ||
const built = queryBuilder.build(); | ||
res.send(built); | ||
}); | ||
server = app.listen(3000, () => { | ||
done(); | ||
}); | ||
}) | ||
|
||
it('should return an appropiate query built', (done) => { | ||
it('should return an appropiate query built for GET /get?...', (done) => { | ||
request(server) | ||
.get('/get?name=rjlopezdev&[email protected]') | ||
.expect(200) | ||
.end((err, res) => { | ||
expect(JSON.parse(res.text)).toEqual({ | ||
where: { | ||
name: 'rjlopezdev', | ||
email: Like('%@gmail.com%') | ||
}, | ||
skip: 0, | ||
take: 25 | ||
}); | ||
done(); | ||
}) | ||
}) | ||
|
||
it('should return an appropiate query built for POST /post_urlquery?...', (done) => { | ||
request(server) | ||
.get('/foo?name=rjlopezdev&[email protected]') | ||
.post('/post_urlquery?name=rjlopezdev&[email protected]') | ||
.expect(200) | ||
.end((err, res) => { | ||
expect(JSON.parse(res.text)).toEqual({ | ||
where: { | ||
name: 'rjlopezdev', | ||
email: Like('%@gmail.com%') | ||
}, | ||
skip: 0, | ||
take: 25 | ||
}); | ||
done(); | ||
}) | ||
}) | ||
|
||
it('should return an appropiate query built for POST /post_body, body: {...}', (done) => { | ||
request(server) | ||
.post('/post_body') | ||
.send({ | ||
name: 'rjlopezdev', | ||
email__contains: '@gmail.com' | ||
}) | ||
.expect(200) | ||
.end((err, res) => { | ||
expect(JSON.parse(res.text)).toEqual({ | ||
|