snapshot of https://github.com/cortezaproject/corteza.git (2024.9.x, 2026-09-18; blobs > 131072B omitted)
Some checks failed
SonarQube / SonarQube (push) Failing after 5m28s
E2e test on main branch push / server and client test (map[name:admin port:8080]) (push) Failing after 3m33s
Server and lib tests / Library test (js) (push) Failing after 1m36s
Server and lib tests / Library test (vue) (push) Successful in 2m24s
Server and lib tests / Web client test (admin) (push) Successful in 2m52s
Server and lib tests / Web client test (compose) (push) Successful in 3m23s
Server and lib tests / Web client test (discovery) (push) Successful in 2m49s
Server and lib tests / Web client test (one) (push) Successful in 2m52s
Server and lib tests / Web client test (privacy) (push) Successful in 2m44s
Server and lib tests / Web client test (reporter) (push) Successful in 2m56s
Server and lib tests / Web client test (workflow) (push) Successful in 3m0s
Server and lib tests / Server tests (push) Failing after 4m55s
E2e test on main branch push / notify-failure (push) Failing after 9s
Server and lib tests / Send matrix testing notification (push) Successful in 2s
Mark stale issues and pull requests / stale (push) Successful in 40s
Some checks failed
SonarQube / SonarQube (push) Failing after 5m28s
E2e test on main branch push / server and client test (map[name:admin port:8080]) (push) Failing after 3m33s
Server and lib tests / Library test (js) (push) Failing after 1m36s
Server and lib tests / Library test (vue) (push) Successful in 2m24s
Server and lib tests / Web client test (admin) (push) Successful in 2m52s
Server and lib tests / Web client test (compose) (push) Successful in 3m23s
Server and lib tests / Web client test (discovery) (push) Successful in 2m49s
Server and lib tests / Web client test (one) (push) Successful in 2m52s
Server and lib tests / Web client test (privacy) (push) Successful in 2m44s
Server and lib tests / Web client test (reporter) (push) Successful in 2m56s
Server and lib tests / Web client test (workflow) (push) Successful in 3m0s
Server and lib tests / Server tests (push) Failing after 4m55s
E2e test on main branch push / notify-failure (push) Failing after 9s
Server and lib tests / Send matrix testing notification (push) Successful in 2s
Mark stale issues and pull requests / stale (push) Successful in 40s
This commit is contained in:
210
server/tests/system/report_test.go
Normal file
210
server/tests/system/report_test.go
Normal file
@@ -0,0 +1,210 @@
|
||||
package system
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/cortezaproject/corteza/server/pkg/id"
|
||||
"github.com/cortezaproject/corteza/server/store"
|
||||
"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 {
|
||||
if report.ID == 0 {
|
||||
report.ID = id.Next()
|
||||
}
|
||||
|
||||
if report.CreatedAt.IsZero() {
|
||||
report.CreatedAt = time.Now()
|
||||
}
|
||||
|
||||
h.a.NoError(service.DefaultStore.CreateReport(context.Background(), report))
|
||||
return report
|
||||
}
|
||||
|
||||
func (h helper) clearReports() {
|
||||
h.noError(store.TruncateReports(context.Background(), service.DefaultStore))
|
||||
}
|
||||
|
||||
func (h helper) lookupReportByHandle(handle string) *types.Report {
|
||||
res, err := store.LookupReportByHandle(context.Background(), service.DefaultStore, handle)
|
||||
h.noError(err)
|
||||
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 TestReportCreate_invalidFilter(t *testing.T) {
|
||||
h := newHelper(t)
|
||||
h.clearReports()
|
||||
helpers.AllowMe(h, types.ComponentRbacResource(), "report.create")
|
||||
|
||||
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": "", "@value": "" }
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"blocks": []
|
||||
}`).
|
||||
Expect(t).
|
||||
Status(http.StatusOK).
|
||||
Assert(helpers.AssertNoErrors).
|
||||
End()
|
||||
}
|
||||
|
||||
func TestReportScenarios_create(t *testing.T) {
|
||||
h := newHelper(t)
|
||||
h.clearReports()
|
||||
helpers.AllowMe(h, types.ComponentRbacResource(), "report.create")
|
||||
|
||||
h.apiInit().
|
||||
Post("/reports/").
|
||||
Header("Accept", "application/json").
|
||||
JSON(`{
|
||||
"handle": "test_report",
|
||||
"scenarios": [{ "label": "scenario 1", "filters": { "ds_1": { "raw": "field == 'value'" } } }]
|
||||
}`).
|
||||
Expect(t).
|
||||
Status(http.StatusOK).
|
||||
Assert(helpers.AssertNoErrors).
|
||||
End()
|
||||
|
||||
r := h.lookupReportByHandle("test_report")
|
||||
h.a.NotNil(r)
|
||||
|
||||
h.a.Len(r.Scenarios, 1)
|
||||
sc := r.Scenarios[0]
|
||||
h.a.NotNil(sc.Filters)
|
||||
h.a.Contains(sc.Filters, "ds_1")
|
||||
}
|
||||
|
||||
func TestReportScenarios_update(t *testing.T) {
|
||||
h := newHelper(t)
|
||||
h.clearReports()
|
||||
helpers.AllowMe(h, types.ReportRbacResource(0), "update")
|
||||
|
||||
r := h.createReport(&types.Report{
|
||||
Handle: "test_report",
|
||||
})
|
||||
|
||||
h.apiInit().
|
||||
Put(fmt.Sprintf("/reports/%d", r.ID)).
|
||||
Header("Accept", "application/json").
|
||||
JSON(`{
|
||||
"handle": "test_report",
|
||||
"scenarios": [{ "label": "scenario 1", "filters": { "ds_1": { "raw": "field == 'value'" } } }]
|
||||
}`).
|
||||
Expect(t).
|
||||
Status(http.StatusOK).
|
||||
Assert(helpers.AssertNoErrors).
|
||||
End()
|
||||
|
||||
r = h.lookupReportByHandle("test_report")
|
||||
h.a.NotNil(r)
|
||||
|
||||
h.a.Len(r.Scenarios, 1)
|
||||
sc := r.Scenarios[0]
|
||||
h.a.NotNil(sc.Filters)
|
||||
h.a.Contains(sc.Filters, "ds_1")
|
||||
}
|
||||
Reference in New Issue
Block a user