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