diff --git a/test/Feature/JsonOperatorSpec.hs b/test/Feature/JsonOperatorSpec.hs index cbe1055c3..2b0495c9e 100644 --- a/test/Feature/JsonOperatorSpec.hs +++ b/test/Feature/JsonOperatorSpec.hs @@ -154,6 +154,20 @@ spec = describe "json and jsonb operators" $ do [json| [{"data":[{"a": [1,2,3]}, {"b": [4,5]}]}] |] { matchHeaders = [matchContentTypeJson] } + it "can filter jsonb" $ do + get "/jsonb_test?data=eq.{\"e\":1}" `shouldRespondWith` + [json| [{"id":4,"data":{"e": 1}}] |] + { matchHeaders = [matchContentTypeJson] } + get "/jsonb_test?data->a=eq.{\"b\":2}" `shouldRespondWith` + [json| [{"id":1,"data":{"a": {"b": 2}}}] |] + { matchHeaders = [matchContentTypeJson] } + get "/jsonb_test?data->c=eq.[1,2,3]" `shouldRespondWith` + [json| [{"id":2,"data":{"c": [1, 2, 3]}}] |] + { matchHeaders = [matchContentTypeJson] } + get "/jsonb_test?data->0=eq.{\"d\":\"test\"}" `shouldRespondWith` + [json| [{"id":3,"data":[{"d": "test"}]}] |] + { matchHeaders = [matchContentTypeJson] } + context "ordering response" $ do it "orders by a json column property asc" $ get "/json?order=data->>id.asc" `shouldRespondWith` diff --git a/test/fixtures/data.sql b/test/fixtures/data.sql index fd5d842fa..b20451440 100644 --- a/test/fixtures/data.sql +++ b/test/fixtures/data.sql @@ -425,3 +425,9 @@ INSERT INTO json_arr VALUES (6, '[{"a": [1,2,3]}, {"b": [4,5]}]'); INSERT INTO json_arr VALUES (7, '{"c": [1,2,3], "d": [4,5]}'); INSERT INTO json_arr VALUES (8, '{"c": [{"d": [4,5,6,7,8]}]}'); INSERT INTO json_arr VALUES (9, '[{"0xy1": [1,{"23-xy-45": [2, {"xy-6": [3]}]}]}]'); + +TRUNCATE TABLE jsonb_test CASCADE; +INSERT INTO jsonb_test VALUES (1, '{ "a": {"b": 2} }'); +INSERT INTO jsonb_test VALUES (2, '{ "c": [1,2,3] }'); +INSERT INTO jsonb_test VALUES (3, '[{ "d": "test" }]'); +INSERT INTO jsonb_test VALUES (4, '{ "e": 1 }'); diff --git a/test/fixtures/privileges.sql b/test/fixtures/privileges.sql index 574dad22a..f8749990d 100644 --- a/test/fixtures/privileges.sql +++ b/test/fixtures/privileges.sql @@ -81,6 +81,7 @@ GRANT ALL ON TABLE , projects_dump , "UnitTest" , json_arr + , jsonb_test TO postgrest_test_anonymous; GRANT INSERT ON TABLE insertonly TO postgrest_test_anonymous; diff --git a/test/fixtures/schema.sql b/test/fixtures/schema.sql index e55a26771..e2a12c440 100755 --- a/test/fixtures/schema.sql +++ b/test/fixtures/schema.sql @@ -1461,3 +1461,8 @@ create table json_arr( id integer primary key, data pg_catalog.json ); + +create table jsonb_test( + id integer primary key, + data jsonb +);