8000 feat(*): revert support v2 events as well as v3 events (#394)" by paul-nicolas · Pull Request #395 · formancehq/payments · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

feat(*): revert support v2 events as well as v3 events (#394)" #395

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
)

func (a Activities) EventsSendAccount(ctx context.Context, account models.Account) error {
return a.events.Publish(ctx, a.events.NewEventSavedAccounts(account)...)
return a.events.Publish(ctx, a.events.NewEventSavedAccounts(account))

Check warning on line 11 in internal/connectors/engine/activities/events_send_account.go

View check run for this annotation

Codecov / codecov/patch

internal/connectors/engine/activities/events_send_account.go#L11

Added line #L11 was not covered by tests
}

var EventsSendAccountActivity = Activities{}.EventsSendAccount
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
)

func (a Activities) EventsSendBalance(ctx context.Context, balance models.Balance) error {
return a.events.Publish(ctx, a.events.NewEventSavedBalances(balance)...)
return a.events.Publish(ctx, a.events.NewEventSavedBalances(balance))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Verification agent

🧩 Analysis chain

Consistent event publishing pattern for balance events

This change follows the same pattern as other event publishing modifications, removing the variadic syntax to align with the v3 events standardization goal.

The static analysis indicates this line isn't covered by tests. Consider ensuring test coverage for the updated event publishing functionality, particularly since this represents a fundamental change in how events are structured.


🏁 Script executed:

#!/bin/bash
# Checking test coverage for balance events
echo "Searching for test files related to balance events..."
fd -e go -g "*test*" events_send_balance

echo "\nChecking test coverage for NewEventSavedBalances..."
fd -e go -g "*test*" events | xargs grep -l "NewEventSavedBalances" || echo "No direct tests found for NewEventSavedBalances"

# Check for integration tests that might cover this functionality
echo "\nChecking for integration tests that might cover balance events..."
fd -e go -g "*integration*test*" | xargs grep -l "Balance" || echo "No integration tests found for balance events"

Length of output: 955


Action Required: Enhance Test Coverage for the Updated Events Publishing Functionality

The updated event publishing code follows the v3 events standardization, aligning with the approach used in other parts of the code. However, our analysis indicates that there are currently no tests covering the newly implemented NewEventSavedBalances functionality. This is concerning given that it represents a fundamental change in event structure. Please add appropriate unit and/or integration tests to verify that the balance events are published and structured correctly.

  • File to review: internal/connectors/engine/activities/events_send_balance.go
  • Action: Add test cases that target the NewEventSavedBalances event publishing path. Consider both direct unit tests and integration tests to ensure comprehensive coverage.
🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 11-12: internal/connectors/engine/activities/events_send_balance.go#L11-L12
Added lines #L11 - L12 were not covered by tests

}

Check warning on line 12 in internal/connectors/engine/activities/events_send_balance.go

View check run for this annotation

Codecov / codecov/patch

internal/connectors/engine/activities/events_send_balance.go#L11-L12

Added lines #L11 - L12 were not covered by tests

var EventsSendBalanceActivity = Activities{}.EventsSendBalance

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
)

func (a Activities) EventsSendBankAccount(ctx context.Context, bankAccount models.BankAccount) error {
bas, err := a.events.NewEventSavedBankAccounts(bankAccount)
ba, err := a.events.NewEventSavedBankAccounts(bankAccount)
if err != nil {
return fmt.Errorf("failed to send bank account events: %w", err)
return fmt.Errorf("failed to send bank account: %w", err)

Check warning on line 14 in internal/connectors/engine/activities/events_send_bank_account.go

View check run for this annotation

Codecov / codecov/patch

internal/connectors/engine/activities/events_send_bank_account.go#L14

Added line #L14 was not covered by tests
}
return a.events.Publish(ctx, bas...)
return a.events.Publish(ctx, ba)

Check warning on line 16 in internal/connectors/engine/activities/events_send_bank_account.go

View check run for this annotation

Codecov / codecov/patch

internal/connectors/engine/activities/events_send_bank_account.go#L16

Added line #L16 was not covered by tests
}

