Add tests for jsonb equality filtering
This commit is contained in:
committed by
Steve Chávez
parent
d34afe861a
commit
9e3454129f
@@ -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`
|
||||
|
||||
Vendored
+6
@@ -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 }');
|
||||
|
||||
Vendored
+1
@@ -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;
|
||||
|
||||
Vendored
+5
@@ -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
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user