Skip to content

Commit b8ea3fa

Browse files
author
Lucas Rocha
committed
Update some integration tests.
1 parent fab3c2e commit b8ea3fa

File tree

1 file changed

+54
-86
lines changed

1 file changed

+54
-86
lines changed

test/integration/index.spec.js

Lines changed: 54 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -42,115 +42,86 @@ describe('queryFilter()', function () {
4242
})
4343
})
4444
})
45-
})
46-
})
4745

48-
/*
4946
context('when query contains pagination param with string limit as skip', function () {
5047
it('should return req.query with set pagination params', function (done) {
5148
const expect_pagination = {limit: Number.MAX_SAFE_INTEGER, skip: 2}
5249

53-
const query = {limit: 'nine', skip: '2'}
54-
const req = httpMocks.createRequest({method: 'GET', url: '/', query: query})
55-
const res = httpMocks.createResponse()
56-
5750
const options = JSON.parse(JSON.stringify(default_options))
5851
options.default.pagination.limit = expect_pagination.limit
5952
options.default.pagination.skip = expect_pagination.skip
6053

61-
qs({})(req, res, function next() {
62-
validate(req, options)
63-
})
64-
done()
54+
request(app)
55+
.get('?limit=nine&skip=2')
56+
.then(res => {
57+
validate(res.body, options)
58+
done()
59+
})
6560
})
6661
})
6762

6863
context('when query contains pagination param with string skip', function () {
6964
it('should return req.query with set pagination params', function (done) {
7065
const expect_pagination = {limit: 10, skip: 0}
7166

72-
const query = {limit: '10', skip: 'two'}
73-
const req = httpMocks.createRequest({method: 'GET', url: '/', query: query})
74-
const res = httpMocks.createResponse()
75-
7667
const options = JSON.parse(JSON.stringify(default_options))
7768
options.default.pagination.limit = expect_pagination.limit
7869
options.default.pagination.skip = expect_pagination.skip
7970

80-
qs({})(req, res, function next() {
81-
validate(req, options)
82-
})
83-
done()
71+
request(app)
72+
.get('?limit=10&skip=two')
73+
.then(res => {
74+
validate(res.body, options)
75+
done()
76+
})
8477
})
8578
})
8679

8780
context('when query contains ordination param', function () {
8881
it('should return req.query with set ordination params', function (done) {
8982
const expect_sort = {name: 'asc', age: 'desc'}
9083

91-
const query = {sort: 'name,-age'}
92-
const req = httpMocks.createRequest({method: 'GET', url: '/', query: query})
93-
const res = httpMocks.createResponse()
94-
9584
const options = JSON.parse(JSON.stringify(default_options))
9685
options.default.sort = expect_sort
9786

98-
qs({})(req, res, function next() {
99-
validate(req, options)
100-
})
101-
done()
87+
request(app)
88+
.get('?sort=name,-age')
89+
.then(res => {
90+
validate(res.body, options)
91+
done()
92+
})
10293
})
10394
})
10495

10596
context('when query contains fields param', function () {
10697
it('should return req.query with set field params', function (done) {
10798
const expect_fields = {name: 1, age: 1}
10899

109-
const query = {fields: 'name, age'}
110-
const req = httpMocks.createRequest({method: 'GET', url: '/', query: query})
111-
const res = httpMocks.createResponse()
112-
113100
const options = JSON.parse(JSON.stringify(default_options))
114101
options.default.fields = expect_fields
115102

116-
qs({})(req, res, function next() {
117-
validate(req, options)
118-
})
119-
done()
120-
})
121-
})
122-
123-
124-
context('when query filters param value is a object', function () {
125-
it('should return req.query as default middleware options', function (done) {
126-
127-
const query = {value: {and: 123}}
128-
const req = httpMocks.createRequest({method: 'GET', url: '/', query: query})
129-
const res = httpMocks.createResponse()
130-
131-
qs({})(req, res, function next() {
132-
validate(req, default_options)
133-
})
134-
done()
103+
request(app)
104+
.get('?fields=name, age')
105+
.then(res => {
106+
validate(res.body, options)
107+
done()
108+
})
135109
})
136110
})
137111

138112
context('when query contains simple filters param', function () {
139113
it('should return req.query with set field params', function (done) {
140114
const expect_filters = {name: 'lucas', age: 30}
141115

142-
const query = {name: 'lucas', age: '30'}
143-
const req = httpMocks.createRequest({method: 'GET', url: '/', query: query})
144-
const res = httpMocks.createResponse()
145-
146-
147116
const options = JSON.parse(JSON.stringify(default_options))
148117
options.default.filters = expect_filters
149118

150-
qs({})(req, res, function next() {
151-
validate(req, options)
152-
})
153-
done()
119+
request(app)
120+
.get('?name=lucas&age=30')
121+
.then(res => {
122+
validate(res.body, options)
123+
done()
124+
})
154125
})
155126
})
156127

@@ -172,22 +143,17 @@ describe('queryFilter()', function () {
172143
'$or': [{job: 'Developer'}, {job: 'Engineer'}]
173144
}
174145

175-
const query = {
176-
name: ['lucas******', '******douglas', '*****jorge********'],
177-
'.school.name.': 'UEPB',
178-
timestamp: '2018-12-05',
179-
job: 'Developer,Engineer'
180-
}
181-
const req = httpMocks.createRequest({method: 'GET', url: '/', query: query})
182-
const res = httpMocks.createResponse()
183-
184146
const options = JSON.parse(JSON.stringify(default_options))
185147
options.default.filters = expect_filters
186148

187-
qs({})(req, res, function next() {
188-
validate(req, options)
189-
})
190-
done()
149+
const query = '?name=lucas******&name=******douglas&name=*****jorge********&.school.name.=UEPB' +
150+
'&timestamp=2018-12-05&job=Developer,Engineer'
151+
request(app)
152+
.get(query)
153+
.then(res => {
154+
validate(res.body, options)
155+
done()
156+
})
191157
})
192158
})
193159

@@ -201,25 +167,24 @@ describe('queryFilter()', function () {
201167
sleep_hour: '22:40'
202168
}
203169

204-
const query = {
205-
name: 'lucas',
206-
age: 'gt:30',
207-
timestamp: 'gt:2018-12-05',
208-
created_at: 'lte:2018-12-06',
209-
sleep_hour: '22:40'
210-
}
211-
const req = httpMocks.createRequest({method: 'GET', url: '/', query: query})
212-
const res = httpMocks.createResponse()
213-
214170
const options = JSON.parse(JSON.stringify(default_options))
215171
options.default.filters = expect_filters
216172

217-
qs({})(req, res, function next() {
218-
validate(req, options)
219-
})
220-
done()
173+
const query = '?name=lucas&age=gt:30&timestamp=gt:2018-12-05&created_at=lte:2018-12-06'+
174+
'&sleep_hour=22:40'
175+
176+
request(app)
177+
.get(query)
178+
.then(res => {
179+
validate(res.body, options)
180+
done()
181+
})
221182
})
222183
})
184+
})
185+
})
186+
187+
/*
223188
224189
context('when query contains date filters param', function () {
225190
it('should return req.query with set start_at params as today', function (done) {
@@ -696,9 +661,11 @@ describe('queryFilter()', function () {
696661
function dateToString(date) {
697662
return `${date.getFullYear()}-${date.getMonth() + 1}-${formatDay(date.getDate())}`
698663
}
664+
699665
function formatDay(day) {
700666
return day < 10 ? '0'.concat(day) : day
701667
}
668+
702669
function validateFilterWithDate(req, options) {
703670
expect(req.query).is.not.null
704671
expect(req.query).is.not.eql({})
@@ -708,6 +675,7 @@ function validateFilterWithDate(req, options) {
708675
expect(req.query.fields).to.eql(options.default.fields)
709676
expect(req.query.filters).to.have.property('$and')
710677
}
678+
711679
*/
712680

713681

0 commit comments

Comments
 (0)