var EventsSendBankAccountActivity = Activities{}.EventsSendBankAccount
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
)

func (a Activities) EventsSendConnectorReset(ctx context.Context, connectorID models.ConnectorID, at time.Time) error {
return a.events.Publish(ctx, a.events.NewEventResetConnector(connectorID, at)...)
return a.events.Publish(ctx, a.events.NewEventResetConnector(connectorID, at))

Check warning on line 12 in internal/connectors/engine/activities/events_send_connector_reset.go

View check run for this annotation

Codecov / codecov/patch

internal/connectors/engine/activities/events_send_connector_reset.go#L12

Added line #L12 was not covered by tests
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Verification agent

🧩 Analysis chain

Standardized event publishing pattern for v3 events

The removal of the variadic syntax in this event publishing call is consistent with the changes in other files and aligns with the PR objective to standardize on v3 events.

Similar to the other files, static analysis shows this line isn't covered by tests. Consider adding or extending tests to verify this functionality works as expected after removing v2 event support.


🏁 Script executed:

#!/bin/bash
# Checking test coverage for connector reset events
echo "Searching for test files related to connector reset events..."
fd -e go -g "*test*" events_send_connector_reset

echo "\nChecking test coverage for NewEventResetConnector..."
fd -e go -g "*test*" events | xargs grep -l "NewEventResetConnector" || echo "No direct tests found for NewEventResetConnector"

Length of output: 687


Standardized V3 Event Publishing – Test Coverage Needed

The updated event publishing in
internal/connectors/engine/activities/events_send_connector_reset.go (line 12):

return a.events.Publish(ctx, a.events.NewEventResetConnector(connectorID, at))

now aligns with the PR objective to standardize on v3 events. However, our investigation using static analysis indicates that there aren’t any direct tests covering the functionality of NewEventResetConnector (as confirmed by the errors when searching for related test files). To ensure this change behaves as expected after dropping v2 event support, please add or extend tests to cover this event publishing path—similar to what’s done (or needed) in other parts of the codebase.

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 12-12: internal/connectors/engine/activities/events_send_connector_reset.go#L12
Added line #L12 was not covered by tests

}

var EventsSendConnectorResetActivity = Activities{}.EventsSendConnectorReset
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
}

func (a Activities) EventsSendPayment(ctx context.Context, req EventsSendPaymentRequest) error {
return a.events.Publish(ctx, a.events.NewEventSavedPayments(req.Payment, req.Adjustment)...)
return a.events.Publish(ctx, a.events.NewEventSavedPayments(req.Payment, req.Adjustment))

Check warning on line 16 in internal/connectors/engine/activities/events_send_payment.go

View check run for this annotation

Codecov / codecov/patch

internal/connectors/engine/activities/events_send_payment.go#L16

Added line #L16 was not covered by tests
}

var EventsSendPaymentActivity = Activities{}.EventsSendPayment
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
)

