Commit bdc6e2fe by Emil Hessman Committed by GitHub

Chore: Require OrgId to be specified in delete playlist command (#29117)

parent fbf0d2c0
......@@ -108,7 +108,7 @@ func GetPlaylist(query *models.GetPlaylistByIdQuery) error {
}
func DeletePlaylist(cmd *models.DeletePlaylistCommand) error {
if cmd.Id == 0 {
if cmd.Id == 0 || cmd.OrgId == 0 {
return models.ErrCommandValidationFailed
}
......
......@@ -3,6 +3,7 @@
package sqlstore
import (
"fmt"
"testing"
"github.com/grafana/grafana/pkg/models"
......@@ -32,9 +33,36 @@ func TestPlaylistDataAccess(t *testing.T) {
})
t.Run("Can remove playlist", func(t *testing.T) {
query := models.DeletePlaylistCommand{Id: 1}
err = DeletePlaylist(&query)
deleteQuery := models.DeletePlaylistCommand{Id: 1, OrgId: 1}
err = DeletePlaylist(&deleteQuery)
require.NoError(t, err)
getQuery := models.GetPlaylistByIdQuery{Id: 1}
err = GetPlaylist(&getQuery)
require.NoError(t, err)
require.Equal(t, int64(0), getQuery.Result.Id, "playlist should've been removed")
})
})
t.Run("Delete playlist that doesn't exist", func(t *testing.T) {
deleteQuery := models.DeletePlaylistCommand{Id: 1, OrgId: 1}
err := DeletePlaylist(&deleteQuery)
require.NoError(t, err)
})
t.Run("Delete playlist with invalid command yields error", func(t *testing.T) {
testCases := []struct {
desc string
cmd models.DeletePlaylistCommand
}{
{desc: "none", cmd: models.DeletePlaylistCommand{}},
{desc: "no OrgId", cmd: models.DeletePlaylistCommand{Id: 1}},
{desc: "no Id", cmd: models.DeletePlaylistCommand{OrgId: 1}},
}
for _, tc := range testCases {
err := DeletePlaylist(&tc.cmd)
require.EqualError(t, err, models.ErrCommandValidationFailed.Error(), fmt.Sprintf("expected command validation error for %q", tc.desc))
}
})
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment