Preferences: Use dashboard uid for the home dashboard (#106666)
This commit is contained in:
@@ -36,56 +36,63 @@ func testIntegrationPreferencesDataAccess(t *testing.T, fn getStore) {
|
||||
t.Run("Get with saved org and user home dashboard should return user home dashboard", func(t *testing.T) {
|
||||
_, err := prefStore.Insert(context.Background(),
|
||||
&pref.Preference{
|
||||
OrgID: 1,
|
||||
UserID: 1,
|
||||
HomeDashboardID: 4,
|
||||
TeamID: 2,
|
||||
Created: time.Now(),
|
||||
Updated: time.Now(),
|
||||
OrgID: 1,
|
||||
UserID: 1,
|
||||
HomeDashboardID: 4, // nolint:staticcheck
|
||||
HomeDashboardUID: "test-uid4",
|
||||
TeamID: 2,
|
||||
Created: time.Now(),
|
||||
Updated: time.Now(),
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
query := &pref.Preference{OrgID: 1, UserID: 1, TeamID: 2}
|
||||
prefs, err := prefStore.Get(context.Background(), query)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, int64(4), prefs.HomeDashboardID)
|
||||
require.Equal(t, int64(4), prefs.HomeDashboardID) // nolint:staticcheck
|
||||
require.Equal(t, "test-uid4", prefs.HomeDashboardUID)
|
||||
})
|
||||
|
||||
t.Run("List with saved org and user home dashboard should return user home dashboard", func(t *testing.T) {
|
||||
_, err := prefStore.Insert(context.Background(),
|
||||
&pref.Preference{
|
||||
OrgID: 1,
|
||||
UserID: 1,
|
||||
TeamID: 3,
|
||||
HomeDashboardID: 1,
|
||||
Created: time.Now(),
|
||||
Updated: time.Now(),
|
||||
OrgID: 1,
|
||||
UserID: 1,
|
||||
TeamID: 3,
|
||||
HomeDashboardID: 1, // nolint:staticcheck
|
||||
HomeDashboardUID: "test-uid1",
|
||||
Created: time.Now(),
|
||||
Updated: time.Now(),
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
query := &pref.Preference{OrgID: 1, UserID: 1, Teams: []int64{2}}
|
||||
prefs, err := prefStore.List(context.Background(), query)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, int64(4), prefs[0].HomeDashboardID)
|
||||
require.Equal(t, int64(4), prefs[0].HomeDashboardID) // nolint:staticcheck
|
||||
require.Equal(t, "test-uid4", prefs[0].HomeDashboardUID)
|
||||
})
|
||||
|
||||
t.Run("List with saved org and other user home dashboard should return org home dashboard", func(t *testing.T) {
|
||||
_, err := prefStore.Insert(context.Background(),
|
||||
&pref.Preference{
|
||||
OrgID: 1,
|
||||
UserID: 2,
|
||||
TeamID: 3,
|
||||
HomeDashboardID: 1,
|
||||
Created: time.Now(),
|
||||
Updated: time.Now(),
|
||||
OrgID: 1,
|
||||
UserID: 2,
|
||||
TeamID: 3,
|
||||
HomeDashboardID: 1, // nolint:staticcheck
|
||||
HomeDashboardUID: "test-uid1",
|
||||
Created: time.Now(),
|
||||
Updated: time.Now(),
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
query := &pref.Preference{OrgID: 1, UserID: 1, Teams: []int64{3}}
|
||||
prefs, err := prefStore.List(context.Background(), query)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, int64(1), prefs[0].HomeDashboardID)
|
||||
require.Equal(t, int64(1), prefs[1].HomeDashboardID)
|
||||
require.Equal(t, int64(1), prefs[0].HomeDashboardID) // nolint:staticcheck
|
||||
require.Equal(t, int64(1), prefs[1].HomeDashboardID) // nolint:staticcheck
|
||||
require.Equal(t, "test-uid1", prefs[0].HomeDashboardUID)
|
||||
require.Equal(t, "test-uid1", prefs[1].HomeDashboardUID)
|
||||
})
|
||||
|
||||
t.Run("List with saved org and teams home dashboard should return last team home dashboard", func(t *testing.T) {
|
||||
@@ -94,64 +101,74 @@ func testIntegrationPreferencesDataAccess(t *testing.T, fn getStore) {
|
||||
}
|
||||
prefs, err := prefStore.List(context.Background(), query)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, int64(4), prefs[0].HomeDashboardID)
|
||||
require.Equal(t, int64(1), prefs[1].HomeDashboardID)
|
||||
require.Equal(t, int64(1), prefs[2].HomeDashboardID)
|
||||
require.Equal(t, int64(4), prefs[0].HomeDashboardID) // nolint:staticcheck
|
||||
require.Equal(t, int64(1), prefs[1].HomeDashboardID) // nolint:staticcheck
|
||||
require.Equal(t, int64(1), prefs[2].HomeDashboardID) // nolint:staticcheck
|
||||
require.Equal(t, "test-uid4", prefs[0].HomeDashboardUID)
|
||||
require.Equal(t, "test-uid1", prefs[1].HomeDashboardUID)
|
||||
require.Equal(t, "test-uid1", prefs[2].HomeDashboardUID)
|
||||
})
|
||||
|
||||
t.Run("List with saved org and other teams home dashboard should return org home dashboard", func(t *testing.T) {
|
||||
_, err := prefStore.Insert(context.Background(), &pref.Preference{OrgID: 1, HomeDashboardID: 1, Created: time.Now(), Updated: time.Now()})
|
||||
// nolint:staticcheck
|
||||
_, err := prefStore.Insert(context.Background(), &pref.Preference{OrgID: 1, HomeDashboardID: 1, HomeDashboardUID: "test-uid1", Created: time.Now(), Updated: time.Now()})
|
||||
require.NoError(t, err)
|
||||
_, err = prefStore.Insert(context.Background(), &pref.Preference{OrgID: 1, TeamID: 2, HomeDashboardID: 2, Created: time.Now(), Updated: time.Now()})
|
||||
// nolint:staticcheck
|
||||
_, err = prefStore.Insert(context.Background(), &pref.Preference{OrgID: 1, TeamID: 2, HomeDashboardID: 2, HomeDashboardUID: "test-uid2", Created: time.Now(), Updated: time.Now()})
|
||||
require.NoError(t, err)
|
||||
_, err = prefStore.Insert(context.Background(), &pref.Preference{OrgID: 1, TeamID: 3, HomeDashboardID: 3, Created: time.Now(), Updated: time.Now()})
|
||||
// nolint:staticcheck
|
||||
_, err = prefStore.Insert(context.Background(), &pref.Preference{OrgID: 1, TeamID: 3, HomeDashboardID: 3, HomeDashboardUID: "test-uid3", Created: time.Now(), Updated: time.Now()})
|
||||
require.NoError(t, err)
|
||||
|
||||
query := &pref.Preference{OrgID: 1}
|
||||
prefs, err := prefStore.List(context.Background(), query)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, int64(1), prefs[0].HomeDashboardID)
|
||||
require.Equal(t, int64(1), prefs[0].HomeDashboardID) // nolint:staticcheck
|
||||
require.Equal(t, "test-uid1", prefs[0].HomeDashboardUID)
|
||||
})
|
||||
|
||||
t.Run("Update for a user should only modify a single value", func(t *testing.T) {
|
||||
ss := db.InitTestDB(t)
|
||||
prefStore := fn(ss)
|
||||
id, err := prefStore.Insert(context.Background(), &pref.Preference{
|
||||
UserID: user.SignedInUser{}.UserID,
|
||||
Theme: "dark",
|
||||
Timezone: "browser",
|
||||
HomeDashboardID: 5,
|
||||
WeekStart: &weekStartOne,
|
||||
JSONData: &pref.PreferenceJSONData{},
|
||||
Created: time.Now(),
|
||||
Updated: time.Now(),
|
||||
UserID: user.SignedInUser{}.UserID,
|
||||
Theme: "dark",
|
||||
Timezone: "browser",
|
||||
HomeDashboardID: 5, // nolint:staticcheck
|
||||
HomeDashboardUID: "test-uid5",
|
||||
WeekStart: &weekStartOne,
|
||||
JSONData: &pref.PreferenceJSONData{},
|
||||
Created: time.Now(),
|
||||
Updated: time.Now(),
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
err = prefStore.Update(context.Background(), &pref.Preference{
|
||||
ID: id,
|
||||
Theme: "dark",
|
||||
HomeDashboardID: 5,
|
||||
Timezone: "browser",
|
||||
WeekStart: &weekStartOne,
|
||||
Created: time.Now(),
|
||||
Updated: time.Now(),
|
||||
JSONData: &pref.PreferenceJSONData{},
|
||||
ID: id,
|
||||
Theme: "dark",
|
||||
HomeDashboardID: 5, // nolint:staticcheck
|
||||
HomeDashboardUID: "test-uid5",
|
||||
Timezone: "browser",
|
||||
WeekStart: &weekStartOne,
|
||||
Created: time.Now(),
|
||||
Updated: time.Now(),
|
||||
JSONData: &pref.PreferenceJSONData{},
|
||||
})
|
||||
require.NoError(t, err)
|
||||
query := &pref.Preference{}
|
||||
prefs, err := prefStore.List(context.Background(), query)
|
||||
require.NoError(t, err)
|
||||
expected := &pref.Preference{
|
||||
ID: prefs[0].ID,
|
||||
Version: prefs[0].Version,
|
||||
HomeDashboardID: 5,
|
||||
Timezone: "browser",
|
||||
WeekStart: &weekStartOne,
|
||||
Theme: "dark",
|
||||
JSONData: prefs[0].JSONData,
|
||||
Created: prefs[0].Created,
|
||||
Updated: prefs[0].Updated,
|
||||
ID: prefs[0].ID,
|
||||
Version: prefs[0].Version,
|
||||
HomeDashboardID: 5, // nolint:staticcheck
|
||||
HomeDashboardUID: "test-uid5",
|
||||
Timezone: "browser",
|
||||
WeekStart: &weekStartOne,
|
||||
Theme: "dark",
|
||||
JSONData: prefs[0].JSONData,
|
||||
Created: prefs[0].Created,
|
||||
Updated: prefs[0].Updated,
|
||||
}
|
||||
if diff := cmp.Diff(expected, prefs[0]); diff != "" {
|
||||
t.Fatalf("Result mismatch (-want +got):\n%s", diff)
|
||||
|
||||
Reference in New Issue
Block a user