|
1
|
|
|
package campay |
|
2
|
|
|
|
|
3
|
|
|
import ( |
|
4
|
|
|
"context" |
|
5
|
|
|
"fmt" |
|
6
|
|
|
"net/http" |
|
7
|
|
|
"strings" |
|
8
|
|
|
"testing" |
|
9
|
|
|
|
|
10
|
|
|
"github.com/NdoleStudio/campay-go-sdk/internal/helpers" |
|
11
|
|
|
"github.com/NdoleStudio/campay-go-sdk/internal/stubs" |
|
12
|
|
|
"github.com/stretchr/testify/assert" |
|
13
|
|
|
) |
|
14
|
|
|
|
|
15
|
|
|
func TestTransactionService_Get(t *testing.T) { |
|
16
|
|
|
// Setup |
|
17
|
|
|
t.Parallel() |
|
18
|
|
|
|
|
19
|
|
|
// Arrange |
|
20
|
|
|
requests := make([]*http.Request, 0) |
|
21
|
|
|
responses := [][]byte{stubs.PostTokenResponse(), stubs.GetPendingTransactionResponse()} |
|
22
|
|
|
server := helpers.MakeRequestCapturingTestServer(http.StatusOK, responses, &requests) |
|
23
|
|
|
client := New(WithEnvironment(Environment(server.URL))) |
|
24
|
|
|
reference := "bcedde9b-62a7-4421-96ac-2e6179552a1a" |
|
25
|
|
|
|
|
26
|
|
|
// Act |
|
27
|
|
|
withdrawResponse, response, err := client.Transaction.Get(context.Background(), reference) |
|
28
|
|
|
|
|
29
|
|
|
// Assert |
|
30
|
|
|
assert.Nil(t, err) |
|
31
|
|
|
|
|
32
|
|
|
assert.GreaterOrEqual(t, len(requests), 1) |
|
33
|
|
|
request := requests[len(requests)-1] |
|
34
|
|
|
assert.Equal(t, fmt.Sprintf("/api/transaction/%s/", reference), request.URL.Path) |
|
35
|
|
|
assert.True(t, strings.HasPrefix(request.Header.Get("Authorization"), "Token")) |
|
36
|
|
|
assert.Equal(t, http.StatusOK, response.HTTPResponse.StatusCode) |
|
37
|
|
|
|
|
38
|
|
|
assert.Equal(t, &Transaction{ |
|
39
|
|
|
Reference: "bcedde9b-62a7-4421-96ac-2e6179552a1a", |
|
40
|
|
|
Status: "PENDING", |
|
41
|
|
|
Amount: 1, |
|
42
|
|
|
Currency: "XAF", |
|
43
|
|
|
Operator: "MTN", |
|
44
|
|
|
Code: "CP201027T00005", |
|
45
|
|
|
OperatorReference: "1880106956", |
|
46
|
|
|
}, withdrawResponse) |
|
47
|
|
|
|
|
48
|
|
|
// Teardown |
|
49
|
|
|
server.Close() |
|
50
|
|
|
} |
|
51
|
|
|
|