forked from yasvisu/gw2api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
commerce_test.go
101 lines (84 loc) · 2.63 KB
/
commerce_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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
package gw2api
import (
"os"
"testing"
)
func TestCommerceListings(t *testing.T) {
var err error
api := NewGW2Api()
var testCommerceListings []int
if testCommerceListings, err = api.CommerceListings(); err != nil {
t.Error("Failed to fetch listings")
}
var listings []ArticleListing
if listings, err = api.CommerceListingIds(testCommerceListings[0:2]...); err != nil {
t.Error("Failed to parse the listing data: ", err)
} else if len(listings) != 2 {
t.Error("Failed to fetch existing listings")
}
if _, err = api.CommerceListingPages(-1, 0); err == nil {
t.Error("Failed to fetch wrong arguments")
}
if listings, err = api.CommerceListingPages(0, 2); err != nil {
t.Error("Failed to parse the listing data: ", err)
} else if len(listings) != 2 {
t.Error("Failed to fetch existing listings")
}
}
func TestCommerceExchange(t *testing.T) {
var err error
api := NewGW2Api()
if _, err = api.CommerceExchangeGems(0); err == nil {
t.Error("Failed to fetch wrong arguments")
}
if _, err = api.CommerceExchangeCoins(0); err == nil {
t.Error("Failed to fetch wrong arguments")
}
var ex Exchange
if ex, err = api.CommerceExchangeGems(100); err != nil || ex.CoinsPerGem <= 0 {
t.Error("Failed to fetch gem exchange rate", ex)
}
if ex, err = api.CommerceExchangeCoins(10000); err != nil || ex.CoinsPerGem <= 0 {
t.Error("Failed to fetch coin exchange rate", ex)
}
}
func TestCommercePrices(t *testing.T) {
var err error
api := NewGW2Api()
var testCommercePrices []int
if testCommercePrices, err = api.CommercePrices(); err != nil {
t.Error("Failed to fetch prices")
}
var prices []ArticlePrice
if prices, err = api.CommercePriceIds(testCommercePrices[0:2]...); err != nil {
t.Error("Failed to parse the listing data: ", err)
} else if len(prices) != 2 {
t.Error("Failed to fetch existing prices")
}
}
func TestCommerceTransactions(t *testing.T) {
var apikey string
if apikey = os.Getenv("APIKEY"); len(apikey) < 1 {
t.Skip("Cannot test without APIKEY")
}
var api *GW2Api
var err error
if api, err = NewAuthenticatedGW2Api(apikey); err != nil {
t.Error(err)
}
if !api.HasPermission(PermTradingpost) {
t.Skip("API-Key does not have required permission for the test")
}
if _, err = api.CommerceTransactionsCurrentBuys(); err != nil {
t.Error("Failed parsing current buys")
}
if _, err = api.CommerceTransactionsCurrentSells(); err != nil {
t.Error("Failed parsing current sells")
}
if _, err = api.CommerceTransactionsHistoryBuys(); err != nil {
t.Error("Failed parsing history buys")
}
if _, err = api.CommerceTransactionsHistorySells(); err != nil {
t.Error("Failed parsing history sells")
}
}