Total Lines | 51 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | package flutterwave |
||
2 | |||
3 | import ( |
||
4 | "context" |
||
5 | "github.com/NdoleStudio/flutterwave-go/internal/helpers" |
||
6 | "github.com/NdoleStudio/flutterwave-go/internal/stubs" |
||
7 | "github.com/stretchr/testify/assert" |
||
8 | "net/http" |
||
9 | "testing" |
||
10 | ) |
||
11 | |||
12 | func TestTransactionsService_Refund(t *testing.T) { |
||
13 | // Setup |
||
14 | t.Parallel() |
||
15 | |||
16 | // Arrange |
||
17 | server := helpers.MakeTestServer(http.StatusOK, string(stubs.TransactionRefundResponse())) |
||
18 | client := New(WithBaseURL(server.URL)) |
||
19 | |||
20 | // Act |
||
21 | refund, response, err := client.Transactions.Refund(context.Background(), 123, 200) |
||
22 | |||
23 | // Assert |
||
24 | assert.Nil(t, err) |
||
25 | |||
26 | assert.Equal(t, http.StatusOK, response.HTTPResponse.StatusCode) |
||
27 | assert.Equal(t, stubs.TransactionRefundResponse(), *response.Body) |
||
28 | assert.Equal(t, 75923, refund.Data.ID) |
||
29 | |||
30 | // Teardown |
||
31 | server.Close() |
||
32 | } |
||
33 | |||
34 | func TestTransactionsService_RefundWithError(t *testing.T) { |
||
35 | // Setup |
||
36 | t.Parallel() |
||
37 | |||
38 | // Arrange |
||
39 | server := helpers.MakeTestServer(http.StatusInternalServerError, "") |
||
40 | client := New(WithBaseURL(server.URL)) |
||
41 | |||
42 | // Act |
||
43 | _, response, err := client.Transactions.Refund(context.Background(), 123, 200) |
||
44 | |||
45 | // Assert |
||
46 | assert.NotNil(t, err) |
||
47 | |||
48 | assert.Equal(t, http.StatusInternalServerError, response.HTTPResponse.StatusCode) |
||
49 | |||
50 | // Teardown |
||
51 | server.Close() |
||
52 | } |
||
53 |