Skip to content
This repository was archived by the owner on Oct 9, 2025. It is now read-only.

Commit 5a63b61

Browse files
committed
#48 Integration tests for new filters
1 parent 66ddbc5 commit 5a63b61

File tree

3 files changed

+33
-6
lines changed

3 files changed

+33
-6
lines changed

test/db/00-schema.sql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ CREATE TABLE public.users (
1313
updated_at timestamp without time zone DEFAULT timezone('utc'::text, now()) NOT NULL,
1414
data jsonb DEFAULT null,
1515
age_range int4range DEFAULT null,
16-
status user_status DEFAULT 'ONLINE'::public.user_status
16+
status user_status DEFAULT 'ONLINE'::public.user_status,
17+
catchphrase tsvector DEFAULT null
1718
);
1819
ALTER TABLE public.users REPLICA IDENTITY FULL; -- Send "previous data" to supabase
1920
COMMENT ON COLUMN public.users.data IS 'For unstructured data and prototyping.';

test/db/01-dummy-data.sql

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
INSERT INTO
2-
public.users (username, status, age_range)
2+
public.users (username, status, age_range, catchphrase)
33
VALUES
4-
('supabot', 'ONLINE', '[1,2)'::int4range),
5-
('kiwicopple', 'OFFLINE', '[25,35)'::int4range),
6-
('awailas', 'ONLINE', '[25,35)'::int4range),
7-
('dragarcia', 'ONLINE', '[20,30)'::int4range);
4+
('supabot', 'ONLINE', '[1,2)'::int4range, 'fat cat'::tsvector),
5+
('kiwicopple', 'OFFLINE', '[25,35)'::int4range, 'cat bat'::tsvector),
6+
('awailas', 'ONLINE', '[25,35)'::int4range, 'bat rat'::tsvector),
7+
('dragarcia', 'ONLINE', '[20,30)'::int4range, 'rat fat'::tsvector);
88

99
INSERT INTO
1010
public.channels (slug)

test/integration/Filters.test.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const rootUrl = 'http://localhost:3000'
66
var arrayFilterList = ['in', 'cs', 'cd', 'ova', 'ovr', 'sl', 'sr', 'nxr', 'nxl', 'adj']
77
var dataTypeList = ['cs', 'cd', 'ova', 'ovr', 'sl', 'sr', 'nxr', 'nxl', 'adj']
88
var rangeFilterList = ['ovr', 'sl', 'sr', 'nxr', 'nxl', 'adj']
9+
var fullTextSearchList = ['fts', 'plfts', 'phfts', 'wfts']
910

1011
var arrayFilterCheck = (filter) => {
1112
it(`should not accept non-array data type for ${filter}`, async () => {
@@ -40,10 +41,23 @@ var rangeFilterCheck = (filter) => {
4041
})
4142
}
4243

44+
var fullTextSearchCheck = (filter) => {
45+
it(`should not accept anything else that is not an Object and does not have they key queryText for ${filter}`, async () => {
46+
let client = new PostgrestClient(rootUrl)
47+
let res = await client.from('users').select('*').filter('username', filter, [1, 2, 3])
48+
49+
assert.equal(
50+
`.${filter}() can only be invoked with a criteria that is an Object with key queryText.`,
51+
res.statusText
52+
)
53+
})
54+
}
55+
4356
describe('Filters', () => {
4457
arrayFilterList.forEach((filter) => arrayFilterCheck(filter))
4558
rangeFilterList.forEach((filter) => rangeFilterCheck(filter))
4659
dataTypeList.forEach((filter) => dataTypeCheck(filter))
60+
fullTextSearchList.forEach((filter) => fullTextSearchCheck(filter))
4761

4862
it('should throw an error for limit() when criteria is not of type number', async () => {
4963
let client = new PostgrestClient(rootUrl)
@@ -70,6 +84,10 @@ describe('Filters', () => {
7084
'name=is.null',
7185
'name=in.(China,France)',
7286
'name=neq.China',
87+
'phrase=fts(english).The Fat Cats',
88+
'phrase=plfts.The Fat Cats',
89+
'phrase=phfts(english).The Fat Cats',
90+
'phrase=wfts.The Fat Cats',
7391
'countries=cs.{China,France}',
7492
'countries=cd.{China,France}',
7593
'allies=ov.{China,France}',
@@ -95,6 +113,10 @@ describe('Filters', () => {
95113
.is('name', null)
96114
.in('name', ['China', 'France'])
97115
.neq('name', 'China')
116+
.fts('phrase', { queryText: 'The Fat Cats', config: 'english' })
117+
.plfts('phrase', { queryText: 'The Fat Cats' })
118+
.phfts('phrase', { queryText: 'The Fat Cats', config: 'english' })
119+
.wfts('phrase', { queryText: 'The Fat Cats' })
98120
.cs('countries', ['China', 'France'])
99121
.cd('countries', ['China', 'France'])
100122
.ova('allies', ['China', 'France'])
@@ -124,6 +146,10 @@ describe('Filters', () => {
124146
.is('name', null)
125147
.in('name', ['China', 'France'])
126148
.neq('name', 'China')
149+
.fts('phrase', { queryText: 'The Fat Cats', config: 'english' })
150+
.plfts('phrase', { queryText: 'The Fat Cats' })
151+
.phfts('phrase', { queryText: 'The Fat Cats', config: 'english' })
152+
.wfts('phrase', { queryText: 'The Fat Cats' })
127153
.cs('countries', ['China', 'France'])
128154
.cd('countries', ['China', 'France'])
129155
.ova('allies', ['China', 'France'])

0 commit comments

Comments
 (0)