2021-03-01 15:33:17 +01:00
|
|
|
package librarypanels
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
|
|
|
|
|
"github.com/grafana/grafana/pkg/models"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func TestDeleteLibraryPanel(t *testing.T) {
|
|
|
|
|
scenarioWithLibraryPanel(t, "When an admin tries to delete a library panel that does not exist, it should fail",
|
|
|
|
|
func(t *testing.T, sc scenarioContext) {
|
|
|
|
|
resp := sc.service.deleteHandler(sc.reqContext)
|
|
|
|
|
require.Equal(t, 404, resp.Status())
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
scenarioWithLibraryPanel(t, "When an admin tries to delete a library panel that exists, it should succeed",
|
|
|
|
|
func(t *testing.T, sc scenarioContext) {
|
|
|
|
|
sc.reqContext.ReplaceAllParams(map[string]string{":uid": sc.initialResult.Result.UID})
|
|
|
|
|
resp := sc.service.deleteHandler(sc.reqContext)
|
|
|
|
|
require.Equal(t, 200, resp.Status())
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
scenarioWithLibraryPanel(t, "When an admin tries to delete a library panel in another org, it should fail",
|
|
|
|
|
func(t *testing.T, sc scenarioContext) {
|
|
|
|
|
sc.reqContext.ReplaceAllParams(map[string]string{":uid": sc.initialResult.Result.UID})
|
|
|
|
|
sc.reqContext.SignedInUser.OrgId = 2
|
|
|
|
|
sc.reqContext.SignedInUser.OrgRole = models.ROLE_ADMIN
|
|
|
|
|
resp := sc.service.deleteHandler(sc.reqContext)
|
|
|
|
|
require.Equal(t, 404, resp.Status())
|
|
|
|
|
})
|
2021-03-24 11:43:27 +01:00
|
|
|
|
|
|
|
|
scenarioWithLibraryPanel(t, "When an admin tries to delete a library panel that is connected, it should fail",
|
|
|
|
|
func(t *testing.T, sc scenarioContext) {
|
|
|
|
|
sc.reqContext.ReplaceAllParams(map[string]string{":uid": sc.initialResult.Result.UID, ":dashboardId": "1"})
|
|
|
|
|
resp := sc.service.connectHandler(sc.reqContext)
|
|
|
|
|
require.Equal(t, 200, resp.Status())
|
|
|
|
|
|
|
|
|
|
sc.reqContext.ReplaceAllParams(map[string]string{":uid": sc.initialResult.Result.UID})
|
|
|
|
|
resp = sc.service.deleteHandler(sc.reqContext)
|
|
|
|
|
require.Equal(t, 403, resp.Status())
|
|
|
|
|
})
|
2021-03-01 15:33:17 +01:00
|
|
|
}
|