From 51774f5b84f1b52df7e8de71a14c09b5f109f9d8 Mon Sep 17 00:00:00 2001 From: Laurence Isla Date: Mon, 12 Dec 2022 19:32:10 -0500 Subject: [PATCH] Add spectests --- src/PostgREST/ApiRequest/Types.hs | 3 ++- test/spec/Feature/Query/EmbedDisambiguationSpec.hs | 12 ++++++------ test/spec/Feature/Query/QuerySpec.hs | 12 ++++++------ 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/src/PostgREST/ApiRequest/Types.hs b/src/PostgREST/ApiRequest/Types.hs index 053f621890..3d0ec48961 100644 --- a/src/PostgREST/ApiRequest/Types.hs +++ b/src/PostgREST/ApiRequest/Types.hs @@ -35,7 +35,8 @@ import PostgREST.MediaType (MediaType (..)) import PostgREST.SchemaCache.Identifiers (FieldName, QualifiedIdentifier) import PostgREST.SchemaCache.Proc (ProcDescription (..)) -import PostgREST.SchemaCache.Relationship (Relationship, RelationshipsMap) +import PostgREST.SchemaCache.Relationship (Relationship, + RelationshipsMap) import Protolude diff --git a/test/spec/Feature/Query/EmbedDisambiguationSpec.hs b/test/spec/Feature/Query/EmbedDisambiguationSpec.hs index ffacc04e81..d99903d1ce 100644 --- a/test/spec/Feature/Query/EmbedDisambiguationSpec.hs +++ b/test/spec/Feature/Query/EmbedDisambiguationSpec.hs @@ -217,10 +217,10 @@ spec = it "fails if the fk is not known" $ get "/message?select=id,sender:person!space(name)&id=lt.4" `shouldRespondWith` [json|{ - "hint":"Verify that 'message' and 'person' exist in the schema 'test' and that there is a foreign key relationship between them. If a new relationship was created, try reloading the schema cache.", + "hint":null, "message":"Could not find a relationship between 'message' and 'person' in the schema cache", "code": "PGRST200", - "details": null}|] + "details":"Searched for a foreign key relationship between 'message' and 'person' using the hint 'space' in the schema 'test', but no matches were found."}|] { matchStatus = 400 , matchHeaders = [matchContentTypeJson] } @@ -507,10 +507,10 @@ spec = it "doesn't work if the junction is only internal" $ get "/end_1?select=end_2(*)" `shouldRespondWith` [json|{ - "hint":"Verify that 'end_1' and 'end_2' exist in the schema 'test' and that there is a foreign key relationship between them. If a new relationship was created, try reloading the schema cache.", + "hint": null, "message":"Could not find a relationship between 'end_1' and 'end_2' in the schema cache", "code":"PGRST200", - "details": null}|] + "details": "Searched for a foreign key relationship between 'end_1' and 'end_2' in the schema 'test', but no matches were found."}|] { matchStatus = 400 , matchHeaders = [matchContentTypeJson] } it "shouldn't try to embed if the private junction has an exposed homonym" $ @@ -518,10 +518,10 @@ spec = -- Ref: https://github.com/PostgREST/postgrest/issues/1587#issuecomment-734995669 get "/schauspieler?select=filme(*)" `shouldRespondWith` [json|{ - "hint":"Verify that 'schauspieler' and 'filme' exist in the schema 'test' and that there is a foreign key relationship between them. If a new relationship was created, try reloading the schema cache.", + "hint":null, "message":"Could not find a relationship between 'schauspieler' and 'filme' in the schema cache", "code":"PGRST200", - "details": null}|] + "details":"Searched for a foreign key relationship between 'schauspieler' and 'filme' in the schema 'test', but no matches were found."}|] { matchStatus = 400 , matchHeaders = [matchContentTypeJson] } diff --git a/test/spec/Feature/Query/QuerySpec.hs b/test/spec/Feature/Query/QuerySpec.hs index 8e2340f70f..7b4997aa4c 100644 --- a/test/spec/Feature/Query/QuerySpec.hs +++ b/test/spec/Feature/Query/QuerySpec.hs @@ -601,8 +601,8 @@ spec actualPgVersion = do it "cannot request a partitioned table as parent from a partition" $ get "/car_model_sales_202101?select=id,name,car_models(id,name)&order=id.asc" `shouldRespondWith` [json| - {"hint":"Verify that 'car_model_sales_202101' and 'car_models' exist in the schema 'test' and that there is a foreign key relationship between them. If a new relationship was created, try reloading the schema cache.", - "details":null, + {"hint":"Perhaps you meant 'car_model_sales' instead of 'car_model_sales_202101'.", + "details":"Searched for a foreign key relationship between 'car_model_sales_202101' and 'car_models' in the schema 'test', but no matches were found.", "code":"PGRST200", "message":"Could not find a relationship between 'car_model_sales_202101' and 'car_models' in the schema cache"} |] { matchStatus = 400 @@ -612,8 +612,8 @@ spec actualPgVersion = do it "cannot request a partition as parent from a partitioned table" $ get "/car_model_sales?id=in.(1,3,4)&select=id,name,car_models_default(id,name)&order=id.asc" `shouldRespondWith` [json| - {"hint":"Verify that 'car_model_sales' and 'car_models_default' exist in the schema 'test' and that there is a foreign key relationship between them. If a new relationship was created, try reloading the schema cache.", - "details":null, + {"hint":"Perhaps you meant 'car_models' instead of 'car_models_default'.", + "details":"Searched for a foreign key relationship between 'car_model_sales' and 'car_models_default' in the schema 'test', but no matches were found.", "code":"PGRST200", "message":"Could not find a relationship between 'car_model_sales' and 'car_models_default' in the schema cache"} |] { matchStatus = 400 @@ -623,8 +623,8 @@ spec actualPgVersion = do it "cannot request partitioned tables as children from a partition" $ get "/car_models_default?select=id,name,car_model_sales(id,name)&order=id.asc" `shouldRespondWith` [json| - {"hint":"Verify that 'car_models_default' and 'car_model_sales' exist in the schema 'test' and that there is a foreign key relationship between them. If a new relationship was created, try reloading the schema cache.", - "details":null, + {"hint":"Perhaps you meant 'car_model_sales' instead of 'car_models_default'.", + "details":"Searched for a foreign key relationship between 'car_models_default' and 'car_model_sales' in the schema 'test', but no matches were found.", "code":"PGRST200", "message":"Could not find a relationship between 'car_models_default' and 'car_model_sales' in the schema cache"} |] { matchStatus = 400