Passed
Push — main ( 4001cc...ce495e )
by Acho
02:18
created

Service_RefundWithError   A

Complexity

Conditions 1

Size

Total Lines 18
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 8
dl 0
loc 18
c 0
b 0
f 0
rs 10
nop 1
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