mirror of
https://github.com/grafana/grafana.git
synced 2024-11-29 12:14:08 -06:00
05709ce411
* chore: add alias for InitTestDB and Session Adds an alias for the sqlstore InitTestDB and Session, and updates tests using these to reduce dependencies on the sqlstore.Store. * next pass of removing sqlstore imports * last little bit * remove mockstore where possible
48 lines
1.8 KiB
Go
48 lines
1.8 KiB
Go
package queryhistory
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"github.com/grafana/grafana/pkg/infra/db"
|
|
"github.com/grafana/grafana/pkg/web"
|
|
)
|
|
|
|
func TestIntegrationDeleteQueryFromQueryHistory(t *testing.T) {
|
|
if testing.Short() {
|
|
t.Skip("skipping integration test")
|
|
}
|
|
testScenarioWithQueryInQueryHistory(t, "When users tries to delete query in query history that does not exist, it should fail",
|
|
func(t *testing.T, sc scenarioContext) {
|
|
resp := sc.service.deleteHandler(sc.reqContext)
|
|
require.Equal(t, 500, resp.Status())
|
|
})
|
|
|
|
testScenarioWithQueryInQueryHistory(t, "When users tries to delete query in query history that exists, it should succeed",
|
|
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())
|
|
})
|
|
|
|
testScenarioWithQueryInQueryHistory(t, "When users tries to delete query in query history that exists, it should also unstar it and succeed",
|
|
func(t *testing.T, sc scenarioContext) {
|
|
sc.ctx.Req = web.SetURLParams(sc.ctx.Req, map[string]string{":uid": sc.initialResult.Result.UID})
|
|
// Star added query
|
|
sc.service.starHandler(sc.reqContext)
|
|
// Then delete it
|
|
resp := sc.service.deleteHandler(sc.reqContext)
|
|
// Check if query is still in query_history_star table
|
|
err := sc.sqlStore.WithDbSession(context.Background(), func(dbSession *db.Session) error {
|
|
exists, err := dbSession.Table("query_history_star").Where("user_id = ? AND query_uid = ?", sc.reqContext.SignedInUser.UserID, sc.initialResult.Result.UID).Exist()
|
|
require.NoError(t, err)
|
|
require.Equal(t, false, exists)
|
|
return err
|
|
})
|
|
require.NoError(t, err)
|
|
require.Equal(t, 200, resp.Status())
|
|
})
|
|
}
|