1
0
Fork 0
mirror of https://github.com/anyproto/anytype-heart.git synced 2025-06-10 18:10:49 +09:00

GO-3631 Add more test for account recover etc

This commit is contained in:
mcrakhman 2024-10-09 15:32:30 +02:00
parent 4007934844
commit 09e496061a
No known key found for this signature in database
GPG key ID: DED12CFEF5B8396B
3 changed files with 110 additions and 121 deletions

View file

@ -75,9 +75,61 @@ func TestService_Init(t *testing.T) {
t.Run("new account", func(t *testing.T) {
newFixture(t, nil)
})
t.Run("old account", func(t *testing.T) {
t.Run("old account, analytics id migrated", func(t *testing.T) {
newFixture(t, func(t *testing.T, fx *fixture) {
fx.factory.EXPECT().LoadAndSetTechSpace(mock.Anything).Return(&clientspace.TechSpace{TechSpace: fx.techSpace}, nil)
accObject := mock_techspace.NewMockAccountObject(t)
accObject.EXPECT().GetAnalyticsId().Return("analyticsId", nil)
fx.techSpace.EXPECT().DoAccountObject(mock.Anything, mock.Anything).RunAndReturn(func(ctx2 context.Context, f func(techspace.AccountObject) error) error {
return f(accObject)
})
fx.techSpace.EXPECT().WakeUpViews()
})
})
t.Run("old account, analytics id not migrated", func(t *testing.T) {
newFixture(t, func(t *testing.T, fx *fixture) {
fx.factory.EXPECT().LoadAndSetTechSpace(mock.Anything).Return(&clientspace.TechSpace{TechSpace: fx.techSpace}, nil)
accObject := mock_techspace.NewMockAccountObject(t)
accObject.EXPECT().GetAnalyticsId().Return("", nil)
fx.techSpace.EXPECT().DoAccountObject(mock.Anything, mock.Anything).RunAndReturn(func(ctx2 context.Context, f func(techspace.AccountObject) error) error {
return f(accObject)
})
prCtrl := mock_spacecontroller.NewMockSpaceController(t)
fx.factory.EXPECT().NewPersonalSpace(mock.Anything, mock.Anything).Return(prCtrl, nil)
prCtrl.EXPECT().Close(mock.Anything).Return(nil)
fx.techSpace.EXPECT().WakeUpViews()
})
})
t.Run("old account, no internet, then internet appeared", func(t *testing.T) {
newFixture(t, func(t *testing.T, fx *fixture) {
fx.factory.EXPECT().LoadAndSetTechSpace(mock.Anything).Return(nil, context.DeadlineExceeded).Times(1)
fx.spaceCore.EXPECT().StorageExistsLocally(mock.Anything, fx.spaceId).Return(false, nil)
fx.factory.EXPECT().LoadAndSetTechSpace(mock.Anything).Return(&clientspace.TechSpace{TechSpace: fx.techSpace}, nil)
accObject := mock_techspace.NewMockAccountObject(t)
accObject.EXPECT().GetAnalyticsId().Return("", nil)
fx.techSpace.EXPECT().DoAccountObject(mock.Anything, mock.Anything).RunAndReturn(func(ctx2 context.Context, f func(techspace.AccountObject) error) error {
return f(accObject)
})
prCtrl := mock_spacecontroller.NewMockSpaceController(t)
fx.factory.EXPECT().NewPersonalSpace(mock.Anything, mock.Anything).Return(prCtrl, nil)
prCtrl.EXPECT().Close(mock.Anything).Return(nil)
fx.techSpace.EXPECT().WakeUpViews()
})
})
t.Run("old account, no internet, but personal space exists", func(t *testing.T) {
newFixture(t, func(t *testing.T, fx *fixture) {
fx.factory.EXPECT().LoadAndSetTechSpace(mock.Anything).Return(nil, context.DeadlineExceeded).Times(1)
fx.spaceCore.EXPECT().StorageExistsLocally(mock.Anything, fx.spaceId).Return(true, nil)
fx.spaceCore.EXPECT().Get(mock.Anything, fx.spaceId).Return(nil, nil)
fx.factory.EXPECT().CreateAndSetTechSpace(mock.Anything).Return(&clientspace.TechSpace{TechSpace: fx.techSpace}, nil)
prCtrl := mock_spacecontroller.NewMockSpaceController(t)
fx.factory.EXPECT().NewPersonalSpace(mock.Anything, mock.Anything).Return(prCtrl, nil)
prCtrl.EXPECT().Close(mock.Anything).Return(nil)
accObject := mock_techspace.NewMockAccountObject(t)
accObject.EXPECT().GetAnalyticsId().Return("", nil)
fx.techSpace.EXPECT().DoAccountObject(mock.Anything, mock.Anything).RunAndReturn(func(ctx2 context.Context, f func(techspace.AccountObject) error) error {
return f(accObject)
})
fx.techSpace.EXPECT().WakeUpViews()
})
})