3
0

upd(crm): add chart tests, fix tests

This commit is contained in:
Tit Petric
2018-11-12 19:35:53 +01:00
parent 7ddff35ed5
commit 5df33d692f
3 changed files with 34 additions and 3 deletions
+6 -2
View File
@@ -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
}
+27
View File
@@ -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")
}
}
+1 -1
View File
@@ -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