Properly handle ID-like report filter responses
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/cortezaproject/corteza-server/pkg/expr"
|
||||
@@ -103,6 +104,13 @@ func (t *typedValue) MarshalJSON() ([]byte, error) {
|
||||
|
||||
aux.Type = t.V.Type()
|
||||
aux.Value = t.V.Get()
|
||||
|
||||
switch aux.Type {
|
||||
case "ID", "Record", "User":
|
||||
v := aux.Value.(uint64)
|
||||
aux.Value = strconv.FormatUint(v, 10)
|
||||
}
|
||||
|
||||
return json.Marshal(aux)
|
||||
}
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@ import (
|
||||
"github.com/cortezaproject/corteza-server/system/service"
|
||||
"github.com/cortezaproject/corteza-server/system/types"
|
||||
"github.com/cortezaproject/corteza-server/tests/helpers"
|
||||
jsonpath "github.com/steinfletcher/apitest-jsonpath"
|
||||
)
|
||||
|
||||
func (h helper) createReport(report *types.Report) *types.Report {
|
||||
@@ -37,6 +38,72 @@ func (h helper) lookupReportByHandle(handle string) *types.Report {
|
||||
return res
|
||||
}
|
||||
|
||||
func TestReportFilterCasting(t *testing.T) {
|
||||
h := newHelper(t)
|
||||
h.clearReports()
|
||||
helpers.AllowMe(h, types.ComponentRbacResource(), "report.create")
|
||||
|
||||
baseAssertPath := "$.response.sources[0].step.load.filter"
|
||||
|
||||
h.apiInit().
|
||||
Post("/reports/").
|
||||
Header("Accept", "application/json").
|
||||
JSON(`{
|
||||
"handle": "test_report",
|
||||
"meta": { "name": "Test Report", "description": "" },
|
||||
"sources": [
|
||||
{
|
||||
"meta": {},
|
||||
"step": {
|
||||
"load": {
|
||||
"name": "Load",
|
||||
"source": "composeRecords",
|
||||
"definition": {
|
||||
"module": "test",
|
||||
"namespace": "test"
|
||||
},
|
||||
"columns": null,
|
||||
"filter": {
|
||||
"ref": "or",
|
||||
"args": [
|
||||
{
|
||||
"ref": "eq",
|
||||
"args": [
|
||||
{ "symbol": "id_str" },
|
||||
{
|
||||
"value": { "@type": "ID", "@value": "123123123" }
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"ref": "eq",
|
||||
"args": [
|
||||
{ "symbol": "id_uint" },
|
||||
{
|
||||
"value": { "@type": "ID", "@value": 123123123 }
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"blocks": []
|
||||
}`).
|
||||
Expect(t).
|
||||
Status(http.StatusOK).
|
||||
Assert(helpers.AssertNoErrors).
|
||||
// Strings handled
|
||||
Assert(jsonpath.Equal(baseAssertPath+`.args[0].args[1].value["@value"]`, "123123123")).
|
||||
Assert(jsonpath.Equal(baseAssertPath+`.args[0].args[0].symbol`, "id_str")).
|
||||
// uint handled
|
||||
Assert(jsonpath.Equal(baseAssertPath+`.args[1].args[1].value["@value"]`, "123123123")).
|
||||
Assert(jsonpath.Equal(baseAssertPath+`.args[1].args[0].symbol`, "id_uint")).
|
||||
End()
|
||||
}
|
||||
|
||||
func TestReportScenarios_create(t *testing.T) {
|
||||
h := newHelper(t)
|
||||
h.clearReports()
|
||||
|
||||
Reference in New Issue
Block a user