fix: Add tests for embedding on overloaded functions with a default param

Resolves #1672

Was actually fixed in #1841 / 67c2ed7, this just adds the tests to confirm it.
This commit is contained in:
Laurence Isla
2021-11-19 09:00:16 +01:00
committed by GitHub
parent bf58a3600a
commit 4e07846c5d
2 changed files with 46 additions and 0 deletions
+30
View File
@@ -738,6 +738,36 @@ spec actualPgVersion =
`shouldRespondWith`
[json|"123"|]
-- https://github.com/PostgREST/postgrest/issues/1672
context "embedding overloaded functions with the same signature except for the last param with a default value" $ do
it "overloaded_default(text default)" $ do
request methodPost "/rpc/overloaded_default?select=id,name,users(name)"
[("Content-Type", "application/json")]
[json|{}|]
`shouldRespondWith`
[json|[{"id": 2, "name": "Code w7", "users": [{"name": "Angela Martin"}]}] |]
it "overloaded_default(int)" $
request methodPost "/rpc/overloaded_default"
[("Content-Type", "application/json")]
[json|{"must_param":1}|]
`shouldRespondWith`
[json|{"val":1}|]
it "overloaded_default(int, text default)" $ do
request methodPost "/rpc/overloaded_default?select=id,name,users(name)"
[("Content-Type", "application/json")]
[json|{"a":4}|]
`shouldRespondWith`
[json|[{"id": 5, "name": "Design IOS", "users": [{"name": "Michael Scott"}, {"name": "Dwight Schrute"}]}] |]
it "overloaded_default(int, int)" $
request methodPost "/rpc/overloaded_default"
[("Content-Type", "application/json")]
[json|{"a":2,"must_param":4}|]
`shouldRespondWith`
[json|{"a":2,"val":4}|]
context "only for POST rpc" $ do
it "gives a parse filter error if GET style proc args are specified" $
post "/rpc/sayhello?name=John" [json|{name: "John"}|] `shouldRespondWith` 400
+16
View File
@@ -1323,6 +1323,22 @@ create or replace function test.overloaded(a text, b text, c text) returns text
select a || b || c
$$ language sql;
create or replace function test.overloaded_default(opt_param text default 'Code w7') returns setof test.tasks as $$
select * from test.tasks where name like opt_param;
$$ language sql;
create or replace function test.overloaded_default(must_param int) returns jsonb as $$
select row_to_json(r)::jsonb from (select must_param as val) as r;
$$ language sql;
create or replace function test.overloaded_default(a int, opt_param text default 'Design IOS') returns setof test.tasks as $$
select * from test.tasks where name like opt_param and id > a;
$$ language sql;
create or replace function test.overloaded_default(a int, must_param int) returns jsonb as $$
select row_to_json(r)::jsonb from (select a, must_param as val) as r;
$$ language sql;
create or replace function test.overloaded_html_form() returns setof int as $$
values (1), (2), (3);
$$ language sql;