Skip to content

Commit

Permalink
test: no req
Browse files Browse the repository at this point in the history
  • Loading branch information
brokeyourbike committed Oct 7, 2023
1 parent 6b4fc92 commit a78dda6
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
14 changes: 14 additions & 0 deletions fx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package clearbank_test
import (
"bytes"
"context"
"errors"
"io"
"net/http"
"testing"
Expand All @@ -26,3 +27,16 @@ func TestInitiateFxOrder(t *testing.T) {

assert.NoError(t, client.InitiateFxOrder(ctx, clearbank.FXPayload{}))
}

func TestInitiateFxOrder_FailedHttpRequest(t *testing.T) {
mockSigner := signature.NewMockSigner(t)
mockHttpClient := clearbank.NewMockHttpClient(t)
client := clearbank.NewClient("token", mockSigner, clearbank.WithHTTPClient(mockHttpClient))

ctx := clearbank.RequestIdContext(context.TODO(), "123")
mockSigner.On("Sign", ctx, mock.Anything).Return([]byte("signed"), nil).Once()

mockHttpClient.On("Do", mock.AnythingOfType("*http.Request")).Return(nil, errors.New("cannot do")).Once()

assert.Error(t, client.InitiateFxOrder(ctx, clearbank.FXPayload{}))
}
6 changes: 2 additions & 4 deletions rate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@ func TestFetchMarketrate_Fail(t *testing.T) {
func TestFetchMarketrate_FailedHttpRequest(t *testing.T) {
mockHttpClient := clearbank.NewMockHttpClient(t)
client := clearbank.NewClient("token", nil, clearbank.WithHTTPClient(mockHttpClient))

mockHttpClient.On("Do", mock.AnythingOfType("*http.Request")).Return(&http.Response{}, errors.New("cannot do")).Once()
mockHttpClient.On("Do", mock.AnythingOfType("*http.Request")).Return(nil, errors.New("cannot do")).Once()

_, err := client.FetchMarketrate(context.TODO(), clearbank.MarketrateParams{FixedSide: clearbank.FixedSideBuy})
assert.Error(t, err)
Expand Down Expand Up @@ -91,8 +90,7 @@ func TestNegotiate_ValidationFailed(t *testing.T) {
func TestNegotiate_FailedHttpRequest(t *testing.T) {
mockHttpClient := clearbank.NewMockHttpClient(t)
client := clearbank.NewClient("token", nil, clearbank.WithHTTPClient(mockHttpClient))

mockHttpClient.On("Do", mock.AnythingOfType("*http.Request")).Return(&http.Response{}, errors.New("cannot do")).Once()
mockHttpClient.On("Do", mock.AnythingOfType("*http.Request")).Return(nil, errors.New("cannot do")).Once()

_, err := client.Negotiate(context.TODO())
assert.Error(t, err)
Expand Down
3 changes: 1 addition & 2 deletions test_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ func TestTest(t *testing.T) {
func TestFailedHttpRequest(t *testing.T) {
mockHttpClient := clearbank.NewMockHttpClient(t)
client := clearbank.NewClient("token", local.NewNilSigner(), clearbank.WithHTTPClient(mockHttpClient))

mockHttpClient.On("Do", mock.AnythingOfType("*http.Request")).Return(&http.Response{}, errors.New("cannot do")).Once()
mockHttpClient.On("Do", mock.AnythingOfType("*http.Request")).Return(nil, errors.New("cannot do")).Once()

assert.Error(t, client.Test(context.TODO(), "hello!"))
}
Expand Down

0 comments on commit a78dda6

Please sign in to comment.