@@ -6,6 +6,7 @@ const rootUrl = 'http://localhost:3000'
6
6
var arrayFilterList = [ 'in' , 'cs' , 'cd' , 'ova' , 'ovr' , 'sl' , 'sr' , 'nxr' , 'nxl' , 'adj' ]
7
7
var dataTypeList = [ 'cs' , 'cd' , 'ova' , 'ovr' , 'sl' , 'sr' , 'nxr' , 'nxl' , 'adj' ]
8
8
var rangeFilterList = [ 'ovr' , 'sl' , 'sr' , 'nxr' , 'nxl' , 'adj' ]
9
+ var fullTextSearchList = [ 'fts' , 'plfts' , 'phfts' , 'wfts' ]
9
10
10
11
var arrayFilterCheck = ( filter ) => {
11
12
it ( `should not accept non-array data type for ${ filter } ` , async ( ) => {
@@ -40,10 +41,23 @@ var rangeFilterCheck = (filter) => {
40
41
} )
41
42
}
42
43
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
+
43
56
describe ( 'Filters' , ( ) => {
44
57
arrayFilterList . forEach ( ( filter ) => arrayFilterCheck ( filter ) )
45
58
rangeFilterList . forEach ( ( filter ) => rangeFilterCheck ( filter ) )
46
59
dataTypeList . forEach ( ( filter ) => dataTypeCheck ( filter ) )
60
+ fullTextSearchList . forEach ( ( filter ) => fullTextSearchCheck ( filter ) )
47
61
48
62
it ( 'should throw an error for limit() when criteria is not of type number' , async ( ) => {
49
63
let client = new PostgrestClient ( rootUrl )
@@ -70,6 +84,10 @@ describe('Filters', () => {
70
84
'name=is.null' ,
71
85
'name=in.(China,France)' ,
72
86
'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' ,
73
91
'countries=cs.{China,France}' ,
74
92
'countries=cd.{China,France}' ,
75
93
'allies=ov.{China,France}' ,
@@ -95,6 +113,10 @@ describe('Filters', () => {
95
113
. is ( 'name' , null )
96
114
. in ( 'name' , [ 'China' , 'France' ] )
97
115
. 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' } )
98
120
. cs ( 'countries' , [ 'China' , 'France' ] )
99
121
. cd ( 'countries' , [ 'China' , 'France' ] )
100
122
. ova ( 'allies' , [ 'China' , 'France' ] )
@@ -124,6 +146,10 @@ describe('Filters', () => {
124
146
. is ( 'name' , null )
125
147
. in ( 'name' , [ 'China' , 'France' ] )
126
148
. 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' } )
127
153
. cs ( 'countries' , [ 'China' , 'France' ] )
128
154
. cd ( 'countries' , [ 'China' , 'France' ] )
129
155
. ova ( 'allies' , [ 'China' , 'France' ] )
0 commit comments