|
|
|
|
@ -33,79 +33,6 @@ var fakeRepo *fakeDashboardRepo |
|
|
|
|
// 2. and the dashboard is in a folder which does have an acl
|
|
|
|
|
|
|
|
|
|
func TestDashboardApiEndpoint(t *testing.T) { |
|
|
|
|
Convey("Given a folder", t, func() { |
|
|
|
|
fakeFolder := m.NewDashboardFolder("Folder") |
|
|
|
|
fakeFolder.Id = 1 |
|
|
|
|
fakeFolder.HasAcl = false |
|
|
|
|
|
|
|
|
|
bus.AddHandler("test", func(query *m.GetDashboardsBySlugQuery) error { |
|
|
|
|
dashboards := []*m.Dashboard{fakeFolder} |
|
|
|
|
query.Result = dashboards |
|
|
|
|
return nil |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
var getDashboardQueries []*m.GetDashboardQuery |
|
|
|
|
|
|
|
|
|
bus.AddHandler("test", func(query *m.GetDashboardQuery) error { |
|
|
|
|
query.Result = fakeFolder |
|
|
|
|
getDashboardQueries = append(getDashboardQueries, query) |
|
|
|
|
return nil |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
cmd := m.SaveDashboardCommand{ |
|
|
|
|
Dashboard: simplejson.NewFromAny(map[string]interface{}{ |
|
|
|
|
"title": fakeFolder.Title, |
|
|
|
|
"id": fakeFolder.Id, |
|
|
|
|
}), |
|
|
|
|
IsFolder: true, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Convey("When user is an Org Editor", func() { |
|
|
|
|
role := m.ROLE_EDITOR |
|
|
|
|
|
|
|
|
|
loggedInUserScenarioWithRole("When calling GET on", "GET", "/api/dashboards/db/child-dash", "/api/dashboards/db/:slug", role, func(sc *scenarioContext) { |
|
|
|
|
CallGetDashboard(sc) |
|
|
|
|
So(sc.resp.Code, ShouldEqual, 404) |
|
|
|
|
|
|
|
|
|
Convey("Should lookup dashboard by slug", func() { |
|
|
|
|
So(getDashboardQueries[0].Slug, ShouldEqual, "child-dash") |
|
|
|
|
}) |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
loggedInUserScenarioWithRole("When calling GET on", "GET", "/api/dashboards/uid/abcdefghi", "/api/dashboards/uid/:uid", role, func(sc *scenarioContext) { |
|
|
|
|
CallGetDashboard(sc) |
|
|
|
|
So(sc.resp.Code, ShouldEqual, 404) |
|
|
|
|
|
|
|
|
|
Convey("Should lookup dashboard by uid", func() { |
|
|
|
|
So(getDashboardQueries[0].Uid, ShouldEqual, "abcdefghi") |
|
|
|
|
}) |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
postDashboardScenario("When calling POST on", "/api/dashboards", "/api/dashboards", role, cmd, func(sc *scenarioContext) { |
|
|
|
|
CallPostDashboard(sc) |
|
|
|
|
So(sc.resp.Code, ShouldEqual, 404) |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
loggedInUserScenarioWithRole("When calling DELETE on", "DELETE", "/api/dashboards/db/child-dash", "/api/dashboards/db/:slug", role, func(sc *scenarioContext) { |
|
|
|
|
CallDeleteDashboard(sc) |
|
|
|
|
So(sc.resp.Code, ShouldEqual, 404) |
|
|
|
|
|
|
|
|
|
Convey("Should lookup dashboard by slug", func() { |
|
|
|
|
So(getDashboardQueries[0].Slug, ShouldEqual, "child-dash") |
|
|
|
|
}) |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
loggedInUserScenarioWithRole("When calling DELETE on", "DELETE", "/api/dashboards/uid/abcdefghi", "/api/dashboards/uid/:uid", role, func(sc *scenarioContext) { |
|
|
|
|
CallDeleteDashboardByUid(sc) |
|
|
|
|
So(sc.resp.Code, ShouldEqual, 404) |
|
|
|
|
|
|
|
|
|
Convey("Should lookup dashboard by uid", func() { |
|
|
|
|
So(getDashboardQueries[0].Uid, ShouldEqual, "abcdefghi") |
|
|
|
|
}) |
|
|
|
|
}) |
|
|
|
|
}) |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
Convey("Given a dashboard with a parent folder which does not have an acl", t, func() { |
|
|
|
|
fakeDash := m.NewDashboard("Child dash") |
|
|
|
|
fakeDash.Id = 1 |
|
|
|
|
|