func (a Activities) EventsSendPaymentInitiation(ctx context.Context, pi models.PaymentInitiation) error {
return a.events.Publish(ctx, a.events.NewEventSavedPaymentInitiation(pi)...)
return a.events.Publish(ctx, a.events.NewEventSavedPaymentInitiation(pi))

Check warning on line 11 in internal/connectors/engine/activities/events_send_payment_initiation.go

View check run for this annotation

Codecov / codecov/patch

internal/connectors/engine/activities/events_send_payment_initiation.go#L11

Added line #L11 was not covered by tests
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Verification agent

🧩 Analysis chain

Standardized event handling for payment initiation events

This modification removes the variadic syntax from the Publish method call, consistent with the other event publishing changes and the PR objective to standardize on v3 events.

As with the other files, static analysis indicates this line isn't covered by tests. Consider adding test coverage to verify this critical functionality works correctly after the event structure changes.


🏁 Script executed:

#!/bin/bash
# Checking test coverage for payment initiation events
echo "Searching for test files related to payment initiation events..."
fd -e go -g "*test*" events_send_payment_initiation

echo "\nChecking test coverage for NewEventSavedPaymentInitiation..."
fd -e go -g "*test*" events | xargs grep -l "NewEventSavedPaymentInitiation" || echo "No direct tests found for NewEventSavedPaymentInitiation"

# Check if there are broader integration tests covering event publishing
echo "\nChecking integration tests that might cover payment events..."
fd -e go -g "*integration*test*" | xargs grep -l "Payment" || echo "No integration tests found for payment events"

Length of output: 1036


🏁 Script executed:

#!/bin/bash
# Checking for changes in the event creation functions
echo "Looking at implementation of event creation functions that are being called..."
rg -A 5 -B 5 "func .* NewEventSavedPaymentInitiation" || echo "Function definition not found"
rg -A 5 -B 5 "func .* NewEventSavedBalances" || echo "Function definition not found"
rg -A 5 -B 5 "func .* NewEventSavedAccounts" || echo "Function definition not found"
rg -A 5 -B 5 "func .* NewEventResetConnector" || echo "Function definition not found"

Length of output: 5292


Standardized event handling for payment initiation events – please add tests

This change correctly updates the call to Publish by removing the variadic syntax, aligning it with the standardized v3 events approach. However, static analysis (and our test search efforts) indicate that there is currently no direct unit or integration test covering the NewEventSavedPaymentInitiation functionality. Please consider adding appropriate tests to ensure that any impacts from the event structure changes are properly verified.

  • Location: internal/connectors/engine/activities/events_send_payment_initiation.go (line 11)
  • Affected Function: NewEventSavedPaymentInitiation in internal/events/payment_initiation.go
  • Action: Add or enhance test coverage (unit/integration) for this event publishing functionality
🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 11-11: internal/connectors/engine/activities/events_send_payment_initiation.go#L11
Added line #L11 was not covered by tests

}

var EventsSendPaymentInitiationActivity = Activities{}.EventsSendPaymentInitiation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
"go.temporal.io/sdk/workflow"
)

