Skip to content

Commit 44e5482

Browse files
committed
Additional testing for #49 & #50
1 parent cf69d09 commit 44e5482

File tree

1 file changed

+114
-0
lines changed

1 file changed

+114
-0
lines changed

Diff for: test/integration/Filters.test.js

+114
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,120 @@ describe('Filters', () => {
7373
assert.equal(`.offset() cannot be invoked with criteria that is not a number.`, res.statusText)
7474
})
7575

76+
it('should throw an error for range() when first parameter is not of type number', async () => {
77+
let client = new PostgrestClient(rootUrl)
78+
let res = await client.from('users').select('*').range('test')
79+
80+
assert.equal(`.range() cannot be invoked with parameters that are not numbers.`, res.statusText)
81+
})
82+
83+
it('should throw an error for range() when second parameter is not of type number and not null', async () => {
84+
let client = new PostgrestClient(rootUrl)
85+
let res = await client.from('users').select('*').range(0, 'test')
86+
87+
assert.equal(`.range() cannot be invoked with parameters that are not numbers.`, res.statusText)
88+
})
89+
90+
it('should be able to support order() if invoked beforehand', async () => {
91+
let client = new PostgrestClient(rootUrl)
92+
let { body } = await client.from('users').order('username').select('*')
93+
94+
assert.equal(body[0].username, 'supabot')
95+
assert.equal(body[3].username, 'awailas')
96+
})
97+
98+
it('should be able to support order() if invoked afterwards', async () => {
99+
let client = new PostgrestClient(rootUrl)
100+
let { body } = await client.from('users').select('*').order('username')
101+
102+
assert.equal(body[0].username, 'supabot')
103+
assert.equal(body[3].username, 'awailas')
104+
})
105+
106+
it('should be able to support order() with all parameters stated if invoked beforehand', async () => {
107+
let client = new PostgrestClient(rootUrl)
108+
let { body } = await client.from('users').order('username', true, false).select('*')
109+
110+
assert.equal(body[0].username, 'awailas')
111+
assert.equal(body[3].username, 'supabot')
112+
})
113+
114+
it('should be able to support order() with all parameters stated if invoked afterwards', async () => {
115+
let client = new PostgrestClient(rootUrl)
116+
let { body } = await client.from('users').select('*').order('username', true, false)
117+
118+
assert.equal(body[0].username, 'awailas')
119+
assert.equal(body[3].username, 'supabot')
120+
})
121+
122+
it('should be able to support limit() if invoked beforehand', async () => {
123+
let client = new PostgrestClient(rootUrl)
124+
let { body } = await client.from('users').limit(1).select('*')
125+
126+
assert.equal(body.length, 1)
127+
assert.equal(body[0].username, 'supabot')
128+
})
129+
130+
it('should be able to support limit() if invoked afterwards', async () => {
131+
let client = new PostgrestClient(rootUrl)
132+
let { body } = await client.from('users').select('*').limit(1)
133+
134+
assert.equal(body.length, 1)
135+
assert.equal(body[0].username, 'supabot')
136+
})
137+
138+
it('should be able to support offset() if invoked beforehand', async () => {
139+
let client = new PostgrestClient(rootUrl)
140+
let { body } = await client.from('users').offset(1).select('*')
141+
142+
assert.equal(body.length, 3)
143+
assert.equal(body[0].username, 'kiwicopple')
144+
})
145+
146+
it('should be able to support offset() if invoked afterwards', async () => {
147+
let client = new PostgrestClient(rootUrl)
148+
let { body } = await client.from('users').select('*').offset(1)
149+
150+
assert.equal(body.length, 3)
151+
assert.equal(body[0].username, 'kiwicopple')
152+
})
153+
154+
it('should be able to support range() if invoked beforehand', async () => {
155+
let client = new PostgrestClient(rootUrl)
156+
let { body } = await client.from('users').range(0, 2).select('*')
157+
158+
assert.equal(body.length, 3)
159+
assert.equal(body[0].username, 'supabot')
160+
assert.equal(body[2].username, 'awailas')
161+
})
162+
163+
it('should be able to support range() if invoked afterwards', async () => {
164+
let client = new PostgrestClient(rootUrl)
165+
let { body } = await client.from('users').select('*').range(0, 2)
166+
167+
assert.equal(body.length, 3)
168+
assert.equal(body[0].username, 'supabot')
169+
assert.equal(body[2].username, 'awailas')
170+
})
171+
172+
it('should be able to support order() with only first parameter stated if invoked beforehand', async () => {
173+
let client = new PostgrestClient(rootUrl)
174+
let { body } = await client.from('users').range(1).select('*')
175+
176+
assert.equal(body.length, 3)
177+
assert.equal(body[0].username, 'kiwicopple')
178+
assert.equal(body[2].username, 'dragarcia')
179+
})
180+
181+
it('should be able to support order() with only first parameter stated if invoked afterwards', async () => {
182+
let client = new PostgrestClient(rootUrl)
183+
let { body } = await client.from('users').select('*').range(1)
184+
185+
assert.equal(body.length, 3)
186+
assert.equal(body[0].username, 'kiwicopple')
187+
assert.equal(body[2].username, 'dragarcia')
188+
})
189+
76190
const expectedQueryArray = [
77191
'name=eq.New Zealand',
78192
'id=gt.20',

0 commit comments

Comments
 (0)