Skip to content

Commit

Permalink
test: pass on pg 9.6, 10, 11
Browse files Browse the repository at this point in the history
  • Loading branch information
steve-chavez committed Nov 2, 2023
1 parent e879fc6 commit e5e9ecb
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
26 changes: 17 additions & 9 deletions test/spec/Feature/Query/AggregateFunctionsSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ spec _ =
get "/entities?select=count()::text" `shouldRespondWith`
[json|[{ "count": "4" }]|] { matchHeaders = [matchContentTypeJson] }
it "returns the count grouped by all provided fields when other fields are selected" $
get "/projects?select=c:count(),client_id" `shouldRespondWith`
get "/projects?select=c:count(),client_id&order=client_id.desc" `shouldRespondWith`
[json|[{ "c": 1, "client_id": null }, { "c": 2, "client_id": 2 }, { "c": 2, "client_id": 1}]|] { matchHeaders = [matchContentTypeJson] }

context "performing a count by using it as a column (backwards compat)" $ do
Expand Down Expand Up @@ -53,27 +53,35 @@ spec _ =
get "/project_invoices?select=invoice_total.count()" `shouldRespondWith`
[json|[{ "count": 8 }]|] { matchHeaders = [matchContentTypeJson] }
it "groups by any fields selected that do not have an aggregate applied" $
get "/project_invoices?select=invoice_total.sum(),invoice_total.max(),invoice_total.min(),project_id" `shouldRespondWith`
get "/project_invoices?select=invoice_total.sum(),invoice_total.max(),invoice_total.min(),project_id&order=project_id.desc" `shouldRespondWith`
[json|[
{"sum":3200,"max":2000,"min":1200,"project_id":3},
{"sum":4100,"max":4000,"min":100,"project_id":4},
{"sum":3200,"max":2000,"min":1200,"project_id":3},
{"sum":1200,"max":700,"min":500,"project_id":2},
{"sum":300,"max":200,"min":100,"project_id":1} ]|]
{ matchHeaders = [matchContentTypeJson] }
it "supports the use of aliases on fields that will be used in the group by" $
get "/project_invoices?select=invoice_total.sum(),invoice_total.max(),invoice_total.min(),pid:project_id" `shouldRespondWith`
get "/project_invoices?select=invoice_total.sum(),invoice_total.max(),invoice_total.min(),pid:project_id&order=project_id.desc" `shouldRespondWith`
[json|[
{"sum":3200,"max":2000,"min":1200,"pid":3},
{"sum":4100,"max":4000,"min":100,"pid":4},
{"sum":3200,"max":2000,"min":1200,"pid":3},
{"sum":1200,"max":700,"min":500,"pid":2},
{"sum":300,"max":200,"min":100,"pid":1}]|]
{ matchHeaders = [matchContentTypeJson] }
it "allows you to specify an alias for the aggregate" $
get "/project_invoices?select=total_charged:invoice_total.sum(),project_id" `shouldRespondWith`
[json|[{"total_charged":3200,"project_id":3}, {"total_charged":4100,"project_id":4}, {"total_charged":1200,"project_id":2}, {"total_charged":300,"project_id":1}]|] { matchHeaders = [matchContentTypeJson] }
get "/project_invoices?select=total_charged:invoice_total.sum(),project_id&order=project_id.desc" `shouldRespondWith`
[json|[
{"total_charged":4100,"project_id":4},
{"total_charged":3200,"project_id":3},
{"total_charged":1200,"project_id":2},
{"total_charged":300,"project_id":1}]|] { matchHeaders = [matchContentTypeJson] }
it "allows you to cast the result of the aggregate" $
get "/project_invoices?select=total_charged:invoice_total.sum()::text,project_id" `shouldRespondWith`
[json|[{"total_charged":"3200","project_id":3}, {"total_charged":"4100","project_id":4}, {"total_charged":"1200","project_id":2}, {"total_charged":"300","project_id":1}]|] { matchHeaders = [matchContentTypeJson] }
get "/project_invoices?select=total_charged:invoice_total.sum()::text,project_id&order=project_id.desc" `shouldRespondWith`
[json|[
{"total_charged":"4100","project_id":4},
{"total_charged":"3200","project_id":3},
{"total_charged":"1200","project_id":2},
{"total_charged":"300","project_id":1}]|] { matchHeaders = [matchContentTypeJson] }
it "allows you to cast the input argument of the aggregate" $
get "/trash_details?select=jsonb_col->>key::integer.sum()" `shouldRespondWith`
[json|[{"sum": 24}]|] { matchHeaders = [matchContentTypeJson] }
Expand Down
4 changes: 2 additions & 2 deletions test/spec/Feature/Query/PlanSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -348,12 +348,12 @@ spec actualPgVersion = do
r1 <- request methodGet "/users?select=*,tasks!inner(*)&tasks.id=eq.1"
[planHdr] ""

liftIO $ planCost r1 `shouldSatisfy` (< 20876.14)
liftIO $ planCost r1 `shouldSatisfy` (< 20888.83)

r2 <- request methodGet "/users?select=*,tasks(*)&tasks.id=eq.1&tasks=not.is.null"
[planHdr] ""

liftIO $ planCost r2 `shouldSatisfy` (< 20876.14)
liftIO $ planCost r2 `shouldSatisfy` (< 20888.83)

describe "function call costs" $ do
it "should not exceed cost when calling setof composite proc" $ do
Expand Down

0 comments on commit e5e9ecb

Please sign in to comment.