From d78410473e604e3d9e8f9d40a0af49cb5f1874de Mon Sep 17 00:00:00 2001 From: steve-chavez Date: Mon, 10 Dec 2018 13:06:15 -0500 Subject: [PATCH] Add test for embedding on a view with group by --- test/Feature/QuerySpec.hs | 8 ++++++++ test/fixtures/privileges.sql | 1 + test/fixtures/schema.sql | 7 +++++++ 3 files changed, 16 insertions(+) diff --git a/test/Feature/QuerySpec.hs b/test/Feature/QuerySpec.hs index 9b51ad6e8..95621430e 100644 --- a/test/Feature/QuerySpec.hs +++ b/test/Feature/QuerySpec.hs @@ -425,6 +425,14 @@ spec = do {"tournament":"tournament_3","player_view":{"first_name":"first_name_3"}}] |] { matchHeaders = [matchContentTypeJson] } + it "can embed a view that has group by" $ + get "/projects_count_grouped_by?select=number_of_projects,client(name)" `shouldRespondWith` + [json| + [{"number_of_projects":1,"client":null}, + {"number_of_projects":2,"client":{"name":"Microsoft"}}, + {"number_of_projects":2,"client":{"name":"Apple"}}] |] + { matchHeaders = [matchContentTypeJson] } + describe "path fixed" $ do it "works when requesting children 2 levels" $ get "/clients?id=eq.1&select=id,projects:projects.client_id(id,tasks(id))" `shouldRespondWith` diff --git a/test/fixtures/privileges.sql b/test/fixtures/privileges.sql index e1123004e..d86689348 100644 --- a/test/fixtures/privileges.sql +++ b/test/fixtures/privileges.sql @@ -95,6 +95,7 @@ GRANT ALL ON TABLE , contract_view , ltree_sample , isn_sample + , projects_count_grouped_by 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 647e96f0a..2d298c713 100755 --- a/test/fixtures/schema.sql +++ b/test/fixtures/schema.sql @@ -1553,6 +1553,13 @@ select from odd_years_books x join private.publishers y on y.id = x.first_publisher_id; +create view test.projects_count_grouped_by as +select + client_id, + count(id) as number_of_projects +from projects +group by client_id; + CREATE TABLE test."Foo"( id int primary key, name text