API: return resource ID when deleting datasource with UID and library element (#41342)

* API: return resource ID when deleting datasource and library element

* keep status codes consistent

* fix element ID

* add test

* improve response struct

* update endpoints documentation

* LibraryElementIDResponse -> DeleteLibraryElementResponse
This commit is contained in:
Agnès Toulet
2021-11-05 15:06:14 +01:00
committed by GitHub
parent e0ad74a815
commit 3a6b8535b1
7 changed files with 34 additions and 8 deletions

View File

@@ -1,6 +1,7 @@
package libraryelements
import (
"encoding/json"
"testing"
"github.com/grafana/grafana/pkg/components/simplejson"
@@ -17,11 +18,17 @@ func TestDeleteLibraryElement(t *testing.T) {
require.Equal(t, 404, resp.Status())
})
scenarioWithPanel(t, "When an admin tries to delete a library panel that exists, it should succeed",
scenarioWithPanel(t, "When an admin tries to delete a library panel that exists, it should succeed and return correct ID",
func(t *testing.T, sc scenarioContext) {
sc.ctx.Req = web.SetURLParams(sc.ctx.Req, map[string]string{":uid": sc.initialResult.Result.UID})
resp := sc.service.deleteHandler(sc.reqContext)
require.Equal(t, 200, resp.Status())
var result DeleteLibraryElementResponse
err := json.Unmarshal(resp.Body(), &result)
require.NoError(t, err)
require.Equal(t, sc.initialResult.Result.ID, result.ID)
})
scenarioWithPanel(t, "When an admin tries to delete a library panel in another org, it should fail",