|
1
|
|
|
package mtnmomo |
|
2
|
|
|
|
|
3
|
|
|
import ( |
|
4
|
|
|
"context" |
|
5
|
|
|
"net/http" |
|
6
|
|
|
"testing" |
|
7
|
|
|
|
|
8
|
|
|
"github.com/NdoleStudio/mtnmomo-go/internal/helpers" |
|
9
|
|
|
"github.com/NdoleStudio/mtnmomo-go/internal/stubs" |
|
10
|
|
|
"github.com/stretchr/testify/assert" |
|
11
|
|
|
) |
|
12
|
|
|
|
|
13
|
|
|
func TestCollectionService_Token(t *testing.T) { |
|
14
|
|
|
// Setup |
|
15
|
|
|
t.Parallel() |
|
16
|
|
|
|
|
17
|
|
|
// Arrange |
|
18
|
|
|
request := http.Request{} |
|
19
|
|
|
server := helpers.MakeRequestCapturingTestServer(http.StatusOK, stubs.CollectionToken(), &request) |
|
20
|
|
|
client := New( |
|
21
|
|
|
WithBaseURL(server.URL), |
|
22
|
|
|
WithSubscriptionKey(testSubscriptionKey), |
|
23
|
|
|
WithAPIUser(testAPIUser), |
|
24
|
|
|
WithAPIKey(testAPIKey), |
|
25
|
|
|
) |
|
26
|
|
|
|
|
27
|
|
|
// Act |
|
28
|
|
|
authToken, response, err := client.Collection.Token(context.Background()) |
|
29
|
|
|
|
|
30
|
|
|
// Assert |
|
31
|
|
|
assert.Nil(t, err) |
|
32
|
|
|
|
|
33
|
|
|
username, password, _ := request.BasicAuth() |
|
34
|
|
|
assert.Equal(t, testAPIUser, username) |
|
35
|
|
|
assert.Equal(t, testAPIKey, password) |
|
36
|
|
|
assert.Equal(t, testSubscriptionKey, request.Header.Get(subscriptionKeyHeaderKey)) |
|
37
|
|
|
assert.Equal(t, http.StatusOK, response.HTTPResponse.StatusCode) |
|
38
|
|
|
assert.Equal(t, 3600, authToken.ExpiresIn) |
|
39
|
|
|
assert.Equal(t, "access_token", authToken.TokenType) |
|
40
|
|
|
assert.Equal(t, "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c", authToken.AccessToken) |
|
41
|
|
|
|
|
42
|
|
|
// Teardown |
|
43
|
|
|
server.Close() |
|
44
|
|
|
} |
|
45
|
|
|
|