Open bjornharrtell opened 5 months ago
An extra example would be great to further clarify the issue. The request and the expected/wrong responses would be enough, e.g.:
The request:
curl 'localhost:3000/table?select=a,b' -H "Accept: text/csv"
Expected:
expected,csv
Got:
bad,csv
Against our spec fixtures:
A test for regular views/tables:
it "should respond with CSV with custom select" $
request methodGet "/projects?select=name,id,client_id&id=eq.2"
(acceptHdrs "text/csv") ""
`shouldRespondWith`
[str|name,id,client_id
|"Windows 10",2,1|]
{ matchStatus = 200
, matchHeaders = ["Content-Type" <:> "text/csv; charset=utf-8"]
}
A test for RPCs:
it "returns CSV with custom select" $
request methodGet "/rpc/getproject?select=name,id,client_id&id=2"
(acceptHdrs "text/csv") ""
`shouldRespondWith`
[str|name,id,client_id
|"Windows 10",2,1|]
{ matchStatus = 200
, matchHeaders = ["Content-Type" <:> "text/csv; charset=utf-8"]
}
The first test passes, the second test fails:
1) Feature.Query.RpcSpec, remote procedure call, a proc that returns a set, returns CSV with custom select
body mismatch:
expected: "name,id,client_id\n\"Windows 10\",2,1"
but got: "client_id,id,name\n\"Windows 10\",2,1"
To get the wrong output you need:
The values will be returned in the correct order, but the headers will always be sorted alphabetically.
Thank you @wolfgangwalther, this is precisely the issue.
When using select query string param to reorder and/or omit columns and outpout format text/csv the csv column names header will still be as without select (but data is selected as expected).