func (a Activities) EventsSendPaymentInitiationAdjustment(ctx context.Context, adj models.PaymentInitiationAdjustment, pi models.PaymentInitiation) error {
return a.events.Publish(ctx, a.events.NewEventSavedPaymentInitiationAdjustment(adj, pi)...)
func (a Activities) EventsSendPaymentInitiationAdjustment(ctx context.Context, adj models.PaymentInitiationAdjustment) error {
return a.events.Publish(ctx, a.events.NewEventSavedPaymentInitiationAdjustment(adj))

Check warning on line 11 in internal/connectors/engine/activities/events_send_payment_initiation_adjustment.go

View check run for this annotation

Codecov / codecov/patch

internal/connectors/engine/activities/events_send_payment_initiation_adjustment.go#L10-L11

Added lines #L10 - L11 were not covered by tests
}

var EventsSendPaymentInitiationAdjustmentActivity = Activities{}.EventsSendPaymentInitiationAdjustment

func EventsSendPaymentInitiationAdjustment(ctx workflow.Context, adj models.PaymentInitiationAdjustment, pi models.PaymentInitiation) error {
return executeActivity(ctx, EventsSendPaymentInitiationAdjustmentActivity, nil, adj, pi)
func EventsSendPaymentInitiationAdjustment(ctx workflow.Context, adj models.PaymentInitiationAdjustment) error {
return executeActivity(ctx, EventsSendPaymentInitiationAdjustmentActivity, nil, adj)

Check warning on line 17 in internal/connectors/engine/activities/events_send_payment_initiation_adjustment.go

View check run for this annotation

Codecov / codecov/patch

internal/connectors/engine/activities/events_send_payment_initiation_adjustment.go#L16-L17

Added lines #L16 - L17 were not covered by tests
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,12 @@
"go.temporal.io/sdk/workflow"
)

func (a Activities) EventsSendPaymentInitiationRelatedPayment(
ctx context.Context,
relatedPayment models.PaymentInitiationRelatedPayments,
pi models.PaymentInitiation,
status models.PaymentInitiationAdjustmentStatus,
) error {
return a.events.Publish(ctx, a.events.NewEventSavedPaymentInitiationRelatedPayment(relatedPayment, pi, status)...)
func (a Activities) EventsSendPaymentInitiationRelatedPayment(ctx context.Context, relatedPayment models.PaymentInitiationRelatedPayments) error {
return a.events.Publish(ctx, a.events.NewEventSavedPaymentInitiationRelatedPayment(relatedPayment))

Check warning on line 11 in internal/connectors/engine/activities/events_send_payment_initiation_related_payments.go

View check run for this annotation

Codecov / codecov/patch

internal/connectors/engine/activities/events_send_payment_initiation_related_payments.go#L10-L11

Added lines #L10 - L11 were not covered by tests
}

var EventsSendPaymentInitiationRelatedPaymentActivity = Activities{}.EventsSendPaymentInitiationRelatedPayment

func EventsSendPaymentInitiationRelatedPayment(
ctx workflow.Context,
relatedPayment models.PaymentInitiationRelatedPayments,
pi models.PaymentInitiation,
status models.PaymentInitiationAdjustmentStatus,
) error {
return executeActivity(ctx, EventsSendPaymentInitiationRelatedPaymentActivity, nil, relatedPayment, pi, status)
func EventsSendPaymentInitiationRelatedPayment(ctx workflow.Context, relatedPayment models.PaymentInitiationRelatedPayments) error {
return executeActivity(ctx, EventsSendPaymentInitiationRelatedPaymentActivity, nil, relatedPayment)

Check warning on line 17 in internal/connectors/engine/activities/events_send_payment_initiation_related_payments.go

View check run for this annotation

Codecov / codecov/patch

internal/connectors/engine/activities/events_send_payment_initiation_related_payments.go#L16-L17

Added lines #L16 - L17 were not covered by tests
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
)

func (a Activities) EventsSendPoolCreation(ctx context.Context, pool models.Pool) error {
return a.events.Publish(ctx, a.events.NewEventSavedPool(pool)...)
return a.events.Publish(ctx, a.events.NewEventSavedPool(pool))

Check warning on line 11 in internal/connectors/engine/activities/events_send_pool_creation.go

View check run for this annotation

Codecov / codecov/patch

internal/connectors/engine/activities/events_send_pool_creation.go#L11

Added line #L11 was not covered by tests
}

var EventsSendPoolCreationActivity = Activities{}.EventsSendPoolCreation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,17 @@

import (
"context"
"time"

"github.com/google/uuid"
"go.temporal.io/sdk/workflow"
)

func (a Activities) EventsSendPoolDeletion(ctx context.Context, id uuid.UUID, at time.Time) error {
return a.events.Publish(ctx, a.events.NewEventDeletePool(id, at)...)
func (a Activities) EventsSendPoolDeletion(ctx context.Context, id uuid.UUID) error {
return a.events.Publish(ctx, a.events.NewEventDeletePool(id))

Check warning on line 11 in internal/connectors/engine/activities/events_send_pool_deletion.go

View check run for this annotation

Codecov / codecov/patch

internal/connectors/engine/activities/events_send_pool_deletion.go#L10-L11

Added lines #L10 - L11 were not covered by tests
}

var EventsSendPoolDeletionActivity = Activities{}.EventsSendPoolDeletion

func EventsSendPoolDeletion(ctx workflow.Context, id uuid.UUID, at time.Time) error {
return executeActivity(ctx, EventsSendPoolDeletionActivity, nil, id, at)
func EventsSendPoolDeletion(ctx workflow.Context, id uuid.UUID) error {
return executeActivity(ctx, EventsSendPoolDeletionActivity, nil, id)

Check warning on line 17 in internal/connectors/engine/activities/events_send_pool_deletion.go

View check run for this annotation

Codecov / codecov/patch

internal/connectors/engine/activities/events_send_pool_deletion.go#L16-L17

Added lines #L16 - L17 were not covered by tests
}
7 changes: 2 additions & 5 deletions internal/connectors/engine/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -477,11 +477,8 @@
},
workflow.RunSendEvents,
workflow.SendEvents{
PaymentInitiation: &pi,
SendEventPaymentInitiationAdjustment: &workflow.SendEventPaymentInitiationAdjustment{
PaymentInitiation: &pi,
PaymentInitiationAdjustment: &adj,
},
PaymentInitiation: &pi,
PaymentInitiationAdjustment: &adj,

Check warning on line 481 in internal/connectors/engine/engine.go

View check run for this annotation

Codecov / codecov/patch

internal/connectors/engine/engine.go#L480-L481

Added lines #L480 - L481 were not covered by tests
},
Comment on lines +480 to 482
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Verification agent

🧩 Analysis chain

Simplified event payload structure.

Good refactoring to flatten the SendEvents structure by directly including the PaymentInitiation and PaymentInitiationAdjustment fields rather than using a nested approach. This makes the code more readable and consistent with the standardized event structure used throughout the codebase.

Static analysis indicates these lines lack test coverage. Consider adding a test case for CreateFormancePaymentInitiation that verifies events are properly structured:


🏁 Script executed:

#!/bin/bash
# Check if there are any tests covering the CreateFormancePaymentInitiation method

echo "Searching for tests that cover CreateFormancePaymentInitiation..."
rg -l "Test.*CreateFormancePaymentInitiation" --type go

Length of output: 198


Simplified Event Payload Structure: Approval with Test Coverage Needed

Great job on flattening the SendEvents structure. Directly embedding the PaymentInitiation and PaymentInitiationAdjustment fields improves readability and consistency across the codebase.

However, our search for tests covering the CreateFormancePaymentInitiation method returned no results. To ensure that this refactoring works as expected and to guard against regressions, please add a test case that verifies the event payload—including both PaymentInitiation and PaymentInitiationAdjustment—is structured correctly.

For example, you could start by double-checking the test coverage with:

#!/bin/bash
echo "Searching for tests that cover CreateFormancePaymentInitiation..."
rg -l "Test.*CreateFormancePaymentInitiation" --type go

Once the tests are in place, it will strengthen our confidence in this refactoring.

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 480-481: internal/connectors/engine/engine.go#L480-L481
Added lines #L480 - L481 were not covered by tests

)
if err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ func (w Workflow) createBankAccount(

bankAccount.RelatedAccounts = append(bankAccount.RelatedAccounts, relatedAccount)

// Do not wait for the events to be sent
if err := workflow.ExecuteChildWorkflow(
workflow.WithChildOptions(
ctx,
Expand All @@ -110,7 +109,7 @@ func (w Workflow) createBankAccount(
SendEvents{
BankAccount: bankAccount,
},
).GetChildWorkflowExecution().Get(ctx, nil); err != nil {
).Get(ctx, nil); err != nil {
return "", err
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,13 +164,41 @@ func (s *UnitTestSuite) Test_CreateBankAccount_StorageBankAccountsAddRelatedAcco
s.Error(err)
}

func (s *UnitTestSuite) Test_CreateBankAccount_RunSendEvents_Error() {
s.env.OnActivity(activities.StorageBankAccountsGetActivity, mock.Anything, s.bankAccount.ID, true).Once().Return(&s.bankAccount, nil)
s.env.OnActivity(activities.PluginCreateBankAccountActivity, mock.Anything, mock.Anything).Once().Return(&models.CreateBankAccountResponse{
RelatedAccount: s.pspAccount,
}, nil)
s.env.OnActivity(activities.StorageAccountsStoreActivity, mock.Anything, mock.Anything).Once().Return(nil)
s.env.OnActivity(activities.StorageBankAccountsAddRelatedAccountActivity, mock.Anything, s.bankAccount.ID, mock.Anything).Once().Return(nil)
s.env.OnWorkflow(s.w.runSendEvents, mock.Anything, mock.Anything).Once().Return(temporal.NewNonRetryableApplicationError("test", "test", errors.New("test")))
s.env.OnActivity(activities.StorageTasksStoreActivity, mock.Anything, mock.Anything).Once().Return(func(ctx context.Context, task models.Task) error {
s.Equal(models.TASK_STATUS_FAILED, task.Status)
return nil
})

s.env.ExecuteWorkflow(RunCreateBankAccount, CreateBankAccount{
TaskID: models.TaskID{
Reference: "test",
ConnectorID: s.connectorID,
},
ConnectorID: s.connectorID,
BankAccountID: s.bankAccount.ID,
})

s.True(s.env.IsWorkflowCompleted())
err := s.env.GetWorkflowError()
s.Error(err)
}

func (s *UnitTestSuite) Test_CreateBankAccount_StorageTasksStore_Error() {
s.env.OnActivity(activities.StorageBankAccountsGetActivity, mock.Anything, s.bankAccount.ID, true).Once().Return(&s.bankAccount, nil)
s.env.OnActivity(activities.PluginCreateBankAccountActivity, mock.Anything, mock.Anything).Once().Return(&models.CreateBankAccountResponse{
RelatedAccount: s.pspAccount,
}, nil)
s.env.OnActivity(activities.StorageAccountsStoreActivity, mock.Anything, mock.Anything).Once().Return(nil)
s.env.OnActivity(activities.StorageBankAccountsAddRelatedAccountActivity, mock.Anything, s.bankAccount.ID, mock.Anything).Once().Return(temporal.NewNonRetryableApplicationError("test", "test", errors.New("test")))
s.env.OnActivity(activities.StorageBankAccountsAddRelatedAccountActivity, mock.Anything, s.bankAccount.ID, mock.Anything).Once().Return(nil)
s.env.OnWorkflow(s.w.runSendEvents, mock.Anything, mock.Anything).Once().Return(temporal.NewNonRetryableApplicationError("test", "test", errors.New("test")))
s.env.OnActivity(activities.StorageTasksStoreActivity, mock.Anything, mock.Anything).Once().Return(func(ctx context.Context, task models.Task) error {
s.Equal(models.TASK_STATUS_FAILED, task.Status)
return temporal.NewNonRetryableApplicationError("test", "test", errors.New("test"))
Expand Down
15 changes: 6 additions & 9 deletions internal/connectors/engine/workflow/create_payout.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ func (w Workflow) createPayout(
if !pi.ScheduledAt.IsZero() && pi.ScheduledAt.After(now) {
err = w.addPIAdjustment(
ctx,
pi,
models.PaymentInitiationAdjustmentID{
PaymentInitiationID: createPayout.PaymentInitiationID,
CreatedAt: workflow.Now(ctx),
Expand Down Expand Up @@ -90,7 +89,6 @@ func (w Workflow) createPayout(

err = w.addPIAdjustment(
ctx,
pi,
models.PaymentInitiationAdjustmentID{
PaymentInitiationID: createPayout.PaymentInitiationID,
CreatedAt: workflow.Now(ctx),
Expand Down Expand Up @@ -120,7 +118,7 @@ func (w Workflow) createPayout(
if err := w.storePIPaymentWithStatus(
ctx,
payment,
pi,
createPayout.PaymentInitiationID,
getPIStatusFromPayment(payment.Status),
); err != nil {
return err
Expand Down Expand Up @@ -164,11 +162,11 @@ func (w Workflow) createPayout(
Workflow: RunPollPayout,
Args: []interface{}{
PollPayout{
TaskID: createPayout.TaskID,
ConnectorID: createPayout.ConnectorID,
PaymentInitiation: pi,
PayoutID: *createPayoutResponse.PollingPayoutID,
ScheduleID: scheduleID,
TaskID: createPayout.TaskID,
ConnectorID: createPayout.ConnectorID,
PaymentInitiationID: createPayout.PaymentInitiationID,
PayoutID: *createPayoutResponse.PollingPayoutID,
ScheduleID: scheduleID,
},
},
TaskQueue: w.getDefaultTaskQueue(),
Expand Down Expand Up @@ -200,7 +198,6 @@ func (w Workflow) createPayout(
cause := errorsutils.Cause(errPlugin)
err = w.addPIAdjustment(
ctx,
pi,
models.PaymentInitiationAdjustmentID{
PaymentInitiationID: createPayout.PaymentInitiationID,
CreatedAt: workflow.Now(ctx),
Expand Down
47 changes: 39 additions & 8 deletions internal/connectors/engine/workflow/create_payout_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func (s *UnitTestSuite) Test_CreatePayout_WithPayment_Success() {
return nil
})
s.env.OnWorkflow(RunSendEvents, mock.Anything, mock.Anything).Once().Return(func(ctx workflow.Context, req SendEvents) error {
s.NotNil(req.SendEventPaymentInitiationAdjustment)
s.NotNil(req.PaymentInitiationAdjustment)
return nil
})
s.env.OnActivity(activities.PluginCreatePayoutActivity, mock.Anything, mock.Anything).Once().Return(func(ctx context.Context, req activities.CreatePayoutRequest) (*models.CreatePayoutResponse, error) {
Expand All @@ -50,7 +50,7 @@ func (s *UnitTestSuite) Test_CreatePayout_WithPayment_Success() {
})
s.env.OnWorkflow(RunSendEvents, mock.Anything, mock.Anything).Once().Return(func(ctx workflow.Context, req SendEvents) error {
s.NotNil(req.Payment)
s.NotNil(req.SendEventPaymentInitiationRelatedPayment)
s.NotNil(req.PaymentInitiationRelatedPayment)
s.Nil(req.Account)
s.Nil(req.Balance)
s.Nil(req.BankAccount)
Expand All @@ -69,7 +69,7 @@ func (s *UnitTestSuite) Test_CreatePayout_WithPayment_Success() {
return nil
})
s.env.OnWorkflow(RunSendEvents, mock.Anything, mock.Anything).Once().Return(func(ctx workflow.Context, req SendEvents) error {
s.NotNil(req.SendEventPaymentInitiationAdjustment)
s.NotNil(req.PaymentInitiationAdjustment)
return nil
})
s.env.OnActivity(activities.StorageTasksStoreActivity, mock.Anything, mock.Anything).Once().Return(func(ctx context.Context, task models.Task) error {
Expand Down Expand Up @@ -104,7 +104,7 @@ func (s *UnitTestSuite) Test_CreatePayout_WithScheduledAt_WithPayment_Success()
return nil
})
s.env.OnWorkflow(RunSendEvents, mock.Anything, mock.Anything).Once().Return(func(ctx workflow.Context, req SendEvents) error {
s.NotNil(req.SendEventPaymentInitiationAdjustment)
s.NotNil(req.PaymentInitiationAdjustment)
return nil
})
s.env.OnActivity(activities.StorageAccountsGetActivity, mock.Anything, *s.paymentInitiationPayout.SourceAccountID).Once().Return(&s.account, nil)
Expand All @@ -119,7 +119,7 @@ func (s *UnitTestSuite) Test_CreatePayout_WithScheduledAt_WithPayment_Success()
return nil
})
s.env.OnWorkflow(RunSendEvents, mock.Anything, mock.Anything).Once().Return(func(ctx workflow.Context, req SendEvents) error {
s.NotNil(req.SendEventPaymentInitiationAdjustment)
s.NotNil(req.PaymentInitiationAdjustment)
return nil
})
s.env.OnActivity(activities.PluginCreatePayoutActivity, mock.Anything, mock.Anything).Once().Return(func(ctx context.Context, req activities.CreatePayoutRequest) (*models.CreatePayoutResponse, error) {
Expand All @@ -141,7 +141,7 @@ func (s *UnitTestSuite) Test_CreatePayout_WithScheduledAt_WithPayment_Success()
})
s.env.OnWorkflow(RunSendEvents, mock.Anything, mock.Anything).Once().Return(func(ctx workflow.Context, req SendEvents) error {
s.NotNil(req.Payment)
s.NotNil(req.SendEventPaymentInitiationRelatedPayment)
s.NotNil(req.PaymentInitiationRelatedPayment)
s.Nil(req.Account)
s.Nil(req.Balance)
s.Nil(req.BankAccount)
Expand All @@ -160,7 +160,7 @@ func (s *UnitTestSuite) Test_CreatePayout_WithScheduledAt_WithPayment_Success()
return nil
})
s.env.OnWorkflow(RunSendEvents, mock.Anything, mock.Anything).Once().Return(func(ctx workflow.Context, req SendEvents) error {
s.NotNil(req.SendEventPaymentInitiationAdjustment)
s.NotNil(req.PaymentInitiationAdjustment)
return nil
})
s.env.OnActivity(activities.StorageTasksStoreActivity, mock.Anything, mock.Anything).Once().Return(func(ctx context.Context, task models.Task) error {
Expand Down Expand Up @@ -194,7 +194,7 @@ func (s *UnitTestSuite) Test_CreatePayout_WithPollingPayment_Success() {
return nil
})
s.env.OnWorkflow(RunSendEvents, mock.Anything, mock.Anything).Once().Return(func(ctx workflow.Context, req SendEvents) error {
s.NotNil(req.SendEventPaymentInitiationAdjustment)
s.NotNil(req.PaymentInitiationAdjustment)
return nil
})
s.env.OnActivity(activities.PluginCreatePayoutActivity, mock.Anything, mock.Anything).Once().Return(func(ctx context.Context, req activities.CreatePayoutRequest) (*models.CreatePayoutResponse, error) {
Expand Down Expand Up @@ -371,6 +371,37 @@ func (s *UnitTestSuite) Test_CreatePayout_StoragePaymentsStore_Error() {
s.Error(err)
}

func (s *UnitTestSuite) Test_CreatePayout_RunSendEvents_Error() {
s.env.OnActivity(activities.StoragePaymentInitiationsGetActivity, mock.Anything, s.paymentInitiationID).Once().Return(&s.paymentInitiationPayout, nil)
s.env.OnActivity(activities.StorageAccountsGetActivity, mock.Anything, *s.paymentInitiationPayout.SourceAccountID).Once().Return(&s.account, nil)
s.env.OnActivity(activities.StorageAccountsGetActivity, mock.Anything, *s.paymentInitiationPayout.DestinationAccountID).Once().Return(&s.account, nil)
s.env.OnActivity(activities.StoragePaymentInitiationsAdjustmentsStoreActivity, mock.Anything, mock.Anything).Once().Return(nil)
s.env.OnWorkflow(RunSendEvents, mock.Anything, mock.Anything).Once().Return(nil)
s.env.OnActivity(activities.PluginCreatePayoutActivity, mock.Anything, mock.Anything).Once().Return(&models.CreatePayoutResponse{
Payment: &s.pspPayment,
}, nil)
s.env.OnActivity(activities.StoragePaymentsStoreActivity, mock.Anything, mock.Anything).Once().Return(nil)
s.env.OnActivity(activities.StoragePaymentInitiationsRelatedPaymentsStoreActivity, mock.Anything, mock.Anything).Once().Return(nil)
s.env.OnWorkflow(RunSendEvents, mock.Anything, mock.Anything).Once().Return(temporal.NewNonRetryableApplicationError("test", "WORKFLOW", errors.New("test")))
s.env.OnActivity(activities.StorageTasksStoreActivity, mock.Anything, mock.Anything).Once().Return(func(ctx context.Context, task models.Task) error {
s.Equal(models.TASK_STATUS_FAILED, task.Status)
return nil
})

s.env.ExecuteWorkflow(RunCreatePayout, CreatePayout{
TaskID: models.TaskID{
Reference: "test",
ConnectorID: s.connectorID,
},
ConnectorID: s.connectorID,
PaymentInitiationID: s.paymentInitiationID,
})

s.True(s.env.IsWorkflowCompleted())
err := s.env.GetWorkflowError()
s.Error(err)
}

func (s *UnitTestSuite) Test_CreatePayoutStoragePaymentInitiationsRelatedPaymentsStore_Error() {
s.env.OnActivity(activities.StoragePaymentInitiationsGetActivity, mock.Anything, s.paymentInitiationID).Once().Return(&s.paymentInitiationPayout, nil)
s.env.OnActivity(activities.StorageAccountsGetActivity, mock.Anything, *s.paymentInitiationPayout.SourceAccountID).Once().Return(&s.account, nil)
Expand Down
Loading
Loading
0