From fe2199caaeb23efe96b6aae93c95022fd78e8b14 Mon Sep 17 00:00:00 2001 From: Angelico Date: Thu, 23 Apr 2020 18:57:00 +0800 Subject: [PATCH] Fix for some filters not being a function && tests to test for this in the future --- libraries/supabase-js/src/Supabase.js | 22 ++++- .../test/integration/testFilters.js | 81 +++++++++++++++++++ 2 files changed, 102 insertions(+), 1 deletion(-) create mode 100644 libraries/supabase-js/test/integration/testFilters.js diff --git a/libraries/supabase-js/src/Supabase.js b/libraries/supabase-js/src/Supabase.js index b85d1b92d7c..79b86012622 100644 --- a/libraries/supabase-js/src/Supabase.js +++ b/libraries/supabase-js/src/Supabase.js @@ -253,7 +253,27 @@ class Supabase { } // pre-empts if any of the filters are used before select -const advancedFilters = ['eq', 'gt', 'lt', 'gte', 'lte', 'like', 'ilike', 'is', 'in', 'not'] +const advancedFilters = [ + 'eq', + 'neq', + 'gt', + 'lt', + 'gte', + 'lte', + 'like', + 'ilike', + 'is', + 'in', + 'cs', + 'cd', + 'ova', + 'ovr', + 'sl', + 'sr', + 'nxr', + 'nxl', + 'adj', +] advancedFilters.forEach( (operator) => diff --git a/libraries/supabase-js/test/integration/testFilters.js b/libraries/supabase-js/test/integration/testFilters.js new file mode 100644 index 00000000000..1456e67630c --- /dev/null +++ b/libraries/supabase-js/test/integration/testFilters.js @@ -0,0 +1,81 @@ +import { assert } from 'chai' +import { createClient } from '../../src' + +describe('test reading from the rest interface', () => { + const supabase = createClient('http://localhost:8000', 'examplekey') + const expectedQueryArray = [ + 'name=eq.New Zealand', + 'id=gt.20', + 'id=lt.20', + 'id=gte.20', + 'id=lte.20', + 'name=like.*United*', + 'name=ilike.*United*', + 'name=is.null', + 'name=in.(China,France)', + 'name=neq.China', + 'countries=cs.{China,France}', + 'countries=cd.{China,France}', + 'allies=ov.{China,France}', + 'population_range=ov.(100,500)', + 'population_range=sl.(100,500)', + 'population_range=sr.(100,500)', + 'population_range=nxl.(100,500)', + 'population_range=nxr.(100,500)', + 'population_range=adj.(100,500)', + ] + + it('should be able to take in filters before an actual request is made', async () => { + const response = supabase + .from('countries') + .eq('name', 'New Zealand') + .gt('id', 20) + .lt('id', 20) + .gte('id', 20) + .lte('id', 20) + .like('name', '%United%') + .ilike('name', '%United%') + .is('name', null) + .in('name', ['China', 'France']) + .neq('name', 'China') + .cs('countries', ['China', 'France']) + .cd('countries', ['China', 'France']) + .ova('allies', ['China', 'France']) + .ovr('population_range', [100, 500]) + .sl('population_range', [100, 500]) + .sr('population_range', [100, 500]) + .nxl('population_range', [100, 500]) + .nxr('population_range', [100, 500]) + .adj('population_range', [100, 500]) + .select('*') + + assert.deepEqual(response._query, expectedQueryArray) + }) + + it('should be able to take in filters after an actual request is made', async () => { + const response = supabase + .from('countries') + .select('*') + .eq('name', 'New Zealand') + .gt('id', 20) + .lt('id', 20) + .gte('id', 20) + .lte('id', 20) + .like('name', '%United%') + .ilike('name', '%United%') + .is('name', null) + .in('name', ['China', 'France']) + .neq('name', 'China') + .cs('countries', ['China', 'France']) + .cd('countries', ['China', 'France']) + .ova('allies', ['China', 'France']) + .ovr('population_range', [100, 500]) + .sl('population_range', [100, 500]) + .sr('population_range', [100, 500]) + .nxl('population_range', [100, 500]) + .nxr('population_range', [100, 500]) + .adj('population_range', [100, 500]) + + assert.deepEqual(response._query, expectedQueryArray) + }) +})