Chore: Remove Result from dashboard models (#61997)

* Chore: Remove Result from dashboard models

* Fix lint tests

* Fix dashboard service tests

* Fix API tests

* Remove commented out code

* Chore: Merge main - cleanup
This commit is contained in:
idafurjes
2023-01-25 10:36:26 +01:00
committed by GitHub
parent 8c3e4487ba
commit b54b80f473
49 changed files with 625 additions and 588 deletions

View File

@@ -227,13 +227,8 @@ func TestAnnotationsAPIEndpoint(t *testing.T) {
t.Run("Should be able to do anything", func(t *testing.T) {
dashSvc := dashboards.NewFakeDashboardService(t)
dashSvc.On("GetDashboard", mock.Anything, mock.AnythingOfType("*dashboards.GetDashboardQuery")).Run(func(args mock.Arguments) {
q := args.Get(1).(*dashboards.GetDashboardQuery)
q.Result = &dashboards.Dashboard{
ID: q.ID,
UID: q.UID,
}
}).Return(nil)
result := &dashboards.Dashboard{}
dashSvc.On("GetDashboard", mock.Anything, mock.AnythingOfType("*dashboards.GetDashboardQuery")).Return(result, nil)
postAnnotationScenario(t, "When calling POST on", "/api/annotations", "/api/annotations", role, cmd, store, dashSvc, func(sc *scenarioContext) {
setUpACL()
sc.fakeReqWithParams("POST", sc.url, map[string]string{}).exec()
@@ -244,6 +239,7 @@ func TestAnnotationsAPIEndpoint(t *testing.T) {
setUpACL()
sc.fakeReqWithParams("POST", sc.url, map[string]string{}).exec()
assert.Equal(t, 200, sc.resp.Code)
dashSvc.AssertCalled(t, "GetDashboard", mock.Anything, mock.AnythingOfType("*dashboards.GetDashboardQuery"))
})
@@ -267,13 +263,17 @@ func TestAnnotationsAPIEndpoint(t *testing.T) {
})
dashSvc = dashboards.NewFakeDashboardService(t)
result = &dashboards.Dashboard{
ID: 1,
UID: deleteWithDashboardUIDCmd.DashboardUID,
}
dashSvc.On("GetDashboard", mock.Anything, mock.AnythingOfType("*dashboards.GetDashboardQuery")).Run(func(args mock.Arguments) {
q := args.Get(1).(*dashboards.GetDashboardQuery)
q.Result = &dashboards.Dashboard{
ID: 1,
result = &dashboards.Dashboard{
ID: q.ID,
UID: deleteWithDashboardUIDCmd.DashboardUID,
}
}).Return(nil)
}).Return(result, nil)
deleteAnnotationsScenario(t, "When calling POST with dashboardUID on", "/api/annotations/mass-delete",
"/api/annotations/mass-delete", role, deleteWithDashboardUIDCmd, mockStore, dashSvc, func(sc *scenarioContext) {
setUpACL()
@@ -287,13 +287,15 @@ func TestAnnotationsAPIEndpoint(t *testing.T) {
}
func postAnnotationScenario(t *testing.T, desc string, url string, routePattern string, role org.RoleType,
cmd dtos.PostAnnotationsCmd, store db.DB, dashSvc dashboards.DashboardService, fn scenarioFunc) {
cmd dtos.PostAnnotationsCmd, store db.DB, dashSvc *dashboards.FakeDashboardService, fn scenarioFunc) {
t.Run(fmt.Sprintf("%s %s", desc, url), func(t *testing.T) {
hs := setupSimpleHTTPServer(nil)
hs.SQLStore = store
hs.DashboardService = dashSvc
sc := setupScenarioContext(t, url)
sc.dashboardService = dashSvc
sc.defaultHandler = routing.Wrap(func(c *models.ReqContext) response.Response {
c.Req.Body = mockRequestBody(cmd)
c.Req.Header.Add("Content-Type", "application/json")
@@ -301,12 +303,10 @@ func postAnnotationScenario(t *testing.T, desc string, url string, routePattern
sc.context.UserID = testUserID
sc.context.OrgID = testOrgID
sc.context.OrgRole = role
return hs.PostAnnotation(c)
})
sc.m.Post(routePattern, sc.defaultHandler)
fn(sc)
})
}
@@ -680,20 +680,22 @@ func setUpACL() {
store := dbtest.NewFakeDB()
teamSvc := &teamtest.FakeService{}
dashSvc := &dashboards.FakeDashboardService{}
qResult := []*dashboards.DashboardACLInfoDTO{
{Role: &viewerRole, Permission: models.PERMISSION_VIEW},
{Role: &editorRole, Permission: models.PERMISSION_EDIT},
}
dashSvc.On("GetDashboardACLInfoList", mock.Anything, mock.AnythingOfType("*dashboards.GetDashboardACLInfoListQuery")).Run(func(args mock.Arguments) {
q := args.Get(1).(*dashboards.GetDashboardACLInfoListQuery)
q.Result = []*dashboards.DashboardACLInfoDTO{
{Role: &viewerRole, Permission: models.PERMISSION_VIEW},
{Role: &editorRole, Permission: models.PERMISSION_EDIT},
}
}).Return(nil)
// q := args.Get(1).(*dashboards.GetDashboardACLInfoListQuery)
}).Return(qResult, nil)
var result *dashboards.Dashboard
dashSvc.On("GetDashboard", mock.Anything, mock.AnythingOfType("*dashboards.GetDashboardQuery")).Run(func(args mock.Arguments) {
q := args.Get(1).(*dashboards.GetDashboardQuery)
q.Result = &dashboards.Dashboard{
result = &dashboards.Dashboard{
ID: q.ID,
UID: q.UID,
}
}).Return(nil)
}).Return(result, nil)
guardian.InitLegacyGuardian(store, dashSvc, teamSvc)
}