From dcc69edafa227793caa0f2200472344cff2a0d09 Mon Sep 17 00:00:00 2001 From: yarex-4chain Date: Thu, 29 Aug 2024 18:59:03 +0200 Subject: [PATCH] feat(SPV-904): fix transactions test --- config.go | 8 ++++---- transactions_test.go | 28 ++++++++++++++++------------ 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/config.go b/config.go index cde6aeb..cbd07d4 100644 --- a/config.go +++ b/config.go @@ -1,6 +1,6 @@ package walletclient -import "github.com/bitcoin-sv/spv-wallet/models" +import "github.com/bitcoin-sv/spv-wallet/models/response" // TransportType the type of transport being used ('http' for usage or 'mock' for testing) type TransportType string @@ -18,9 +18,9 @@ const ( // Recipients is a struct for recipients type Recipients struct { - OpReturn *models.OpReturn `json:"op_return"` - Satoshis uint64 `json:"satoshis"` - To string `json:"to"` + OpReturn *response.OpReturn `json:"opReturn"` + Satoshis uint64 `json:"satoshis"` + To string `json:"to"` } const ( diff --git a/transactions_test.go b/transactions_test.go index f359cce..f4066f1 100644 --- a/transactions_test.go +++ b/transactions_test.go @@ -8,26 +8,30 @@ import ( "testing" "github.com/bitcoin-sv/spv-wallet-go-client/fixtures" - "github.com/bitcoin-sv/spv-wallet/models" "github.com/bitcoin-sv/spv-wallet/models/filter" + "github.com/bitcoin-sv/spv-wallet/models/response" "github.com/stretchr/testify/require" ) func TestTransactions(t *testing.T) { server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { switch r.URL.Path { - case "/v1/transaction": - handleTransaction(w, r) - case "/v1/transaction/search": - json.NewEncoder(w).Encode([]*models.Transaction{fixtures.Transaction}) - case "/v1/transaction/count": - json.NewEncoder(w).Encode(1) - case "/v1/transaction/record": - if r.Method == http.MethodPost { + case "/v1/transactions": + switch r.Method { + case http.MethodGet: + json.NewEncoder(w).Encode([]*response.Transaction{fixtures.Transaction}) + case http.MethodPost: w.Header().Set("Content-Type", "application/json") json.NewEncoder(w).Encode(fixtures.Transaction) - } else { - w.WriteHeader(http.StatusMethodNotAllowed) + } + case "/v1/transactions/" + fixtures.Transaction.ID: + switch r.Method { + case http.MethodGet, http.MethodPatch: + handleTransaction(w, r) + } + case "/v1/transactions/drafts": + if r.Method == http.MethodPost { + handleTransaction(w, r) } default: w.WriteHeader(http.StatusNotFound) @@ -51,7 +55,7 @@ func TestTransactions(t *testing.T) { } txs, err := client.GetTransactions(context.Background(), conditions, fixtures.TestMetadata, nil) require.NoError(t, err) - require.Equal(t, []*models.Transaction{fixtures.Transaction}, txs) + require.Equal(t, []*response.Transaction{fixtures.Transaction}, txs) }) t.Run("GetTransactionsCount", func(t *testing.T) {