PublicDashboards: refactor service (#57372)
This commit is contained in:
@@ -88,8 +88,7 @@ func TestIntegrationGetDashboard(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
// AccessTokenExists
|
||||
func TestIntegrationAccessTokenExists(t *testing.T) {
|
||||
func TestIntegrationEnabledPublicDashboardExistsByAccessToken(t *testing.T) {
|
||||
var sqlStore db.DB
|
||||
var cfg *setting.Cfg
|
||||
var dashboardStore *dashboardsDB.DashboardStore
|
||||
@@ -102,7 +101,7 @@ func TestIntegrationAccessTokenExists(t *testing.T) {
|
||||
publicdashboardStore = ProvideStore(sqlStore)
|
||||
savedDashboard = insertTestDashboard(t, dashboardStore, "testDashie", 1, 0, true)
|
||||
}
|
||||
t.Run("AccessTokenExists will return true when at least one public dashboard has a matching access token", func(t *testing.T) {
|
||||
t.Run("PublicDashboardEnabledExistsByAccessToken will return true when at least one public dashboard has a matching access token", func(t *testing.T) {
|
||||
setup()
|
||||
|
||||
err := publicdashboardStore.SavePublicDashboardConfig(context.Background(), SavePublicDashboardConfigCommand{
|
||||
@@ -118,13 +117,13 @@ func TestIntegrationAccessTokenExists(t *testing.T) {
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
res, err := publicdashboardStore.AccessTokenExists(context.Background(), "accessToken")
|
||||
res, err := publicdashboardStore.PublicDashboardEnabledExistsByAccessToken(context.Background(), "accessToken")
|
||||
require.NoError(t, err)
|
||||
|
||||
require.True(t, res)
|
||||
})
|
||||
|
||||
t.Run("AccessTokenExists will return false when IsEnabled=false", func(t *testing.T) {
|
||||
t.Run("PublicDashboardEnabledExistsByAccessToken will return false when IsEnabled=false", func(t *testing.T) {
|
||||
setup()
|
||||
|
||||
err := publicdashboardStore.SavePublicDashboardConfig(context.Background(), SavePublicDashboardConfigCommand{
|
||||
@@ -140,24 +139,23 @@ func TestIntegrationAccessTokenExists(t *testing.T) {
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
res, err := publicdashboardStore.AccessTokenExists(context.Background(), "accessToken")
|
||||
res, err := publicdashboardStore.PublicDashboardEnabledExistsByAccessToken(context.Background(), "accessToken")
|
||||
require.NoError(t, err)
|
||||
|
||||
require.False(t, res)
|
||||
})
|
||||
|
||||
t.Run("AccessTokenExists will return false when no public dashboard has matching access token", func(t *testing.T) {
|
||||
t.Run("PublicDashboardEnabledExistsByAccessToken will return false when no public dashboard has matching access token", func(t *testing.T) {
|
||||
setup()
|
||||
|
||||
res, err := publicdashboardStore.AccessTokenExists(context.Background(), "accessToken")
|
||||
res, err := publicdashboardStore.PublicDashboardEnabledExistsByAccessToken(context.Background(), "accessToken")
|
||||
|
||||
require.NoError(t, err)
|
||||
require.False(t, res)
|
||||
})
|
||||
}
|
||||
|
||||
// PublicDashboardEnabled
|
||||
func TestIntegrationPublicDashboardEnabled(t *testing.T) {
|
||||
func TestIntegrationEnabledPublicDashboardExistsByDashboardUid(t *testing.T) {
|
||||
var sqlStore db.DB
|
||||
var cfg *setting.Cfg
|
||||
var dashboardStore *dashboardsDB.DashboardStore
|
||||
@@ -171,7 +169,7 @@ func TestIntegrationPublicDashboardEnabled(t *testing.T) {
|
||||
savedDashboard = insertTestDashboard(t, dashboardStore, "testDashie", 1, 0, true)
|
||||
}
|
||||
|
||||
t.Run("PublicDashboardEnabled Will return true when dashboard has at least one enabled public dashboard", func(t *testing.T) {
|
||||
t.Run("PublicDashboardEnabledExistsByDashboardUid Will return true when dashboard has at least one enabled public dashboard", func(t *testing.T) {
|
||||
setup()
|
||||
|
||||
err := publicdashboardStore.SavePublicDashboardConfig(context.Background(), SavePublicDashboardConfigCommand{
|
||||
@@ -187,13 +185,13 @@ func TestIntegrationPublicDashboardEnabled(t *testing.T) {
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
res, err := publicdashboardStore.PublicDashboardEnabled(context.Background(), savedDashboard.Uid)
|
||||
res, err := publicdashboardStore.PublicDashboardEnabledExistsByDashboardUid(context.Background(), savedDashboard.Uid)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.True(t, res)
|
||||
})
|
||||
|
||||
t.Run("PublicDashboardEnabled will return false when dashboard has public dashboards but they are not enabled", func(t *testing.T) {
|
||||
t.Run("PublicDashboardEnabledExistsByDashboardUid will return false when dashboard has public dashboards but they are not enabled", func(t *testing.T) {
|
||||
setup()
|
||||
|
||||
err := publicdashboardStore.SavePublicDashboardConfig(context.Background(), SavePublicDashboardConfigCommand{
|
||||
@@ -209,7 +207,7 @@ func TestIntegrationPublicDashboardEnabled(t *testing.T) {
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
res, err := publicdashboardStore.PublicDashboardEnabled(context.Background(), savedDashboard.Uid)
|
||||
res, err := publicdashboardStore.PublicDashboardEnabledExistsByDashboardUid(context.Background(), savedDashboard.Uid)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.False(t, res)
|
||||
|
||||
Reference in New Issue
Block a user