Skip to content

Commit

Permalink
test: Add test for openapi output of views
Browse files Browse the repository at this point in the history
Signed-off-by: Wolfgang Walther <walther@technowledgy.de>
  • Loading branch information
wolfgangwalther committed Jul 5, 2022
1 parent 3e83bef commit ee906da
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
32 changes: 32 additions & 0 deletions test/spec/Feature/OpenApi/OpenApiSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,38 @@ spec actualPgVersion = describe "OpenAPI" $ do
}
|]

it "includes definitions to views" $ do
r <- simpleBody <$> get "/"

let def = r ^? key "definitions" . key "child_entities_view"

liftIO $

def `shouldBe` Just
[aesonQQ|
{
"type": "object",
"description": "child_entities_view comment",
"properties": {
"id": {
"description": "child_entities_view id comment\n\nNote:\nThis is a Primary Key.<pk/>",
"format": "integer",
"type": "integer"
},
"name": {
"description": "child_entities_view name comment. Can be longer than sixty-three characters long",
"format": "text",
"type": "string"
},
"parent_id": {
"description": "Note:\nThis is a Foreign Key to `entities.id`.<fk table='entities' column='id'/>",
"format": "integer",
"type": "integer"
}
}
}
|]

it "doesn't include privileged table for anonymous" $ do
r <- simpleBody <$> get "/"
let tablePath = r ^? key "paths" . key "/authors_only"
Expand Down
1 change: 1 addition & 0 deletions test/spec/fixtures/privileges.sql
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ GRANT ALL ON TABLE
, items_with_different_col_types
, entities
, child_entities
, child_entities_view
, grandchild_entities
, ranges
, being
Expand Down
6 changes: 6 additions & 0 deletions test/spec/fixtures/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -1153,6 +1153,8 @@ create table child_entities (
parent_id integer references entities(id)
);

create view child_entities_view as table child_entities;

create table grandchild_entities (
id integer primary key,
name text,
Expand All @@ -1176,6 +1178,10 @@ comment on table child_entities is 'child_entities comment';
comment on column child_entities.id is 'child_entities id comment';
comment on column child_entities.name is 'child_entities name comment. Can be longer than sixty-three characters long';

comment on view child_entities_view is 'child_entities_view comment';
comment on column child_entities_view.id is 'child_entities_view id comment';
comment on column child_entities_view.name is 'child_entities_view name comment. Can be longer than sixty-three characters long';

comment on table grandchild_entities is
$$grandchild_entities summary

Expand Down

0 comments on commit ee906da

Please sign in to comment.