Skip to content

Commit

Permalink
fix after review
Browse files Browse the repository at this point in the history
  • Loading branch information
paul-nicolas committed Sep 26, 2024
1 parent 8861170 commit 36aae93
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
4 changes: 3 additions & 1 deletion components/payments/internal/storage/balances_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func TestBalancesUpsert(t *testing.T) {
{
AccountID: defaultAccounts[2].ID,
CreatedAt: now.Add(-59 * time.Minute).UTC().Time,
LastUpdatedAt: now.Add(-20 * time.Minute).UTC().Time,
LastUpdatedAt: now.Add(-20 * time.Minute).UTC().Time, // Last updated at should be updated to the new balance value
Asset: "USD/2",
Balance: big.NewInt(100),
},
Expand Down Expand Up @@ -125,13 +125,15 @@ func TestBalancesUpsert(t *testing.T) {
)

expectedBalances := []models.Balance{
// We should have one more balance with the new balance value
{
AccountID: defaultAccounts[0].ID,
CreatedAt: now.Add(-20 * time.Minute).UTC().Time,
LastUpdatedAt: now.Add(-20 * time.Minute).UTC().Time,
Asset: "USD/2",
Balance: big.NewInt(200),
},
// and the old balance should have its updated at to the new balance created at
{
AccountID: defaultAccounts[0].ID,
CreatedAt: now.Add(-60 * time.Minute).UTC().Time,
Expand Down
12 changes: 8 additions & 4 deletions components/payments/internal/storage/bank_accounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,22 @@ func (s *store) BankAccountsUpsert(ctx context.Context, ba models.BankAccount) e

toInsert := fromBankAccountModels(ba)
// Insert or update the bank account
var idsUpdated []uuid.UUID
err = tx.NewInsert().
res, err := tx.NewInsert().
Model(&toInsert).
Column("id", "created_at", "name", "country", "metadata").
On("CONFLICT (id) DO NOTHING").
Returning("id").
Scan(ctx, &idsUpdated)
Exec(ctx)
if err != nil {
return e("insert bank account", err)
}

rowsAffected, err := res.RowsAffected()
if err != nil {
return e("insert bank account", err)
}

if len(idsUpdated) > 0 {
if rowsAffected > 0 {
_, err = tx.NewUpdate().
Model((*bankAccount)(nil)).
Set("account_number = pgp_sym_encrypt(?::TEXT, ?, ?)", toInsert.AccountNumber, s.configEncryptionKey, encryptionOptions).
Expand Down
9 changes: 2 additions & 7 deletions components/payments/internal/storage/payments_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,13 +229,8 @@ func TestPaymentsUpsert(t *testing.T) {
p := models.Payment{
ID: pID1,
ConnectorID: defaultConnector.ID,
Reference: "test1",
CreatedAt: now.Add(-20 * time.Minute).UTC().Time,
Type: models.PAYMENT_TYPE_TRANSFER,
InitialAmount: big.NewInt(100),
Amount: big.NewInt(100),
Asset: "USD/2",
Scheme: models.PAYMENT_SCHEME_OTHER,
InitialAmount: big.NewInt(0),
Amount: big.NewInt(0),
Adjustments: []models.PaymentAdjustment{
{
ID: models.PaymentAdjustmentID{
Expand Down

0 comments on commit 36aae93

Please sign in to comment.