upd(crm): add chart tests, fix tests
This commit is contained in:
@@ -31,6 +31,10 @@ func (m *module) Chart(r *request.ModuleChart) (interface{}, error) {
|
||||
return nil, errors.Wrap(err, "Error creating statik filesystem")
|
||||
}
|
||||
|
||||
filename := "./chart-" + r.Kind + ".json"
|
||||
return fs.ReadFile(statikFS, filename)
|
||||
filename := "/chart-" + r.Kind + ".json"
|
||||
body, err := fs.ReadFile(statikFS, filename)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "Error when reading "+filename)
|
||||
}
|
||||
return body, err
|
||||
}
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
package repository
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/crusttech/crust/crm/rest/request"
|
||||
)
|
||||
|
||||
func TestModuleGraph(t *testing.T) {
|
||||
repository := Module(context.TODO(), nil).With(context.Background(), nil)
|
||||
|
||||
params := &request.ModuleChart{
|
||||
Kind: "line",
|
||||
}
|
||||
|
||||
{
|
||||
_, err := repository.Chart(params)
|
||||
assert(t, err == nil, "Error when getting module graph: %+v", err)
|
||||
}
|
||||
|
||||
{
|
||||
params.Kind = "404"
|
||||
_, err := repository.Chart(params)
|
||||
assert(t, err != nil, "Expected error when getting chart for 404")
|
||||
}
|
||||
}
|
||||
@@ -118,7 +118,7 @@ func TestContent(t *testing.T) {
|
||||
assert(t, err == nil, "Error when retrieving contents: %+v", err)
|
||||
assert(t, len(mr.Contents) == 1, "Expected one content, got %d", len(mr.Contents))
|
||||
assert(t, mr.Meta.Count == 1, "Expected Meta.Count == 1, got %d", mr.Meta.Count)
|
||||
assert(t, mr.Contents[0].ModuleID == m.ModuleID, "Expected content module to match, %s != %s", m.ModuleID, mr.Contents[0].ModuleID)
|
||||
assert(t, mr.Contents[0].ModuleID == m.ModuleID, "Expected content module to match, %d != %d", m.ModuleID, mr.Contents[0].ModuleID)
|
||||
}
|
||||
|
||||
// fetch all contents by query
|
||||
|
||||
Reference in New Issue
Block a user