diff --git a/test/Feature/QuerySpec.hs b/test/Feature/QuerySpec.hs index 6b48e518c..670e1e9d0 100644 --- a/test/Feature/QuerySpec.hs +++ b/test/Feature/QuerySpec.hs @@ -10,6 +10,7 @@ import SpecHelper spec :: Spec spec = beforeAll (clearTable "items" >> createItems 15) + . beforeAll (clearTable "nullable_integer" >> createNullInteger) . beforeAll ( clearTable "no_pk" >> createNulls 2 >> @@ -38,10 +39,12 @@ spec = , matchHeaders = ["Content-Range" <:> "0-2/3"] } - it "matches nulls" $ + it "matches nulls in varchar and numeric fields alike" $ do get "/no_pk?a=is.null" `shouldRespondWith` [json| [{"a": null, "b": null}] |] + get "/nullable_integer?a=is.null" `shouldRespondWith` "[{\"a\":null}]" + it "matches with like" $ do get "/simple_pk?k=like.*yx" `shouldRespondWith` "[{\"k\":\"xyyx\",\"extra\":\"u\"}]" diff --git a/test/Feature/StructureSpec.hs b/test/Feature/StructureSpec.hs index fbc0b08d7..a1b7f19f0 100644 --- a/test/Feature/StructureSpec.hs +++ b/test/Feature/StructureSpec.hs @@ -22,6 +22,7 @@ spec = around withApp $ do , {"schema":"1","name":"json","insertable":true} , {"schema":"1","name":"menagerie","insertable":true} , {"schema":"1","name":"no_pk","insertable":true} + , {"schema":"1","name":"nullable_integer","insertable":true} , {"schema":"1","name":"simple_pk","insertable":true} , {"schema":"1","name":"tsearch","insertable":true} ] |] diff --git a/test/SpecHelper.hs b/test/SpecHelper.hs index a6e116dfe..a88da793e 100644 --- a/test/SpecHelper.hs +++ b/test/SpecHelper.hs @@ -94,7 +94,7 @@ matchHeader name valRegex headers = authHeaderBasic :: String -> String -> Header authHeaderBasic u p = (hAuthorization, cs $ "Basic " ++ encode (u ++ ":" ++ p)) - + authHeaderJWT :: String -> Header authHeaderJWT token = (hAuthorization, cs $ "Bearer " ++ token) @@ -125,6 +125,12 @@ createNulls n = do stmt' = [H.stmt|insert into "1".no_pk (a,b) values (null,null)|] stmts = map [H.stmt|insert into "1".no_pk (a,b) values (?,0)|] [1..n] +createNullInteger :: IO () +createNullInteger = do + pool <- testPool + void . liftIO $ H.session pool $ H.tx Nothing $ + H.unitEx $ [H.stmt| insert into "1".nullable_integer (a) values (null) |] + createLikableStrings :: IO () createLikableStrings = do pool <- testPool diff --git a/test/fixtures/schema.sql b/test/fixtures/schema.sql index 3a010b691..9ba10db5a 100755 --- a/test/fixtures/schema.sql +++ b/test/fixtures/schema.sql @@ -230,6 +230,14 @@ CREATE TABLE no_pk ( ALTER TABLE "1".no_pk OWNER TO postgrest_test; +CREATE TABLE nullable_integer ( + a integer +); + + +ALTER TABLE "1".nullable_integer OWNER TO postgrest_test; + + CREATE TABLE simple_pk ( k character varying NOT NULL, extra character varying NOT NULL @@ -518,6 +526,13 @@ GRANT ALL ON TABLE no_pk TO postgrest_anonymous; +REVOKE ALL ON TABLE nullable_integer FROM PUBLIC; +REVOKE ALL ON TABLE nullable_integer FROM postgrest_test; +GRANT ALL ON TABLE nullable_integer TO postgrest_test; +GRANT ALL ON TABLE nullable_integer TO postgrest_anonymous; + + + REVOKE ALL ON TABLE simple_pk FROM PUBLIC; REVOKE ALL ON TABLE simple_pk FROM postgrest_test; GRANT ALL ON TABLE simple_pk TO postgrest_test;