Passed
Push — main ( c968a0...dd821a )
by Acho
03:18 queued 10s
created

afrikpay.TestAirtime_Pay   A

Complexity

Conditions 1

Size

Total Lines 21
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 15
nop 1
dl 0
loc 21
rs 9.65
c 0
b 0
f 0
1
package afrikpay
2
3
import (
4
	"context"
5
	"net/http"
6
	"testing"
7
8
	"github.com/NdoleStudio/afrikpay-go/internal/helpers"
9
	"github.com/NdoleStudio/afrikpay-go/internal/stubs"
10
	"github.com/stretchr/testify/assert"
11
)
12
13
func TestAirtime_Pay(t *testing.T) {
14
	// Arrange
15
	apiKey := "test-api-key"
16
	server := helpers.MakeTestServer(http.StatusOK, stubs.AirtimePaymentResponse())
17
	client := New(WithBaseURL(server.URL), WithAPIKey(apiKey))
18
	input := &AirtimePaymentRequest{
19
		ReferenceNumber: "659683157",
20
		Amount:          1000,
21
		Email:           "[email protected]",
22
		ExternalID:      "224169cd-caa6-46d3-8262-eb95adb6b1d9",
23
		Description:     "Orange Airtime Purchase",
24
	}
25
26
	// Act
27
	txn, response, err := client.OrangeAirtime.Pay(context.Background(), input)
28
29
	// Assert
30
	assert.Nil(t, err)
31
	assert.False(t, txn.IsFailed())
32
	assert.Equal(t, 1000, txn.Result.Amount)
33
	assert.Equal(t, http.StatusOK, response.HTTPResponse.StatusCode)
34
}
35
36
func TestAirtime_TransactionStatus(t *testing.T) {
37
	// Arrange
38
	apiKey := "test-api-key"
39
	server := helpers.MakeTestServer(http.StatusOK, stubs.AirtimePaymentResponse())
40
	client := New(WithBaseURL(server.URL), WithAPIKey(apiKey))
41
	input := &TransactionStatusRequest{
42
		ReferenceNumber: "659683157",
43
		Amount:          1000,
44
		ExternalID:      "224169cd-caa6-46d3-8262-eb95adb6b1d9",
45
	}
46
47
	// Act
48
	txn, response, err := client.OrangeAirtime.TransactionStatus(context.Background(), input)
49
50
	// Assert
51
	assert.Nil(t, err)
52
	assert.False(t, txn.IsFailed())
53
	assert.Equal(t, 1000, txn.Result.Amount)
54
	assert.Equal(t, http.StatusOK, response.HTTPResponse.StatusCode)
55
}
56