Skip to content

Commit

Permalink
fix time test storage
Browse files Browse the repository at this point in the history
  • Loading branch information
paul-nicolas committed Sep 24, 2024
1 parent 665383a commit 4327aeb
Show file tree
Hide file tree
Showing 8 changed files with 130 additions and 130 deletions.
14 changes: 7 additions & 7 deletions components/payments/internal/storage/accounts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ package storage
import (
"context"
"testing"
"time"

"github.com/formancehq/go-libs/bun/bunpaginate"
"github.com/formancehq/go-libs/logging"
"github.com/formancehq/go-libs/pointer"
"github.com/formancehq/go-libs/query"
"github.com/formancehq/go-libs/time"
"github.com/formancehq/payments/internal/models"
"github.com/google/uuid"
"github.com/stretchr/testify/require"
Expand All @@ -23,7 +23,7 @@ var (
},
ConnectorID: defaultConnector.ID,
Reference: "test1",
CreatedAt: now.Add(-60 * time.Minute).UTC(),
CreatedAt: now.Add(-60 * time.Minute).UTC().Time,
Type: models.ACCOUNT_TYPE_INTERNAL,
Name: pointer.For("test1"),
DefaultAsset: pointer.For("USD/2"),
Expand All @@ -39,7 +39,7 @@ var (
},
ConnectorID: defaultConnector.ID,
Reference: "test2",
CreatedAt: now.Add(-30 * time.Minute).UTC(),
CreatedAt: now.Add(-30 * time.Minute).UTC().Time,
Type: models.ACCOUNT_TYPE_INTERNAL,
Metadata: map[string]string{
"foo2": "bar2",
Expand All @@ -53,7 +53,7 @@ var (
},
ConnectorID: defaultConnector.ID,
Reference: "test3",
CreatedAt: now.Add(-45 * time.Minute).UTC(),
CreatedAt: now.Add(-45 * time.Minute).UTC().Time,
Type: models.ACCOUNT_TYPE_EXTERNAL,
Name: pointer.For("test3"),
Metadata: map[string]string{
Expand All @@ -71,7 +71,7 @@ var (
},
ConnectorID: defaultConnector2.ID,
Reference: "test1",
CreatedAt: now.Add(-55 * time.Minute).UTC(),
CreatedAt: now.Add(-55 * time.Minute).UTC().Time,
Type: models.ACCOUNT_TYPE_INTERNAL,
Name: pointer.For("test1"),
DefaultAsset: pointer.For("USD/2"),
Expand Down Expand Up @@ -110,7 +110,7 @@ func TestAccountsUpsert(t *testing.T) {
ID: id,
ConnectorID: defaultConnector.ID,
Reference: "test1",
CreatedAt: now.Add(-12 * time.Minute),
CreatedAt: now.Add(-12 * time.Minute).UTC().Time,
Type: models.ACCOUNT_TYPE_EXTERNAL,
Name: pointer.For("changed"),
DefaultAsset: pointer.For("EUR"),
Expand Down Expand Up @@ -145,7 +145,7 @@ func TestAccountsUpsert(t *testing.T) {
},
ConnectorID: unknownConnectorID,
Reference: "test_unknown",
CreatedAt: now.Add(-12 * time.Minute),
CreatedAt: now.Add(-12 * time.Minute).UTC().Time,
Type: models.ACCOUNT_TYPE_EXTERNAL,
Name: pointer.For("changed"),
DefaultAsset: pointer.For("EUR"),
Expand Down
114 changes: 57 additions & 57 deletions components/payments/internal/storage/balances_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import (
"context"
"math/big"
"testing"
"time"

"github.com/formancehq/go-libs/bun/bunpaginate"
"github.com/formancehq/go-libs/logging"
"github.com/formancehq/go-libs/pointer"
"github.com/formancehq/go-libs/time"
"github.com/formancehq/payments/internal/models"
"github.com/google/uuid"
"github.com/stretchr/testify/require"
Expand All @@ -18,22 +18,22 @@ var (
defaultBalances = []models.Balance{
{
AccountID: defaultAccounts[0].ID,
CreatedAt: now.Add(-60 * time.Minute).UTC(),
LastUpdatedAt: now.Add(-60 * time.Minute).UTC(),
CreatedAt: now.Add(-60 * time.Minute).UTC().Time,
LastUpdatedAt: now.Add(-60 * time.Minute).UTC().Time,
Asset: "USD/2",
Balance: big.NewInt(100),
},
{
AccountID: defaultAccounts[1].ID,
CreatedAt: now.Add(-30 * time.Minute).UTC(),
LastUpdatedAt: now.Add(-30 * time.Minute).UTC(),
CreatedAt: now.Add(-30 * time.Minute).UTC().Time,
LastUpdatedAt: now.Add(-30 * time.Minute).UTC().Time,
Asset: "EUR/2",
Balance: big.NewInt(1000),
},
{
AccountID: defaultAccounts[0].ID,
CreatedAt: now.Add(-55 * time.Minute).UTC(),
LastUpdatedAt: now.Add(-55 * time.Minute).UTC(),
CreatedAt: now.Add(-55 * time.Minute).UTC().Time,
LastUpdatedAt: now.Add(-55 * time.Minute).UTC().Time,
Asset: "EUR/2",
Balance: big.NewInt(150),
},
Expand All @@ -42,15 +42,15 @@ var (
defaultBalances2 = []models.Balance{
{
AccountID: defaultAccounts[2].ID,
CreatedAt: now.Add(-59 * time.Minute).UTC(),
LastUpdatedAt: now.Add(-59 * time.Minute).UTC(),
CreatedAt: now.Add(-59 * time.Minute).UTC().Time,
LastUpdatedAt: now.Add(-59 * time.Minute).UTC().Time,
Asset: "USD/2",
Balance: big.NewInt(100),
},
{
AccountID: defaultAccounts[2].ID,
CreatedAt: now.Add(-31 * time.Minute).UTC(),
LastUpdatedAt: now.Add(-31 * time.Minute).UTC(),
CreatedAt: now.Add(-31 * time.Minute).UTC().Time,
LastUpdatedAt: now.Add(-31 * time.Minute).UTC().Time,
Asset: "DKK/2",
Balance: big.NewInt(1000),
},
Expand All @@ -77,8 +77,8 @@ func TestBalancesUpsert(t *testing.T) {

b := models.Balance{
AccountID: defaultAccounts[2].ID,
CreatedAt: now.Add(-20 * time.Minute).UTC(),
LastUpdatedAt: now.Add(-20 * time.Minute).UTC(),
CreatedAt: now.Add(-20 * time.Minute).UTC().Time,
LastUpdatedAt: now.Add(-20 * time.Minute).UTC().Time,
Asset: "USD/2",
Balance: big.NewInt(100),
}
Expand All @@ -95,8 +95,8 @@ func TestBalancesUpsert(t *testing.T) {
expectedBalances := []models.Balance{
{
AccountID: defaultAccounts[2].ID,
CreatedAt: now.Add(-59 * time.Minute).UTC(),
LastUpdatedAt: now.Add(-20 * time.Minute).UTC(),
CreatedAt: now.Add(-59 * time.Minute).UTC().Time,
LastUpdatedAt: now.Add(-20 * time.Minute).UTC().Time,
Asset: "USD/2",
Balance: big.NewInt(100),
},
Expand All @@ -113,8 +113,8 @@ func TestBalancesUpsert(t *testing.T) {

b := models.Balance{
AccountID: defaultAccounts[0].ID,
CreatedAt: now.Add(-20 * time.Minute).UTC(),
LastUpdatedAt: now.Add(-20 * time.Minute).UTC(),
CreatedAt: now.Add(-20 * time.Minute).UTC().Time,
LastUpdatedAt: now.Add(-20 * time.Minute).UTC().Time,
Asset: "USD/2",
Balance: big.NewInt(200),
}
Expand All @@ -130,15 +130,15 @@ func TestBalancesUpsert(t *testing.T) {
expectedBalances := []models.Balance{
{
AccountID: defaultAccounts[0].ID,
CreatedAt: now.Add(-20 * time.Minute).UTC(),
LastUpdatedAt: now.Add(-20 * time.Minute).UTC(),
CreatedAt: now.Add(-20 * time.Minute).UTC().Time,
LastUpdatedAt: now.Add(-20 * time.Minute).UTC().Time,
Asset: "USD/2",
Balance: big.NewInt(200),
},
{
AccountID: defaultAccounts[0].ID,
CreatedAt: now.Add(-60 * time.Minute).UTC(),
LastUpdatedAt: now.Add(-20 * time.Minute).UTC(),
CreatedAt: now.Add(-60 * time.Minute).UTC().Time,
LastUpdatedAt: now.Add(-20 * time.Minute).UTC().Time,
Asset: "USD/2",
Balance: big.NewInt(100),
},
Expand All @@ -155,8 +155,8 @@ func TestBalancesUpsert(t *testing.T) {

b := models.Balance{
AccountID: defaultAccounts[0].ID,
CreatedAt: now.Add(-10 * time.Minute).UTC(),
LastUpdatedAt: now.Add(-10 * time.Minute).UTC(),
CreatedAt: now.Add(-10 * time.Minute).UTC().Time,
LastUpdatedAt: now.Add(-10 * time.Minute).UTC().Time,
Asset: "DKK/2",
Balance: big.NewInt(200),
}
Expand All @@ -172,22 +172,22 @@ func TestBalancesUpsert(t *testing.T) {
expectedBalances := []models.Balance{
{
AccountID: defaultAccounts[0].ID,
CreatedAt: now.Add(-10 * time.Minute).UTC(),
LastUpdatedAt: now.Add(-10 * time.Minute).UTC(),
CreatedAt: now.Add(-10 * time.Minute).UTC().Time,
LastUpdatedAt: now.Add(-10 * time.Minute).UTC().Time,
Asset: "DKK/2",
Balance: big.NewInt(200),
},
{
AccountID: defaultAccounts[0].ID,
CreatedAt: now.Add(-55 * time.Minute).UTC(),
LastUpdatedAt: now.Add(-55 * time.Minute).UTC(),
CreatedAt: now.Add(-55 * time.Minute).UTC().Time,
LastUpdatedAt: now.Add(-55 * time.Minute).UTC().Time,
Asset: "EUR/2",
Balance: big.NewInt(150),
},
{
AccountID: defaultAccounts[0].ID,
CreatedAt: now.Add(-60 * time.Minute).UTC(),
LastUpdatedAt: now.Add(-60 * time.Minute).UTC(),
CreatedAt: now.Add(-60 * time.Minute).UTC().Time,
LastUpdatedAt: now.Add(-60 * time.Minute).UTC().Time,
Asset: "USD/2",
Balance: big.NewInt(100),
},
Expand Down Expand Up @@ -258,15 +258,15 @@ func TestBalancesList(t *testing.T) {
expectedBalances := []models.Balance{
{
AccountID: defaultAccounts[0].ID,
CreatedAt: now.Add(-55 * time.Minute).UTC(),
LastUpdatedAt: now.Add(-55 * time.Minute).UTC(),
CreatedAt: now.Add(-55 * time.Minute).UTC().Time,
LastUpdatedAt: now.Add(-55 * time.Minute).UTC().Time,
Asset: "EUR/2",
Balance: big.NewInt(150),
},
{
AccountID: defaultAccounts[0].ID,
CreatedAt: now.Add(-60 * time.Minute).UTC(),
LastUpdatedAt: now.Add(-60 * time.Minute).UTC(),
CreatedAt: now.Add(-60 * time.Minute).UTC().Time,
LastUpdatedAt: now.Add(-60 * time.Minute).UTC().Time,
Asset: "USD/2",
Balance: big.NewInt(100),
},
Expand All @@ -291,15 +291,15 @@ func TestBalancesList(t *testing.T) {
expectedBalances := []models.Balance{
{
AccountID: defaultAccounts[2].ID,
CreatedAt: now.Add(-59 * time.Minute).UTC(),
LastUpdatedAt: now.Add(-59 * time.Minute).UTC(),
CreatedAt: now.Add(-59 * time.Minute).UTC().Time,
LastUpdatedAt: now.Add(-59 * time.Minute).UTC().Time,
Asset: "USD/2",
Balance: big.NewInt(100),
},
{
AccountID: defaultAccounts[0].ID,
CreatedAt: now.Add(-60 * time.Minute).UTC(),
LastUpdatedAt: now.Add(-60 * time.Minute).UTC(),
CreatedAt: now.Add(-60 * time.Minute).UTC().Time,
LastUpdatedAt: now.Add(-60 * time.Minute).UTC().Time,
Asset: "USD/2",
Balance: big.NewInt(100),
},
Expand All @@ -324,8 +324,8 @@ func TestBalancesList(t *testing.T) {
expectedBalances := []models.Balance{
{
AccountID: defaultAccounts[2].ID,
CreatedAt: now.Add(-30 * time.Minute).UTC(),
LastUpdatedAt: now.Add(-30 * time.Minute).UTC(),
CreatedAt: now.Add(-30 * time.Minute).UTC().Time,
LastUpdatedAt: now.Add(-30 * time.Minute).UTC().Time,
Asset: "DKK/2",
Balance: big.NewInt(1000),
},
Expand All @@ -343,22 +343,22 @@ func TestBalancesList(t *testing.T) {

q := NewListBalancesQuery(
bunpaginate.NewPaginatedQueryOptions(BalanceQuery{
From: now.Add(-40 * time.Minute),
From: now.Add(-40 * time.Minute).UTC().Time,
}).WithPageSize(15),
)

expectedBalances := []models.Balance{
{
AccountID: defaultAccounts[1].ID,
CreatedAt: now.Add(-30 * time.Minute).UTC(),
LastUpdatedAt: now.Add(-30 * time.Minute).UTC(),
CreatedAt: now.Add(-30 * time.Minute).UTC().Time,
LastUpdatedAt: now.Add(-30 * time.Minute).UTC().Time,
Asset: "EUR/2",
Balance: big.NewInt(1000),
},
{
AccountID: defaultAccounts[2].ID,
CreatedAt: now.Add(-31 * time.Minute).UTC(),
LastUpdatedAt: now.Add(-31 * time.Minute).UTC(),
CreatedAt: now.Add(-31 * time.Minute).UTC().Time,
LastUpdatedAt: now.Add(-31 * time.Minute).UTC().Time,
Asset: "DKK/2",
Balance: big.NewInt(1000),
},
Expand All @@ -376,7 +376,7 @@ func TestBalancesList(t *testing.T) {

q := NewListBalancesQuery(
bunpaginate.NewPaginatedQueryOptions(BalanceQuery{
From: now.Add(-20 * time.Minute),
From: now.Add(-20 * time.Minute).UTC().Time,
}).WithPageSize(15),
)

Expand All @@ -391,29 +391,29 @@ func TestBalancesList(t *testing.T) {

q := NewListBalancesQuery(
bunpaginate.NewPaginatedQueryOptions(BalanceQuery{
To: now.Add(-40 * time.Minute),
To: now.Add(-40 * time.Minute).UTC().Time,
}).WithPageSize(15),
)

expectedBalances := []models.Balance{
{
AccountID: defaultAccounts[0].ID,
CreatedAt: now.Add(-55 * time.Minute).UTC(),
LastUpdatedAt: now.Add(-55 * time.Minute).UTC(),
CreatedAt: now.Add(-55 * time.Minute).UTC().Time,
LastUpdatedAt: now.Add(-55 * time.Minute).UTC().Time,
Asset: "EUR/2",
Balance: big.NewInt(150),
},
{
AccountID: defaultAccounts[2].ID,
CreatedAt: now.Add(-59 * time.Minute).UTC(),
LastUpdatedAt: now.Add(-59 * time.Minute).UTC(),
CreatedAt: now.Add(-59 * time.Minute).UTC().Time,
LastUpdatedAt: now.Add(-59 * time.Minute).UTC().Time,
Asset: "USD/2",
Balance: big.NewInt(100),
},
{
AccountID: defaultAccounts[0].ID,
CreatedAt: now.Add(-60 * time.Minute).UTC(),
LastUpdatedAt: now.Add(-60 * time.Minute).UTC(),
CreatedAt: now.Add(-60 * time.Minute).UTC().Time,
LastUpdatedAt: now.Add(-60 * time.Minute).UTC().Time,
Asset: "USD/2",
Balance: big.NewInt(100),
},
Expand All @@ -431,7 +431,7 @@ func TestBalancesList(t *testing.T) {

q := NewListBalancesQuery(
bunpaginate.NewPaginatedQueryOptions(BalanceQuery{
To: now.Add(-70 * time.Minute),
To: now.Add(-70 * time.Minute).UTC().Time,
}).WithPageSize(15),
)

Expand All @@ -453,8 +453,8 @@ func TestBalancesList(t *testing.T) {
expectedBalances1 := []models.Balance{
{
AccountID: defaultAccounts[0].ID,
CreatedAt: now.Add(-55 * time.Minute).UTC(),
LastUpdatedAt: now.Add(-55 * time.Minute).UTC(),
CreatedAt: now.Add(-55 * time.Minute).UTC().Time,
LastUpdatedAt: now.Add(-55 * time.Minute).UTC().Time,
Asset: "EUR/2",
Balance: big.NewInt(150),
},
Expand All @@ -471,8 +471,8 @@ func TestBalancesList(t *testing.T) {
expectedBalances2 := []models.Balance{
{
AccountID: defaultAccounts[0].ID,
CreatedAt: now.Add(-60 * time.Minute).UTC(),
LastUpdatedAt: now.Add(-60 * time.Minute).UTC(),
CreatedAt: now.Add(-60 * time.Minute).UTC().Time,
LastUpdatedAt: now.Add(-60 * time.Minute).UTC().Time,
Asset: "USD/2",
Balance: big.NewInt(100),
},
Expand Down
Loading

0 comments on commit 4327aeb

Please sign in to comment.