Skip to content

Commit

Permalink
fix: priority handling
Browse files Browse the repository at this point in the history
  • Loading branch information
gfyrag committed Jan 20, 2025
1 parent 63ad893 commit b367fae
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 0 deletions.
1 change: 1 addition & 0 deletions Justfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ generate:
tests:
@go test -race -covermode=atomic \
-coverprofile coverage.txt \
-tags it \
./...

generate-client:
Expand Down
1 change: 1 addition & 0 deletions pkg/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,7 @@ func (m *Manager) CreateBalance(ctx context.Context, data *CreateBalance) (*Bala
}

balance := NewBalance(data.Name, data.ExpiresAt)
balance.Priority = data.Priority

if err := m.client.AddMetadataToAccount(
ctx,
Expand Down
94 changes: 94 additions & 0 deletions test/e2e/balances_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
//go:build it

package suite_test

import (
"github.com/formancehq/go-libs/v2/logging"
"github.com/formancehq/go-libs/v2/pointer"
"github.com/formancehq/wallets/pkg/client/models/components"
"github.com/formancehq/wallets/pkg/client/models/operations"
"github.com/formancehq/wallets/pkg/testserver"
"github.com/google/uuid"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"math/big"
)

var _ = Context("Wallets - balances", func() {

var (
srv *testserver.Server
ctx = logging.TestingContext()
)
BeforeEach(func() {
srv = testserver.New(GinkgoT(), testserver.Configuration{
Output: GinkgoWriter,
Debug: debug,
StackURL: stackURL.GetValue(),
})
})

When("creating a wallet", func() {
var (
createWalletResponse *operations.CreateWalletResponse
err error
)
BeforeEach(func() {
createWalletResponse, err = srv.Client().Wallets.V1.CreateWallet(
ctx,
operations.CreateWalletRequest{
CreateWalletRequest: &components.CreateWalletRequest{
Name: uuid.NewString(),
Metadata: map[string]string{},
},
},
)
Expect(err).ToNot(HaveOccurred())
})
When("creating a new balance", func() {
var (
createBalanceResponse *operations.CreateBalanceResponse
err error
)
BeforeEach(func() {
createBalanceResponse, err = srv.Client().Wallets.V1.CreateBalance(ctx, operations.CreateBalanceRequest{
CreateBalanceRequest: &components.CreateBalanceRequest{
Name: "balance1",
Priority: big.NewInt(10),
},
ID: createWalletResponse.CreateWalletResponse.Data.ID,
IdempotencyKey: pointer.For("foo"),
})
Expect(err).To(Succeed())
})
It("should be ok", func() {
Expect(createBalanceResponse.CreateBalanceResponse.Data.Name).To(Equal("balance1"))
Expect(createBalanceResponse.CreateBalanceResponse.Data.Priority).To(Equal(big.NewInt(10)))
})
When("listing balances", func() {
var (
listBalancesResponse *operations.ListBalancesResponse
)
BeforeEach(func() {
listBalancesResponse, err = srv.Client().Wallets.V1.ListBalances(ctx, operations.ListBalancesRequest{
ID: createWalletResponse.CreateWalletResponse.Data.ID,
})
Expect(err).ToNot(HaveOccurred())
})
It("should return created balance", func() {
Expect(listBalancesResponse.ListBalancesResponse.Cursor.Data).To(HaveLen(2))
Expect(listBalancesResponse.ListBalancesResponse.Cursor.Data).To(ContainElements(
components.Balance{
Name: "balance1",
Priority: big.NewInt(10),
},
components.Balance{
Name: "main",
Priority: big.NewInt(0),
},
))
})
})
})
})
})

0 comments on commit b367fae

Please sign in to comment.