diff --git a/pkg/services/sqlstore/playlist.go b/pkg/services/sqlstore/playlist.go index 9fbc3b02bbb4c..269bf06183a95 100644 --- a/pkg/services/sqlstore/playlist.go +++ b/pkg/services/sqlstore/playlist.go @@ -103,7 +103,10 @@ func (ss *SQLStore) GetPlaylist(ctx context.Context, query *models.GetPlaylistBy return ss.WithDbSession(ctx, func(sess *DBSession) error { playlist := models.Playlist{UID: query.UID, OrgId: query.OrgId} - _, err := sess.Get(&playlist) + exists, err := sess.Get(&playlist) + if !exists { + return models.ErrPlaylistNotFound + } query.Result = &playlist return err diff --git a/pkg/services/sqlstore/playlist_test.go b/pkg/services/sqlstore/playlist_test.go index 762b3f93d11fa..a3605bdb42991 100644 --- a/pkg/services/sqlstore/playlist_test.go +++ b/pkg/services/sqlstore/playlist_test.go @@ -25,6 +25,15 @@ func TestIntegrationPlaylistDataAccess(t *testing.T) { require.NoError(t, err) uid := cmd.Result.UID + t.Run("Can get playlist", func(t *testing.T) { + get := &models.GetPlaylistByUidQuery{UID: uid, OrgId: 1} + err = ss.GetPlaylist(context.Background(), get) + require.NoError(t, err) + require.NotNil(t, get.Result) + require.Equal(t, get.Result.Name, "NYC office") + require.Equal(t, get.Result.Interval, "10m") + }) + t.Run("Can get playlist items", func(t *testing.T) { get := &models.GetPlaylistItemsByUidQuery{PlaylistUID: uid, OrgId: 1} err = ss.GetPlaylistItem(context.Background(), get) @@ -49,11 +58,18 @@ func TestIntegrationPlaylistDataAccess(t *testing.T) { getQuery := models.GetPlaylistByUidQuery{UID: uid, OrgId: 1} err = ss.GetPlaylist(context.Background(), &getQuery) - require.NoError(t, err) - require.Equal(t, uid, getQuery.Result.UID, "playlist should've been removed") + require.Error(t, err) + require.ErrorIs(t, err, models.ErrPlaylistNotFound) }) }) + t.Run("Get playlist that doesn't exist", func(t *testing.T) { + get := &models.GetPlaylistByUidQuery{UID: "unknown", OrgId: 1} + err := ss.GetPlaylist(context.Background(), get) + require.Error(t, err) + require.ErrorIs(t, err, models.ErrPlaylistNotFound) + }) + t.Run("Delete playlist that doesn't exist", func(t *testing.T) { deleteQuery := models.DeletePlaylistCommand{UID: "654312", OrgId: 1} err := ss.DeletePlaylist(context.Background(), &deleteQuery)