mirror of https://github.com/usememos/memos
feat: update InstanceProfile to include initialization status
- Removed the owner field from InstanceProfile as it is no longer needed. - Added an initialized field to InstanceProfile to indicate if the instance has completed first-time setup. - Updated GetInstanceProfile method to set initialized based on the existence of an admin user. - Modified tests to reflect changes in InstanceProfile and ensure correct behavior regarding instance initialization. - Adjusted frontend logic to redirect users based on the initialized status instead of the owner field.pull/5519/head
parent
c240b70591
commit
ba099b72ed
@ -0,0 +1,58 @@
|
|||||||
|
package test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
|
v1pb "github.com/usememos/memos/proto/gen/api/v1"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestInstanceOwnerCache(t *testing.T) {
|
||||||
|
ctx := context.Background()
|
||||||
|
|
||||||
|
t.Run("Instance becomes initialized after first admin user is created", func(t *testing.T) {
|
||||||
|
// Create test service
|
||||||
|
ts := NewTestService(t)
|
||||||
|
defer ts.Cleanup()
|
||||||
|
|
||||||
|
// Verify instance is not initialized initially
|
||||||
|
profile1, err := ts.Service.GetInstanceProfile(ctx, &v1pb.GetInstanceProfileRequest{})
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.False(t, profile1.Initialized, "Instance should not be initialized before first admin user")
|
||||||
|
|
||||||
|
// Create the first admin user
|
||||||
|
user, err := ts.CreateHostUser(ctx, "admin")
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.NotNil(t, user)
|
||||||
|
|
||||||
|
// Verify instance is now initialized
|
||||||
|
profile2, err := ts.Service.GetInstanceProfile(ctx, &v1pb.GetInstanceProfileRequest{})
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.True(t, profile2.Initialized, "Instance should be initialized after first admin user is created")
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("ClearInstanceOwnerCache works correctly", func(t *testing.T) {
|
||||||
|
// Create test service
|
||||||
|
ts := NewTestService(t)
|
||||||
|
defer ts.Cleanup()
|
||||||
|
|
||||||
|
// Create admin user
|
||||||
|
_, err := ts.CreateHostUser(ctx, "admin")
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
// Verify initialized
|
||||||
|
profile1, err := ts.Service.GetInstanceProfile(ctx, &v1pb.GetInstanceProfileRequest{})
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.True(t, profile1.Initialized)
|
||||||
|
|
||||||
|
// Clear cache
|
||||||
|
ts.Service.ClearInstanceOwnerCache()
|
||||||
|
|
||||||
|
// Should still be initialized (cache is refilled from DB)
|
||||||
|
profile2, err := ts.Service.GetInstanceProfile(ctx, &v1pb.GetInstanceProfileRequest{})
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.True(t, profile2.Initialized)
|
||||||
|
})
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue