Skip to content

Commit

Permalink
fix: adapt code
Browse files Browse the repository at this point in the history
  • Loading branch information
David Ragot committed Jan 8, 2024
1 parent b4fb85c commit 4295929
Show file tree
Hide file tree
Showing 20 changed files with 95 additions and 89 deletions.
4 changes: 2 additions & 2 deletions components/fctl/cmd/payments/accounts/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
)

type ListStore struct {
Cursor *shared.AccountsCursorCursor `json:"cursor"`
Cursor *shared.Cursor `json:"cursor"`
}

type ListController struct {
Expand All @@ -26,7 +26,7 @@ var _ fctl.Controller[*ListStore] = (*ListController)(nil)

func NewListStore() *ListStore {
return &ListStore{
Cursor: &shared.AccountsCursorCursor{},
Cursor: &shared.Cursor{},
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func (c *UpdateStatusController) Run(cmd *cobra.Command, args []string) (fctl.Re
//nolint:gosimple
response, err := client.Payments.UdpateTransferInitiationStatus(cmd.Context(), operations.UdpateTransferInitiationStatusRequest{
UpdateTransferInitiationStatusRequest: shared.UpdateTransferInitiationStatusRequest{
Status: shared.UpdateTransferInitiationStatusRequestStatus(args[1]),
Status: shared.Status(args[1]),
},
TransferID: args[0],
})
Expand Down
10 changes: 4 additions & 6 deletions components/fctl/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
"github.com/formancehq/fctl/cmd/webhooks"
"github.com/formancehq/fctl/membershipclient"
fctl "github.com/formancehq/fctl/pkg"
"github.com/formancehq/formance-sdk-go/pkg/models/shared"
"github.com/formancehq/formance-sdk-go/pkg/models/sdkerrors"
"github.com/formancehq/stack/libs/go-libs/api"
"github.com/pterm/pterm"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -119,7 +119,7 @@ func extractOpenAPIErrorMessage(err error) error {
return err
}

func unwrapOpenAPIError(err error) *shared.V2ErrorResponse {
func unwrapOpenAPIError(err error) *sdkerrors.V2Error {
openapiError := &membershipclient.GenericOpenAPIError{}
if errors.As(err, &openapiError) {
body := openapiError.Body()
Expand All @@ -133,11 +133,9 @@ func unwrapOpenAPIError(err error) *shared.V2ErrorResponse {
}

if errResponse.ErrorCode != "" {
errorCode := shared.V2ErrorsEnum(errResponse.ErrorCode)
return &shared.V2ErrorResponse{
ErrorCode: errorCode,
return &sdkerrors.V2Error{
ErrorCode: sdkerrors.ErrorCode(errResponse.ErrorCode),
ErrorMessage: errResponse.ErrorMessage,
Details: &errResponse.Details,
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions components/fctl/cmd/webhooks/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ import (

fctl "github.com/formancehq/fctl/pkg"
"github.com/formancehq/formance-sdk-go/pkg/models/operations"
"github.com/formancehq/formance-sdk-go/pkg/models/shared"
"github.com/formancehq/formance-sdk-go/pkg/models/sdkerrors"
"github.com/pkg/errors"
"github.com/pterm/pterm"
"github.com/spf13/cobra"
)

type DeleteWebhookStore struct {
ErrorResponse *shared.WebhooksErrorResponse `json:"error"`
Success bool `json:"success"`
ErrorResponse *sdkerrors.WebhooksErrorResponse `json:"error"`
Success bool `json:"success"`
}

type DeleteWebhookController struct {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ type CreateTransactionWrapper struct {
// OK
CreateTransactionResponse *CreateTransactionResponse
// Error
ErrorResponse *shared.ErrorResponse
ErrorResponse *shared.Error
StatusCode int
RawResponse *http.Response
}
Expand Down
12 changes: 5 additions & 7 deletions ee/wallets/pkg/api/handler_wallets_debit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,17 @@ type testCase struct {
}

type apiErrorMock struct {
ErrorCode shared.ErrorsEnum `json:"errorCode,omitempty"`
ErrorMessage string `json:"errorMessage,omitempty"`
Details *string `json:"details,omitempty"`
ErrorCode shared.WalletsErrorResponseErrorCode `json:"errorCode,omitempty"`
ErrorMessage string `json:"errorMessage,omitempty"`
}

func (a *apiErrorMock) Model() any {
if a == nil {
return nil
}
return shared.ErrorResponse{
return shared.WalletsErrorResponse{
ErrorCode: a.ErrorCode,
ErrorMessage: a.ErrorMessage,
Details: a.Details,
}
}

Expand Down Expand Up @@ -141,7 +139,7 @@ var walletDebitTestCases = []testCase{
Amount: wallet.NewMonetary(big.NewInt(100), "USD"),
},
postTransactionError: &apiErrorMock{
ErrorCode: shared.ErrorsEnumInsufficientFund,
ErrorCode: shared.WalletsErrorResponseErrorCodeInsufficientFund,
},
expectedStatusCode: http.StatusBadRequest,
expectedErrorCode: string(shared.ErrorsEnumInsufficientFund),
Expand Down Expand Up @@ -246,7 +244,7 @@ var walletDebitTestCases = []testCase{
}
},
expectedStatusCode: http.StatusBadRequest,
expectedErrorCode: string(shared.ErrorErrorCodeValidation),
expectedErrorCode: string(shared.WalletsErrorResponseErrorCodeValidation),
},
{
name: "with custom balance as destination",
Expand Down
4 changes: 2 additions & 2 deletions ee/wallets/pkg/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,10 +288,10 @@ func (m *Manager) CreateTransaction(ctx context.Context, postTransaction PostTra
if _, err := m.client.CreateTransaction(ctx, m.ledgerName, postTransaction); err != nil {
apiErr, ok := err.(GenericOpenAPIError)
if ok {
respErr, ok := apiErr.Model().(shared.ErrorResponse)
respErr, ok := apiErr.Model().(shared.WalletsErrorResponse)
if ok {
switch respErr.ErrorCode {
case shared.ErrorsEnumInsufficientFund:
case shared.WalletsErrorResponseErrorCodeInsufficientFund:
return ErrInsufficientFundError
}
}
Expand Down
17 changes: 9 additions & 8 deletions tests/integration/suite/ledger-aggregated-balances.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package suite

import (
"math/big"
"net/http"

"github.com/formancehq/formance-sdk-go/pkg/models/operations"
"github.com/formancehq/formance-sdk-go/pkg/models/shared"
. "github.com/formancehq/stack/tests/integration/internal"
"github.com/formancehq/stack/tests/integration/internal/modules"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"math/big"
"net/http"
)

var _ = WithModules([]*Module{modules.Ledger, modules.Search}, func() {
Expand All @@ -22,7 +23,7 @@ var _ = WithModules([]*Module{modules.Ledger, modules.Search}, func() {

_, err = Client().Ledger.V2CreateBulk(TestContext(), operations.V2CreateBulkRequest{
RequestBody: []shared.V2BulkElement{
shared.CreateV2BulkElementCreateTransaction(shared.V2BulkElementV2BulkElementCreateTransaction{
shared.CreateV2BulkElementCreateTransaction(shared.V2BulkElementCreateTransaction{
Data: &shared.V2PostTransaction{
Metadata: map[string]string{},
Postings: []shared.V2Posting{{
Expand All @@ -33,7 +34,7 @@ var _ = WithModules([]*Module{modules.Ledger, modules.Search}, func() {
}},
},
}),
shared.CreateV2BulkElementCreateTransaction(shared.V2BulkElementV2BulkElementCreateTransaction{
shared.CreateV2BulkElementCreateTransaction(shared.V2BulkElementCreateTransaction{
Data: &shared.V2PostTransaction{
Metadata: map[string]string{},
Postings: []shared.V2Posting{{
Expand All @@ -44,17 +45,17 @@ var _ = WithModules([]*Module{modules.Ledger, modules.Search}, func() {
}},
},
}),
shared.CreateV2BulkElementAddMetadata(shared.V2BulkElementV2BulkElementAddMetadata{
Data: &shared.V2BulkElementV2BulkElementAddMetadataData{
shared.CreateV2BulkElementAddMetadata(shared.V2BulkElementAddMetadata{
Data: &shared.V2BulkElementAddMetadataData{
Metadata: map[string]string{
"category": "premium",
},
TargetID: shared.CreateV2TargetIDStr("bank2"),
TargetType: shared.V2TargetTypeAccount,
},
}),
shared.CreateV2BulkElementAddMetadata(shared.V2BulkElementV2BulkElementAddMetadata{
Data: &shared.V2BulkElementV2BulkElementAddMetadataData{
shared.CreateV2BulkElementAddMetadata(shared.V2BulkElementAddMetadata{
Data: &shared.V2BulkElementAddMetadataData{
Metadata: map[string]string{
"category": "premium",
},
Expand Down
27 changes: 14 additions & 13 deletions tests/integration/suite/ledger-create-bulk.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
package suite

import (
"math/big"
"net/http"
"time"

"github.com/formancehq/formance-sdk-go/pkg/models/operations"
"github.com/formancehq/formance-sdk-go/pkg/models/shared"
"github.com/formancehq/stack/libs/go-libs/metadata"
. "github.com/formancehq/stack/tests/integration/internal"
"github.com/formancehq/stack/tests/integration/internal/modules"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"math/big"
"net/http"
"time"
)

var _ = WithModules([]*Module{modules.Ledger}, func() {
Expand All @@ -28,7 +29,7 @@ var _ = WithModules([]*Module{modules.Ledger}, func() {
BeforeEach(func() {
_, err := Client().Ledger.V2CreateBulk(TestContext(), operations.V2CreateBulkRequest{
RequestBody: []shared.V2BulkElement{
shared.CreateV2BulkElementCreateTransaction(shared.V2BulkElementV2BulkElementCreateTransaction{
shared.CreateV2BulkElementCreateTransaction(shared.V2BulkElementCreateTransaction{
Data: &shared.V2PostTransaction{
Metadata: map[string]string{},
Postings: []shared.V2Posting{{
Expand All @@ -40,8 +41,8 @@ var _ = WithModules([]*Module{modules.Ledger}, func() {
Timestamp: &now,
},
}),
shared.CreateV2BulkElementAddMetadata(shared.V2BulkElementV2BulkElementAddMetadata{
Data: &shared.V2BulkElementV2BulkElementAddMetadataData{
shared.CreateV2BulkElementAddMetadata(shared.V2BulkElementAddMetadata{
Data: &shared.V2BulkElementAddMetadataData{
Metadata: metadata.Metadata{
"foo": "bar",
"role": "admin",
Expand All @@ -50,15 +51,15 @@ var _ = WithModules([]*Module{modules.Ledger}, func() {
TargetType: shared.V2TargetTypeTransaction,
},
}),
shared.CreateV2BulkElementDeleteMetadata(shared.V2BulkElementV2BulkElementDeleteMetadata{
Data: &shared.V2BulkElementV2BulkElementDeleteMetadataData{
shared.CreateV2BulkElementDeleteMetadata(shared.V2BulkElementDeleteMetadata{
Data: &shared.V2BulkElementDeleteMetadataData{
Key: "foo",
TargetID: shared.CreateV2TargetIDBigint(big.NewInt(0)),
TargetType: shared.V2TargetTypeTransaction,
},
}),
shared.CreateV2BulkElementRevertTransaction(shared.V2BulkElementV2BulkElementRevertTransaction{
Data: &shared.V2BulkElementV2BulkElementRevertTransactionData{
shared.CreateV2BulkElementRevertTransaction(shared.V2BulkElementRevertTransaction{
Data: &shared.V2BulkElementRevertTransactionData{
ID: big.NewInt(0),
},
}),
Expand Down Expand Up @@ -98,7 +99,7 @@ var _ = WithModules([]*Module{modules.Ledger}, func() {
BeforeEach(func() {
bulkResponse, err = Client().Ledger.V2CreateBulk(TestContext(), operations.V2CreateBulkRequest{
RequestBody: []shared.V2BulkElement{
shared.CreateV2BulkElementCreateTransaction(shared.V2BulkElementV2BulkElementCreateTransaction{
shared.CreateV2BulkElementCreateTransaction(shared.V2BulkElementCreateTransaction{
Data: &shared.V2PostTransaction{
Metadata: map[string]string{},
Postings: []shared.V2Posting{{
Expand All @@ -110,7 +111,7 @@ var _ = WithModules([]*Module{modules.Ledger}, func() {
Timestamp: &now,
},
}),
shared.CreateV2BulkElementCreateTransaction(shared.V2BulkElementV2BulkElementCreateTransaction{
shared.CreateV2BulkElementCreateTransaction(shared.V2BulkElementCreateTransaction{
Data: &shared.V2PostTransaction{
Metadata: map[string]string{},
Postings: []shared.V2Posting{{
Expand All @@ -129,7 +130,7 @@ var _ = WithModules([]*Module{modules.Ledger}, func() {
})
It("should respond with an error", func() {
Expect(bulkResponse.V2BulkResponse.Data[1].Type).To(Equal(shared.V2BulkElementResultType("ERROR")))
Expect(bulkResponse.V2BulkResponse.Data[1].V2BulkElementResultV2BulkElementResultError.ErrorCode).To(Equal("INSUFFICIENT_FUND"))
Expect(bulkResponse.V2BulkResponse.Data[1].V2BulkElementResultErrorSchemas.ErrorCode).To(Equal("INSUFFICIENT_FUND"))
})
})
})
31 changes: 16 additions & 15 deletions tests/integration/suite/ledger-create-transaction.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package suite

import (
"github.com/formancehq/formance-sdk-go/pkg/models/sdkerrors"
"github.com/formancehq/stack/tests/integration/internal/modules"
"math/big"
"net/http"
"time"

"github.com/formancehq/formance-sdk-go/pkg/models/sdkerrors"
"github.com/formancehq/stack/tests/integration/internal/modules"

"github.com/formancehq/formance-sdk-go/pkg/models/operations"
"github.com/formancehq/formance-sdk-go/pkg/models/shared"
ledgerevents "github.com/formancehq/ledger/pkg/events"
Expand Down Expand Up @@ -170,9 +171,9 @@ var _ = WithModules([]*Module{modules.Search, modules.Ledger}, func() {
},
)
Expect(err).To(HaveOccurred())
Expect(err.(*sdkerrors.V2ErrorResponse).ErrorCode).To(Equal(sdkerrors.V2ErrorsEnumConflict))
Expect(err.(*sdkerrors.V2ErrorResponse).ErrorCode).To(Equal(shared.V2ErrorsEnumConflict))
})
It("Should fail with "+string(sdkerrors.V2ErrorsEnumConflict)+" error code", func() {})
It("Should fail with "+string(shared.V2ErrorsEnumConflict)+" error code", func() {})
})
It("should trigger a new event", func() {
// Wait for created transaction event
Expand Down Expand Up @@ -279,7 +280,7 @@ var _ = WithModules([]*Module{modules.Search, modules.Ledger}, func() {
Expect(err).To(HaveOccurred())

Expect(err).Should(Equal(&sdkerrors.V2ErrorResponse{
ErrorCode: sdkerrors.V2ErrorsEnumInsufficientFund,
ErrorCode: shared.V2ErrorsEnumInsufficientFund,
ErrorMessage: "running numscript: script execution failed: no more fund to withdraw",
}))
})
Expand Down Expand Up @@ -347,9 +348,9 @@ var _ = WithModules([]*Module{modules.Search, modules.Ledger}, func() {
},
)
})
It("should fail with "+string(sdkerrors.V2ErrorsEnumCompilationFailed)+" code", func() {
It("should fail with "+string(shared.V2ErrorsEnumCompilationFailed)+" code", func() {
Expect(err).NotTo(Succeed())
Expect(err.(*sdkerrors.V2ErrorResponse).ErrorCode).To(Equal(sdkerrors.V2ErrorsEnumCompilationFailed))
Expect(err.(*sdkerrors.V2ErrorResponse).ErrorCode).To(Equal(shared.V2ErrorsEnumCompilationFailed))
Expect(err.(*sdkerrors.V2ErrorResponse).Details).To(Equal(pointer.For("https://play.numscript.org/?payload=eyJlcnJvciI6Ilx1MDAxYlszMW0tLVx1MDAzZVx1MDAxYlswbSBlcnJvcjoxOjE1XHJcbiAgXHUwMDFiWzM0bXxcdTAwMWJbMG1cclxuXHUwMDFiWzMxbTEgfCBcdTAwMWJbMG1cdTAwMWJbOTBtc2VuZCBbQ09JTiAtMTAwXHUwMDFiWzBtXVx1MDAxYls5MG0gKFxyXG5cdTAwMWJbMG0gIFx1MDAxYlszNG18XHUwMDFiWzBtICAgICAgICAgICAgICAgIFx1MDAxYlszMW1eXHUwMDFiWzBtIG5vIHZpYWJsZSBhbHRlcm5hdGl2ZSBhdCBpbnB1dCAnW0NPSU4tMTAwXSdcclxuIn0=")))
})
})
Expand Down Expand Up @@ -381,9 +382,9 @@ var _ = WithModules([]*Module{modules.Search, modules.Ledger}, func() {
},
)
})
It("should fail with "+string(sdkerrors.V2ErrorsEnumCompilationFailed)+" code", func() {
It("should fail with "+string(shared.V2ErrorsEnumCompilationFailed)+" code", func() {
Expect(err).NotTo(Succeed())
Expect(err.(*sdkerrors.V2ErrorResponse).ErrorCode).To(Equal(sdkerrors.V2ErrorsEnumCompilationFailed))
Expect(err.(*sdkerrors.V2ErrorResponse).ErrorCode).To(Equal(shared.V2ErrorsEnumCompilationFailed))
Expect(err.(*sdkerrors.V2ErrorResponse).Details).To(Equal(pointer.For("https://play.numscript.org/?payload=eyJlcnJvciI6ImludmFsaWQgSlNPTiB2YWx1ZSBmb3IgdmFyaWFibGUgJGFtb3VudCBvZiB0eXBlIG1vbmV0YXJ5OiB2YWx1ZSBbVVNEIC0xMDBdOiBuZWdhdGl2ZSBhbW91bnQifQ==")))
})
})
Expand All @@ -407,9 +408,9 @@ var _ = WithModules([]*Module{modules.Search, modules.Ledger}, func() {
},
)
})
It("should fail with "+string(sdkerrors.V2ErrorsEnumCompilationFailed)+" code", func() {
It("should fail with "+string(shared.V2ErrorsEnumCompilationFailed)+" code", func() {
Expect(err).NotTo(Succeed())
Expect(err.(*sdkerrors.V2ErrorResponse).ErrorCode).To(Equal(sdkerrors.V2ErrorsEnumCompilationFailed))
Expect(err.(*sdkerrors.V2ErrorResponse).ErrorCode).To(Equal(shared.V2ErrorsEnumCompilationFailed))
Expect(err.(*sdkerrors.V2ErrorResponse).Details).To(Equal(pointer.For("https://play.numscript.org/?payload=eyJlcnJvciI6Ilx1MDAxYlszMW0tLVx1MDAzZVx1MDAxYlswbSBlcnJvcjoxOjBcclxuICBcdTAwMWJbMzRtfFx1MDAxYlswbVxyXG5cdTAwMWJbMzFtMSB8IFx1MDAxYlswbVx1MDAxYls5MG1cdTAwMWJbMG1YWFhcdTAwMWJbOTBtXHJcblx1MDAxYlswbSAgXHUwMDFiWzM0bXxcdTAwMWJbMG0gXHUwMDFiWzMxbV5eXHUwMDFiWzBtIG1pc21hdGNoZWQgaW5wdXQgJ1hYWCcgZXhwZWN0aW5nIHtORVdMSU5FLCAndmFycycsICdzZXRfdHhfbWV0YScsICdzZXRfYWNjb3VudF9tZXRhJywgJ3ByaW50JywgJ2ZhaWwnLCAnc2VuZCcsICdzYXZlJ31cclxuIn0=")))
})
})
Expand Down Expand Up @@ -439,9 +440,9 @@ var _ = WithModules([]*Module{modules.Search, modules.Ledger}, func() {
},
)
})
It("should fail with "+string(sdkerrors.V2ErrorsEnumNoPostings)+" code", func() {
It("should fail with "+string(shared.V2ErrorsEnumNoPostings)+" code", func() {
Expect(err).NotTo(Succeed())
Expect(err.(*sdkerrors.V2ErrorResponse).ErrorCode).To(Equal(sdkerrors.V2ErrorsEnumNoPostings))
Expect(err.(*sdkerrors.V2ErrorResponse).ErrorCode).To(Equal(shared.V2ErrorsEnumNoPostings))
})
})
When("creating a transaction with metadata override", func() {
Expand Down Expand Up @@ -470,9 +471,9 @@ var _ = WithModules([]*Module{modules.Search, modules.Ledger}, func() {
},
)
})
It("should fail with "+string(sdkerrors.V2ErrorsEnumMetadataOverride)+" code", func() {
It("should fail with "+string(shared.V2ErrorsEnumMetadataOverride)+" code", func() {
Expect(err).NotTo(Succeed())
Expect(err.(*sdkerrors.V2ErrorResponse).ErrorCode).To(Equal(sdkerrors.V2ErrorsEnumMetadataOverride))
Expect(err.(*sdkerrors.V2ErrorResponse).ErrorCode).To(Equal(shared.V2ErrorsEnumMetadataOverride))
})
})
})
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/suite/ledger-create.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ var _ = WithModules([]*Module{modules.Ledger}, func() {
Ledger: "default",
})
Expect(err).NotTo(BeNil())
Expect(err.(*sdkerrors.V2ErrorResponse).ErrorCode).To(Equal(sdkerrors.V2ErrorsEnumValidation))
Expect(err.(*sdkerrors.V2ErrorResponse).ErrorCode).To(Equal(shared.V2ErrorsEnumValidation))
})
It("should fail", func() {})
})
Expand Down
Loading

0 comments on commit 4295929

Please sign in to comment.