diff --git a/pkg/qlng/ast_nodes.go b/pkg/qlng/ast_nodes.go index 3935dfa89..1259dbf9a 100644 --- a/pkg/qlng/ast_nodes.go +++ b/pkg/qlng/ast_nodes.go @@ -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) } diff --git a/tests/system/report_test.go b/tests/system/report_test.go index e2b0e000a..914c339c1 100644 --- a/tests/system/report_test.go +++ b/tests/system/report_test.go @@ -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()