Files
grafana/pkg/models/dashboards_public_test.go
Jeff Levin d076bedb5e public dashboards: finalize db schema & v1 feature complete (#50467)
This PR completes public dashboards v1 functionality and simplifies public dashboard conventions. It exists as a large PR so that we are not making constant changes to the database schema.

models.PublicDashboardConfig model replaced with models.PublicDashboard directly
dashboard_public_config table renamed to dashboard_public
models.Dashboard.IsPublic removed from the dashboard and replaced with models.PublicDashboard.isEnabled
Routing now uses a uuid v4 as an access token for viewing a public dashboard anonymously, PublicDashboard.Uid only used as database identifier
Frontend utilizes uuid for auth'd operations and access token for anonymous access
Default to time range defined on dashboard when viewing public dashboard
Add audit fields to public dashboard

Co-authored-by: Owen Smallwood <owen.smallwood@grafana.com>, Ezequiel Victorero <ezequiel.victorero@grafana.com>, Jesse Weaver <jesse.weaver@grafana.com>
2022-06-22 13:58:52 -08:00

57 lines
1.4 KiB
Go

package models
import (
"testing"
"github.com/grafana/grafana/pkg/components/simplejson"
"github.com/stretchr/testify/assert"
)
func TestPublicDashboardTableName(t *testing.T) {
assert.Equal(t, "dashboard_public", PublicDashboard{}.TableName())
}
func TestBuildTimeSettings(t *testing.T) {
var dashboardData = simplejson.NewFromAny(map[string]interface{}{"time": map[string]interface{}{"from": "now-8", "to": "now"}})
testCases := []struct {
name string
dashboard *Dashboard
pubdash *PublicDashboard
timeResult *TimeSettings
}{
{
name: "should use dashboard time if pubdash time empty",
dashboard: &Dashboard{Data: dashboardData},
pubdash: &PublicDashboard{},
timeResult: &TimeSettings{
From: "now-8",
To: "now",
},
},
{
name: "should use dashboard time if pubdash to/from empty",
dashboard: &Dashboard{Data: dashboardData},
pubdash: &PublicDashboard{},
timeResult: &TimeSettings{
From: "now-8",
To: "now",
},
},
{
name: "should use pubdash time",
dashboard: &Dashboard{Data: dashboardData},
pubdash: &PublicDashboard{TimeSettings: simplejson.NewFromAny(map[string]interface{}{"from": "now-12", "to": "now"})},
timeResult: &TimeSettings{
From: "now-12",
To: "now",
},
},
}
for _, test := range testCases {
t.Run(test.name, func(t *testing.T) {
assert.Equal(t, test.timeResult, test.pubdash.BuildTimeSettings(test.dashboard))
})
}
}