Passed
Push — main ( 206f54...06bb6a )
by Acho
02:26
created

campay.TestUtilitiesService_AirtimeTransferSync   A

Complexity

Conditions 1

Size

Total Lines 38
Code Lines 26

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 26
nop 1
dl 0
loc 38
rs 9.256
c 0
b 0
f 0
1
package campay
2
3
import (
4
	"context"
5
	"net/http"
6
	"testing"
7
8
	"github.com/NdoleStudio/campay-go-sdk/internal/helpers"
9
	"github.com/NdoleStudio/campay-go-sdk/internal/stubs"
10
	"github.com/stretchr/testify/assert"
11
)
12
13
func TestUtilitiesService_AirtimeTransferSync(t *testing.T) {
14
	// Setup
15
	t.Parallel()
16
17
	// Arrange
18
	requests := make([]*http.Request, 0)
19
	responses := [][]byte{stubs.PostTokenResponse(), stubs.PostTransferResponse(), stubs.GetPendingAirtimeTransactionResponse(), stubs.GetSuccessfullAirtimeTransactionResponse()}
20
	server := helpers.MakeRequestCapturingTestServer(http.StatusOK, responses, &requests)
21
	client := New(WithEnvironment(Environment(server.URL)))
22
23
	// Act
24
	transaction, _, err := client.Utilities.AirtimeTransferSync(context.Background(), &AirtimeTransferParams{
25
		Amount:            "100",
26
		To:                "2376XXXXXXXXX",
27
		ExternalReference: "5577006791947779410",
28
	})
29
30
	// Assert
31
	assert.Nil(t, err)
32
33
	assert.GreaterOrEqual(t, len(requests), 4)
34
	assert.Equal(t, &UtilitiesTransaction{
35
		Reference:         "971e32ae-bb5a-420a-a38a-c2931536609f",
36
		ExternalReference: "5577006791947779410",
37
		Status:            "SUCCESSFUL",
38
		Amount:            100,
39
		Currency:          "XAF",
40
		Operator:          "ORANGE_CM",
41
		Code:              "CP220804U0649K",
42
		Type:              "AIRTIME",
43
		Reason:            "",
44
	}, transaction)
45
46
	assert.True(t, transaction.IsSuccessfull())
47
	assert.False(t, transaction.IsPending())
48
49
	// Teardown
50
	server.Close()
51
}
52