Skip to content

Commit 4df6785

Browse files
committed
feat(EN-214): more fixes after rebase, also fix connection reset workflow
1 parent 10dbc0b commit 4df6785

File tree

9 files changed

+55
-259
lines changed

9 files changed

+55
-259
lines changed

internal/api/services/payment_service_users_forward_bank_account_test.go

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,16 @@ func TestPaymentServiceUsersForwardBankAccountsToConnector(t *testing.T) {
2929
}
3030

3131
tests := []struct {
32-
name string
33-
bankAccountID uuid.UUID
34-
psuID uuid.UUID
35-
engineErr error
36-
bankAccountStorageErr error
37-
psuStorageErr error
38-
expectedEngineError error
39-
expectedStorageError error
40-
typedError bool
32+
name string
33+
bankAccountID uuid.UUID
34+
psuID uuid.UUID
35+
engineErr error
36+
bankAccountStorageErr error
37+
psuStorageErr error
38+
expectedEngineError error
39+
expectedStorageError error
40+
expectedMetadataStorageError error
41+
typedError bool
4142
}{
4243
{
4344
name: "success",
@@ -74,6 +75,13 @@ func TestPaymentServiceUsersForwardBankAccountsToConnector(t *testing.T) {
7475
typedError: true,
7576
expectedStorageError: newStorageError(storage.ErrNotFound, "failed to get bank account"),
7677
},
78+
{
79+
name: "bank account storage error update metadata",
80+
bankAccountID: uuid.New(),
81+
psuID: uuid.New(),
82+
typedError: true,
83+
expectedMetadataStorageError: newStorageError(storage.ErrNotFound, "failed to get bank account"),
84+
},
7785
{
7886
name: "bank account other error",
7987
bankAccountStorageErr: fmt.Errorf("error"),
@@ -94,16 +102,23 @@ func TestPaymentServiceUsersForwardBankAccountsToConnector(t *testing.T) {
94102

95103
for _, test := range tests {
96104
t.Run(test.name, func(t *testing.T) {
97-
store.EXPECT().BankAccountsGet(gomock.Any(), test.bankAccountID, true).Return(&models.BankAccount{}, test.bankAccountStorageErr)
105+
expectedBankAccount := models.BankAccount{
106+
ID: test.bankAccountID,
107+
}
108+
store.EXPECT().BankAccountsGet(gomock.Any(), test.bankAccountID, true).Return(&expectedBankAccount, test.bankAccountStorageErr)
98109

99110
if test.bankAccountStorageErr == nil {
100111
store.EXPECT().PaymentServiceUsersGet(gomock.Any(), test.psuID).Return(&models.PaymentServiceUser{}, test.psuStorageErr)
101112

102113
if test.psuStorageErr == nil {
103-
eng.EXPECT().ForwardBankAccount(gomock.Any(), models.BankAccount{}, connectorID, false).Return(models.Task{}, test.engineErr)
114+
store.EXPECT().BankAccountsUpdateMetadata(gomock.Any(), test.bankAccountID, gomock.Any()).Return(test.expectedMetadataStorageError)
115+
if test.expectedMetadataStorageError == nil {
116+
eng.EXPECT().ForwardBankAccount(gomock.Any(), expectedBankAccount, connectorID, false).Return(models.Task{}, test.engineErr)
117+
}
104118
}
105119
}
106120
_, err := s.PaymentServiceUsersForwardBankAccountToConnector(context.Background(), test.psuID, test.bankAccountID, connectorID)
121+
107122
switch {
108123
case test.expectedEngineError != nil && test.typedError:
109124
require.ErrorIs(t, err, test.expectedEngineError)
@@ -115,6 +130,8 @@ func TestPaymentServiceUsersForwardBankAccountsToConnector(t *testing.T) {
115130
case test.expectedStorageError != nil && !test.typedError:
116131
require.Error(t, err)
117132
require.Equal(t, test.expectedStorageError.Error(), err.Error())
133+
case test.expectedMetadataStorageError != nil && test.typedError:
134+
require.ErrorIs(t, err, test.expectedMetadataStorageError)
118135
default:
119136
require.NoError(t, err)
120137
}

internal/connectors/engine/workflow/fetch_accounts_test.go

Lines changed: 0 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ func (s *UnitTestSuite) Test_FetchNextAccounts_WithoutInstance_Success() {
3737
s.Equal(s.accountID, accounts[0].ID)
3838
return nil
3939
})
40-
s.env.OnWorkflow(Run, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Once().Return(nil)
4140
s.env.OnActivity(activities.StorageStatesStoreActivity, mock.Anything, mock.Anything).Once().Return(nil)
4241

4342
s.env.ExecuteWorkflow(RunFetchNextAccounts, FetchNextAccounts{
@@ -81,7 +80,6 @@ func (s *UnitTestSuite) Test_FetchNextAccounts_WithNextTasks_Success() {
8180
s.Equal(s.accountID, accounts[0].ID)
8281
return nil
8382
})
84-
s.env.OnActivity(activities.SendEventsActivity, mock.Anything, mock.Anything).Once().Return(nil)
8583
s.env.OnActivity(activities.StorageConnectorsGetActivity, mock.Anything, s.connectorID).Once().Return(
8684
&s.connector,
8785
nil,
@@ -139,7 +137,6 @@ func (s *UnitTestSuite) Test_FetchNextAccounts_WithNextTasks_ConnectorScheduledF
139137
s.Equal(s.accountID, accounts[0].ID)
140138
return nil
141139
})
142-
s.env.OnActivity(activities.SendEventsActivity, mock.Anything, mock.Anything).Once().Return(nil)
143140
s.env.OnActivity(activities.StorageConnectorsGetActivity, mock.Anything, s.connectorID).Once().Return(
144141
&connector,
145142
nil,
@@ -199,7 +196,6 @@ func (s *UnitTestSuite) Test_FetchNextAccounts_Success() {
199196
s.Equal(s.accountID, accounts[0].ID)
200197
return nil
201198
})
202-
s.env.OnWorkflow(Run, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Once().Return(nil)
203199
s.env.OnActivity(activities.StorageStatesStoreActivity, mock.Anything, mock.Anything).Once().Return(nil)
204200
s.env.OnActivity(activities.StorageInstancesUpdateActivity, mock.Anything, mock.Anything).Once().Return(func(ctx context.Context, instance models.Instance) error {
205201
s.Equal("test", instance.ScheduleID)
@@ -254,7 +250,6 @@ func (s *UnitTestSuite) Test_FetchNextAccounts_WithoutNextTasks_Success() {
254250
s.Equal(s.accountID, accounts[0].ID)
255251
return nil
256252
})
257-
s.env.OnActivity(activities.SendEventsActivity, mock.Anything, mock.Anything).Once().Return(nil)
258253
s.env.OnActivity(activities.StorageStatesStoreActivity, mock.Anything, mock.Anything).Once().Return(nil)
259254
s.env.OnActivity(activities.StorageInstancesUpdateActivity, mock.Anything, mock.Anything).Once().Return(func(ctx context.Context, instance models.Instance) error {
260255
s.Equal("test", instance.ScheduleID)
@@ -309,7 +304,6 @@ func (s *UnitTestSuite) Test_FetchNextAccounts_HasMoreLoop_Success() {
309304
s.Equal(s.accountID, accounts[0].ID)
310305
return nil
311306
})
312-
s.env.OnWorkflow(Run, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Once().Return(nil)
313307
s.env.OnActivity(activities.StorageStatesStoreActivity, mock.Anything, mock.Anything).Once().Return(nil)
314308

315309
s.env.OnActivity(activities.PluginFetchNextAccountsActivity, mock.Anything, mock.Anything).Once().Return(func(ctx context.Context, req activities.FetchNextAccountsRequest) (*models.FetchNextAccountsResponse, error) {
@@ -476,55 +470,6 @@ func (s *UnitTestSuite) Test_FetchNextAccounts_StorageAccountsStore_Error() {
476470
s.ErrorContains(err, expectedErr.Error())
477471
}
478472

479-
func (s *UnitTestSuite) Test_FetchNextAccounts_Run_Error() {
480-
s.env.OnActivity(activities.StorageInstancesStoreActivity, mock.Anything, mock.Anything).Once().Return(nil)
481-
s.env.OnActivity(activities.StorageStatesGetActivity, mock.Anything, mock.Anything).Once().Return(
482-
&models.State{
483-
ID: models.StateID{
484-
Reference: models.CAPABILITY_FETCH_ACCOUNTS.String(),
485-
ConnectorID: s.connectorID,
486-
},
487-
ConnectorID: s.connectorID,
488-
State: []byte(`{}`),
489-
},
490-
nil,
491-
)
492-
s.env.OnActivity(activities.PluginFetchNextAccountsActivity, mock.Anything, mock.Anything).Once().Return(&models.FetchNextAccountsResponse{
493-
Accounts: []models.PSPAccount{
494-
s.pspAccount,
495-
},
496-
NewState: []byte(`{}`),
497-
HasMore: false,
498-
}, nil)
499-
s.env.OnActivity(activities.StorageAccountsStoreActivity, mock.Anything, mock.Anything).Once().Return(nil)
500-
expectedErr := temporal.NewNonRetryableApplicationError("error-test", "WORKFLOW", errors.New("error-test"))
501-
s.env.OnWorkflow(Run, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Once().Return(expectedErr)
502-
s.env.OnActivity(activities.StorageInstancesUpdateActivity, mock.Anything, mock.Anything).Once().Return(func(ctx context.Context, instance models.Instance) error {
503-
s.True(instance.Terminated)
504-
s.NotNil(instance.Error)
505-
return nil
506-
})
507-
508-
err := s.env.SetTypedSearchAttributesOnStart(temporal.NewSearchAttributes(temporal.NewSearchAttributeKeyKeyword(SearchAttributeScheduleID).ValueSet("test")))
509-
s.NoError(err)
510-
s.env.ExecuteWorkflow(RunFetchNextAccounts, FetchNextAccounts{
511-
Config: models.DefaultConfig(),
512-
ConnectorID: s.connectorID,
513-
FromPayload: nil,
514-
Periodically: false,
515-
}, []models.ConnectorTaskTree{{
516-
Name: "test",
517-
}})
518-
519-
s.True(s.env.IsWorkflowCompleted())
520-
err = s.env.GetWorkflowError()
521-
s.Error(err)
522-
s.ErrorContains(err, "error-test")
523-
workflowErr, ok := err.(*temporal.WorkflowExecutionError)
524-
s.True(ok)
525-
s.ErrorContains(workflowErr.Unwrap(), expectedErr.Error())
526-
}
527-
528473
func (s *UnitTestSuite) Test_FetchNextAccounts_StorageStatesStore_Error() {
529474
s.env.OnActivity(activities.StorageInstancesStoreActivity, mock.Anything, mock.Anything).Once().Return(nil)
530475
s.env.OnActivity(activities.StorageStatesGetActivity, mock.Anything, mock.Anything).Once().Return(
@@ -546,7 +491,6 @@ func (s *UnitTestSuite) Test_FetchNextAccounts_StorageStatesStore_Error() {
546491
HasMore: false,
547492
}, nil)
548493
s.env.OnActivity(activities.StorageAccountsStoreActivity, mock.Anything, mock.Anything).Once().Return(nil)
549-
s.env.OnWorkflow(Run, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Once().Return(nil)
550494
expectedErr := temporal.NewNonRetryableApplicationError("error-test", "STORAGE", errors.New("error-test"))
551495
s.env.OnActivity(activities.StorageStatesStoreActivity, mock.Anything, mock.Anything).Once().Return(expectedErr)
552496
s.env.OnActivity(activities.StorageInstancesUpdateActivity, mock.Anything, mock.Anything).Once().Return(func(ctx context.Context, instance models.Instance) error {
@@ -594,7 +538,6 @@ func (s *UnitTestSuite) Test_FetchNextAccounts_StorageInstancesUpdate_Error() {
594538
HasMore: false,
595539
}, nil)
596540
s.env.OnActivity(activities.StorageAccountsStoreActivity, mock.Anything, mock.Anything).Once().Return(nil)
597-
s.env.OnWorkflow(Run, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Once().Return(nil)
598541
s.env.OnActivity(activities.StorageStatesStoreActivity, mock.Anything, mock.Anything).Once().Return(nil)
599542
expectedErr := temporal.NewNonRetryableApplicationError("error-test", "STORAGE", errors.New("error-test"))
600543
s.env.OnActivity(activities.StorageInstancesUpdateActivity, mock.Anything, mock.Anything).Once().Return(func(ctx context.Context, instance models.Instance) error {

internal/connectors/engine/workflow/fetch_balances_test.go

Lines changed: 0 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ func (s *UnitTestSuite) Test_FetchNextBalances_WithoutInstance_Success() {
3737
s.Equal(s.accountID, balances[0].AccountID)
3838
return nil
3939
})
40-
s.env.OnWorkflow(Run, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Once().Return(nil)
4140
s.env.OnActivity(activities.StorageStatesStoreActivity, mock.Anything, mock.Anything).Once().Return(nil)
4241

4342
s.env.ExecuteWorkflow(RunFetchNextBalances, FetchNextBalances{
@@ -81,7 +80,6 @@ func (s *UnitTestSuite) Test_FetchNextBalances_WithNextTasks_Success() {
8180
s.Equal(s.accountID, balances[0].AccountID)
8281
return nil
8382
})
84-
s.env.OnActivity(activities.SendEventsActivity, mock.Anything, mock.Anything).Once().Return(nil)
8583
s.env.OnActivity(activities.StorageConnectorsGetActivity, mock.Anything, s.connectorID).Once().Return(
8684
&s.connector,
8785
nil,
@@ -139,7 +137,6 @@ func (s *UnitTestSuite) Test_FetchNextBalances_WithNextTasks_ConnectorScheduledF
139137
s.Equal(s.accountID, balances[0].AccountID)
140138
return nil
141139
})
142-
s.env.OnActivity(activities.SendEventsActivity, mock.Anything, mock.Anything).Once().Return(nil)
143140
s.env.OnActivity(activities.StorageConnectorsGetActivity, mock.Anything, s.connectorID).Once().Return(
144141
&connector,
145142
nil,
@@ -199,7 +196,6 @@ func (s *UnitTestSuite) Test_FetchNextBalances_Success() {
199196
s.Equal(s.accountID, balances[0].AccountID)
200197
return nil
201198
})
202-
s.env.OnWorkflow(Run, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Once().Return(nil)
203199
s.env.OnActivity(activities.StorageStatesStoreActivity, mock.Anything, mock.Anything).Once().Return(nil)
204200
s.env.OnActivity(activities.StorageInstancesUpdateActivity, mock.Anything, mock.Anything).Once().Return(func(ctx context.Context, instance models.Instance) error {
205201
s.Equal("test", instance.ScheduleID)
@@ -254,7 +250,6 @@ func (s *UnitTestSuite) Test_FetchNextBalances_WithoutNextTasks_Success() {
254250
s.Equal(s.accountID, balances[0].AccountID)
255251
return nil
256252
})
257-
s.env.OnActivity(activities.SendEventsActivity, mock.Anything, mock.Anything).Once().Return(nil)
258253
s.env.OnActivity(activities.StorageStatesStoreActivity, mock.Anything, mock.Anything).Once().Return(nil)
259254
s.env.OnActivity(activities.StorageInstancesUpdateActivity, mock.Anything, mock.Anything).Once().Return(func(ctx context.Context, instance models.Instance) error {
260255
s.Equal("test", instance.ScheduleID)
@@ -309,7 +304,6 @@ func (s *UnitTestSuite) Test_FetchNextBalances_HasMoreLoop_Success() {
309304
s.Equal(s.accountID, balances[0].AccountID)
310305
return nil
311306
})
312-
s.env.OnWorkflow(Run, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Once().Return(nil)
313307
s.env.OnActivity(activities.StorageStatesStoreActivity, mock.Anything, mock.Anything).Once().Return(nil)
314308

315309
s.env.OnActivity(activities.PluginFetchNextBalancesActivity, mock.Anything, mock.Anything).Once().Return(func(ctx context.Context, req activities.FetchNextBalancesRequest) (*models.FetchNextBalancesResponse, error) {
@@ -475,54 +469,6 @@ func (s *UnitTestSuite) Test_FetchNextBalances_StorageBalancesStore_Error() {
475469
s.ErrorContains(err, expectedErr.Error())
476470
}
477471

478-
func (s *UnitTestSuite) Test_FetchNextBalances_Run_Error() {
479-
s.env.OnActivity(activities.StorageInstancesStoreActivity, mock.Anything, mock.Anything).Once().Return(nil)
480-
s.env.OnActivity(activities.StorageStatesGetActivity, mock.Anything, mock.Anything).Once().Return(
481-
&models.State{
482-
ID: models.StateID{
483-
Reference: models.CAPABILITY_FETCH_BALANCES.String(),
484-
ConnectorID: s.connectorID,
485-
},
486-
ConnectorID: s.connectorID,
487-
State: []byte(`{}`),
488-
},
489-
nil,
490-
)
491-
s.env.OnActivity(activities.PluginFetchNextBalancesActivity, mock.Anything, mock.Anything).Once().Return(&models.FetchNextBalancesResponse{
492-
Balances: []models.PSPBalance{
493-
s.pspBalance,
494-
},
495-
NewState: []byte(`{}`),
496-
HasMore: false,
497-
}, nil)
498-
s.env.OnActivity(activities.StorageBalancesStoreActivity, mock.Anything, mock.Anything).Once().Return(nil)
499-
expectedErr := errors.New("error-test")
500-
s.env.OnWorkflow(Run, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Once().Return(
501-
temporal.NewNonRetryableApplicationError("error-test", "WORKFLOW", expectedErr),
502-
)
503-
s.env.OnActivity(activities.StorageInstancesUpdateActivity, mock.Anything, mock.Anything).Once().Return(func(ctx context.Context, instance models.Instance) error {
504-
s.True(instance.Terminated)
505-
s.NotNil(instance.Error)
506-
return nil
507-
})
508-
509-
err := s.env.SetTypedSearchAttributesOnStart(temporal.NewSearchAttributes(temporal.NewSearchAttributeKeyKeyword(SearchAttributeScheduleID).ValueSet("test")))
510-
s.NoError(err)
511-
s.env.ExecuteWorkflow(RunFetchNextBalances, FetchNextBalances{
512-
Config: models.DefaultConfig(),
513-
ConnectorID: s.connectorID,
514-
FromPayload: nil,
515-
Periodically: false,
516-
}, []models.ConnectorTaskTree{{
517-
Name: "test",
518-
}})
519-
520-
s.True(s.env.IsWorkflowCompleted())
521-
err = s.env.GetWorkflowError()
522-
s.Error(err)
523-
s.ErrorContains(err, expectedErr.Error())
524-
}
525-
526472
func (s *UnitTestSuite) Test_FetchNextBalances_StorageStatesStore_Error() {
527473
s.env.OnActivity(activities.StorageInstancesStoreActivity, mock.Anything, mock.Anything).Once().Return(nil)
528474
s.env.OnActivity(activities.StorageStatesGetActivity, mock.Anything, mock.Anything).Once().Return(
@@ -544,7 +490,6 @@ func (s *UnitTestSuite) Test_FetchNextBalances_StorageStatesStore_Error() {
544490
HasMore: false,
545491
}, nil)
546492
s.env.OnActivity(activities.StorageBalancesStoreActivity, mock.Anything, mock.Anything).Once().Return(nil)
547-
s.env.OnWorkflow(Run, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Once().Return(nil)
548493
expectedErr := errors.New("error-test")
549494
s.env.OnActivity(activities.StorageStatesStoreActivity, mock.Anything, mock.Anything).Once().Return(
550495
temporal.NewNonRetryableApplicationError("error-test", "STORAGE", expectedErr),
@@ -591,7 +536,6 @@ func (s *UnitTestSuite) Test_FetchNextBalances_StorageInstancesUpdate_Error() {
591536
HasMore: false,
592537
}, nil)
593538
s.env.OnActivity(activities.StorageBalancesStoreActivity, mock.Anything, mock.Anything).Once().Return(nil)
594-
s.env.OnWorkflow(Run, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Once().Return(nil)
595539
s.env.OnActivity(activities.StorageStatesStoreActivity, mock.Anything, mock.Anything).Once().Return(nil)
596540
expectedErr := errors.New("error-test")
597541
s.env.OnActivity(activities.StorageInstancesUpdateActivity, mock.Anything, mock.Anything).Once().Return(func(ctx context.Context, instance models.Instance) error {

0 commit comments

Comments
 (0)