2023-06-29 17:55:03 +03:00
|
|
|
package teststore
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"github.com/usememos/memos/store"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestUserSettingStore(t *testing.T) {
|
|
|
|
ctx := context.Background()
|
|
|
|
ts := NewTestingStore(ctx, t)
|
|
|
|
user, err := createTestingHostUser(ctx, ts)
|
|
|
|
require.NoError(t, err)
|
2023-07-02 13:56:25 +03:00
|
|
|
testSetting, err := ts.UpsertUserSetting(ctx, &store.UserSetting{
|
2023-06-29 17:55:03 +03:00
|
|
|
UserID: user.ID,
|
|
|
|
Key: "test_key",
|
|
|
|
Value: "test_value",
|
|
|
|
})
|
|
|
|
require.NoError(t, err)
|
2023-07-02 13:56:25 +03:00
|
|
|
localeSetting, err := ts.UpsertUserSetting(ctx, &store.UserSetting{
|
|
|
|
UserID: user.ID,
|
|
|
|
Key: "locale",
|
|
|
|
Value: "zh",
|
|
|
|
})
|
|
|
|
require.NoError(t, err)
|
2023-06-29 17:55:03 +03:00
|
|
|
list, err := ts.ListUserSettings(ctx, &store.FindUserSetting{})
|
|
|
|
require.NoError(t, err)
|
2023-07-02 13:56:25 +03:00
|
|
|
require.Equal(t, 2, len(list))
|
|
|
|
require.Equal(t, testSetting, list[0])
|
|
|
|
require.Equal(t, localeSetting, list[1])
|
2023-06-29 17:55:03 +03:00
|
|
|
}
|