-
Notifications
You must be signed in to change notification settings - Fork 2
/
paymego_test.go
52 lines (41 loc) · 1.35 KB
/
paymego_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
52
package paymego
import (
"context"
"net/http"
"net/http/httptest"
"testing"
"time"
"github.com/stretchr/testify/assert"
)
func TestCardsCheck_Success(t *testing.T) {
mockServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte(`{"jsonrpc":"2.0","id":"123","result":{"receipt":{"_id":"abc123"},"card":{"number":"****"}}}`))
}))
defer mockServer.Close()
api := SubscribeAPI{
baseURL: mockServer.URL,
timeout: 5 * time.Second,
httpClient: http.Client{},
}
resp, err := api.CardsCheck(context.Background(), "123", "token123")
assert.NoError(t, err)
assert.NotNil(t, resp)
assert.Equal(t, "abc123", resp.Result.Receipt.ID)
assert.Equal(t, "****", resp.Result.Card.Number)
}
func TestCardsRemove_Success(t *testing.T) {
mockServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte(`{"jsonrpc":"2.0","id":"123","result":{"receipt":{"_id":"abc123"},"card":{"number":"****"}}}`))
}))
defer mockServer.Close()
api := SubscribeAPI{
baseURL: mockServer.URL,
timeout: 5 * time.Second,
httpClient: http.Client{},
}
resp, err := api.CardsRemove(context.Background(), "123", "token123")
assert.NoError(t, err)
assert.NotNil(t, resp)
assert.Equal(t, "abc123", resp.Result.Receipt.ID)
assert.Equal(t, "****", resp.Result.Card.Number)
}