* backend/api: refactor PlaylistId to PlaylistUid
* Add org_id to Get and Update playlist functions
Fix migration - no longer pad the uid; fix mysql syntax
The relevant tests are passing using postgres, mysql and the default sqllite backends, but there are a number of other failing tests when using postgres and myself so I'm not entirely confident with those results.
* fix bad query in GetPlaylistItem and add a test that would have caught the mistake in the first place. Reverted the playlist_uid column addition in playlist_item; it became unnecessary after this PR.
Added default value to the new UID column based on PR feedback.
* break this PRs migration into its own function
* Playlists: Update UI to use the updated API
Co-authored-by: Sofia Papagiannaki <1632407+papagian@users.noreply.github.com>
(cherry picked from commit a33a023629)
Co-authored-by: Kristin Laemmert <mildwonkey@users.noreply.github.com>
This commit is contained in:
co-authored by
Kristin Laemmert
parent
d78c04c8e6
commit
8ef7fd3859
@@ -7,8 +7,9 @@ import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
)
|
||||
|
||||
func TestIntegrationPlaylistDataAccess(t *testing.T) {
|
||||
@@ -22,31 +23,39 @@ func TestIntegrationPlaylistDataAccess(t *testing.T) {
|
||||
cmd := models.CreatePlaylistCommand{Name: "NYC office", Interval: "10m", OrgId: 1, Items: items}
|
||||
err := ss.CreatePlaylist(context.Background(), &cmd)
|
||||
require.NoError(t, err)
|
||||
uid := cmd.Result.UID
|
||||
|
||||
t.Run("Can get playlist items", func(t *testing.T) {
|
||||
get := &models.GetPlaylistItemsByUidQuery{PlaylistUID: uid, OrgId: 1}
|
||||
err = ss.GetPlaylistItem(context.Background(), get)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, len(*get.Result), len(items))
|
||||
})
|
||||
|
||||
t.Run("Can update playlist", func(t *testing.T) {
|
||||
items := []models.PlaylistItemDTO{
|
||||
{Title: "influxdb", Value: "influxdb", Type: "dashboard_by_tag"},
|
||||
{Title: "Backend response times", Value: "2", Type: "dashboard_by_id"},
|
||||
}
|
||||
query := models.UpdatePlaylistCommand{Name: "NYC office ", OrgId: 1, Id: 1, Interval: "10s", Items: items}
|
||||
query := models.UpdatePlaylistCommand{Name: "NYC office ", OrgId: 1, UID: uid, Interval: "10s", Items: items}
|
||||
err = ss.UpdatePlaylist(context.Background(), &query)
|
||||
require.NoError(t, err)
|
||||
})
|
||||
|
||||
t.Run("Can remove playlist", func(t *testing.T) {
|
||||
deleteQuery := models.DeletePlaylistCommand{Id: 1, OrgId: 1}
|
||||
deleteQuery := models.DeletePlaylistCommand{UID: uid, OrgId: 1}
|
||||
err = ss.DeletePlaylist(context.Background(), &deleteQuery)
|
||||
require.NoError(t, err)
|
||||
|
||||
getQuery := models.GetPlaylistByIdQuery{Id: 1}
|
||||
getQuery := models.GetPlaylistByUidQuery{UID: uid, OrgId: 1}
|
||||
err = ss.GetPlaylist(context.Background(), &getQuery)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, int64(0), getQuery.Result.Id, "playlist should've been removed")
|
||||
require.Equal(t, uid, getQuery.Result.UID, "playlist should've been removed")
|
||||
})
|
||||
})
|
||||
|
||||
t.Run("Delete playlist that doesn't exist", func(t *testing.T) {
|
||||
deleteQuery := models.DeletePlaylistCommand{Id: 1, OrgId: 1}
|
||||
deleteQuery := models.DeletePlaylistCommand{UID: "654312", OrgId: 1}
|
||||
err := ss.DeletePlaylist(context.Background(), &deleteQuery)
|
||||
require.NoError(t, err)
|
||||
})
|
||||
@@ -57,8 +66,8 @@ func TestIntegrationPlaylistDataAccess(t *testing.T) {
|
||||
cmd models.DeletePlaylistCommand
|
||||
}{
|
||||
{desc: "none", cmd: models.DeletePlaylistCommand{}},
|
||||
{desc: "no OrgId", cmd: models.DeletePlaylistCommand{Id: 1}},
|
||||
{desc: "no Id", cmd: models.DeletePlaylistCommand{OrgId: 1}},
|
||||
{desc: "no OrgId", cmd: models.DeletePlaylistCommand{UID: "1"}},
|
||||
{desc: "no Uid", cmd: models.DeletePlaylistCommand{OrgId: 1}},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
|
||||
Reference in New Issue
Block a user