Skip to content

Commit

Permalink
test: /v2/private/account/api-key (#73)
Browse files Browse the repository at this point in the history
* test: integration

* test: unit
  • Loading branch information
hirokisan authored Jan 24, 2023
1 parent dd40aec commit 57d9f1c
Show file tree
Hide file tree
Showing 5 changed files with 193 additions and 4 deletions.
2 changes: 1 addition & 1 deletion future_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func (s *FutureCommonService) APIKeyInfo() (*APIKeyInfoResponse, error) {
query url.Values
)

if err := s.client.getPrivately("v2/private/account/api-key", query, &res); err != nil {
if err := s.client.getPrivately("/v2/private/account/api-key", query, &res); err != nil {
return nil, err
}

Expand Down
105 changes: 105 additions & 0 deletions future_inverse_perpetual_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1097,3 +1097,108 @@ func TestTradingStop(t *testing.T) {
assert.Error(t, err)
})
}

func TestAPIKeyInfo(t *testing.T) {
t.Run("success", func(t *testing.T) {
path := "/v2/private/account/api-key"
method := http.MethodGet
status := http.StatusOK
respBody := map[string]interface{}{
"result": []map[string]interface{}{
{
"api_key": "TrswBXTLDVhxqkfDEI",
"type": "personal",
"user_id": 146940,
"inviter_id": 0,
"ips": []string{
"*",
},
"note": "full3",
"permissions": []string{
"OptionsTrade",
"CopyTrading",
"ExchangeHistory",
"SpotTrade",
"AccountTransfer",
"SubMemberTransfer",
"Order",
"Position",
"DerivativesTrade",
},
"created_at": "2022-06-20T13:26:50Z",
"expired_at": "2023-04-23T05:52:24Z",
"read_only": false,
"vip_level": "No VIP",
"mkt_maker_level": "0",
"affiliate_id": 0,
},
},
}
bytesBody, err := json.Marshal(respBody)
require.NoError(t, err)

server, teardown := testhelper.NewServer(
testhelper.WithHandlerOption(path, method, status, bytesBody),
)
defer teardown()

client := NewTestClient().
WithBaseURL(server.URL).
WithAuth("test", "test")

resp, err := client.Future().InversePerpetual().APIKeyInfo()
require.NoError(t, err)

require.NotNil(t, resp)
testhelper.Compare(t, respBody["result"], resp.Result)
})
t.Run("authentication required", func(t *testing.T) {
path := "/v2/private/account/api-key"
method := http.MethodGet
status := http.StatusOK
respBody := map[string]interface{}{
"result": []map[string]interface{}{
{
"api_key": "TrswBXTLDVhxqkfDEI",
"type": "personal",
"user_id": 146940,
"inviter_id": 0,
"ips": []string{
"*",
},
"note": "full3",
"permissions": []string{
"OptionsTrade",
"CopyTrading",
"ExchangeHistory",
"SpotTrade",
"AccountTransfer",
"SubMemberTransfer",
"Order",
"Position",
"DerivativesTrade",
},
"created_at": "2022-06-20T13:26:50Z",
"expired_at": "2023-04-23T05:52:24Z",
"read_only": false,
"vip_level": "No VIP",
"mkt_maker_level": "0",
"affiliate_id": 0,
},
},
}
bytesBody, err := json.Marshal(respBody)
require.NoError(t, err)

server, teardown := testhelper.NewServer(
testhelper.WithHandlerOption(path, method, status, bytesBody),
)
defer teardown()

client := NewTestClient().
WithBaseURL(server.URL)

_, err = client.Future().InversePerpetual().APIKeyInfo()
assert.Error(t, err)
})
}
Original file line number Diff line number Diff line change
@@ -1 +1,29 @@
{}
[
{
"api_key": "TrswBXTLDVhxqkfDEI",
"type": "personal",
"user_id": 146940,
"inviter_id": 0,
"ips": [
"*"
],
"note": "full3",
"permissions": [
"OptionsTrade",
"CopyTrading",
"ExchangeHistory",
"SpotTrade",
"AccountTransfer",
"SubMemberTransfer",
"Order",
"Position",
"DerivativesTrade"
],
"created_at": "2022-06-20T13:26:50Z",
"expired_at": "2023-04-23T05:52:24Z",
"read_only": false,
"vip_level": "No VIP",
"mkt_maker_level": "0",
"affiliate_id": 0
}
]
Original file line number Diff line number Diff line change
@@ -1 +1,29 @@
{}
[
{
"api_key": "TrswBXTLDVhxqkfDEI",
"type": "personal",
"user_id": 146940,
"inviter_id": 0,
"ips": [
"*"
],
"note": "full3",
"permissions": [
"OptionsTrade",
"CopyTrading",
"ExchangeHistory",
"SpotTrade",
"AccountTransfer",
"SubMemberTransfer",
"Order",
"Position",
"DerivativesTrade"
],
"created_at": "2022-06-20T13:26:50Z",
"expired_at": "2023-04-23T05:52:24Z",
"read_only": false,
"vip_level": "No VIP",
"mkt_maker_level": "0",
"affiliate_id": 0
}
]
Original file line number Diff line number Diff line change
@@ -1 +1,29 @@
{}
[
{
"api_key": "TrswBXTLDVhxqkfDEI",
"type": "personal",
"user_id": 146940,
"inviter_id": 0,
"ips": [
"*"
],
"note": "full3",
"permissions": [
"OptionsTrade",
"CopyTrading",
"ExchangeHistory",
"SpotTrade",
"AccountTransfer",
"SubMemberTransfer",
"Order",
"Position",
"DerivativesTrade"
],
"created_at": "2022-06-20T13:26:50Z",
"expired_at": "2023-04-23T05:52:24Z",
"read_only": false,
"vip_level": "No VIP",
"mkt_maker_level": "0",
"affiliate_id": 0
}
]

0 comments on commit 57d9f1c

Please sign in to comment.