-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathqueryOrder_test.go
51 lines (43 loc) · 1.16 KB
/
queryOrder_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
/*
* Created by Du, Chengbin on 2022/6/15.
*/
package binancepay
import (
"bytes"
"encoding/json"
"github.com/stretchr/testify/assert"
"io/ioutil"
"net/http"
"testing"
)
func TestQueryOrder(t *testing.T) {
req := &QueryOrderRequest{}
expectedResp := Response[QueryOrderResult]{
Status: "SUCCESS",
Code: "1",
Data: QueryOrderResult{
MerchantId: "123",
},
ErrMsg: "",
}
httpClient := mockHttpClient(func(request *http.Request) (*http.Response, error) {
assert.Equal(t, "/binancepay/openapi/v2/order/query", request.URL.Path)
assert.Equal(t, http.MethodPost, request.Method)
reqBodyBytes, err := ioutil.ReadAll(request.Body)
assert.Nil(t, err, err)
expectedReq, err := json.Marshal(req)
assert.Nil(t, err, err)
assert.Equal(t, string(expectedReq), string(reqBodyBytes))
respBody, err := json.Marshal(expectedResp)
assert.Nil(t, err, err)
return &http.Response{
Body: ioutil.NopCloser(bytes.NewReader(respBody)),
}, nil
})
client := NewMerchant("", "", nil, logger)
client.httpClient = httpClient
var resp Response[QueryOrderResult]
err := client.Do(req, &resp)
assert.Nil(t, err, err)
assert.Equal(t, expectedResp, resp)
}