-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathclient_test.go
82 lines (59 loc) · 2.1 KB
/
client_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
package dwolla
import (
"context"
"os"
"path/filepath"
"testing"
"time"
"github.com/stretchr/testify/assert"
)
var ctx = context.TODO()
func TestClientEnvironment(t *testing.T) {
productionClient := New("foobar", "barbaz", Production)
assert.Equal(t, productionClient.APIURL(), ProductionAPIURL)
assert.Equal(t, productionClient.AuthURL(), ProductionAuthURL)
assert.Equal(t, productionClient.TokenURL(), ProductionTokenURL)
sandboxClient := New("foobar", "barbaz", Sandbox)
assert.Equal(t, sandboxClient.APIURL(), SandboxAPIURL)
assert.Equal(t, sandboxClient.AuthURL(), SandboxAuthURL)
assert.Equal(t, sandboxClient.TokenURL(), SandboxTokenURL)
}
func TestClientRequestToken(t *testing.T) {
c := newMockClient(201, filepath.Join("testdata", "token.json"))
c.Token = nil
assert.NoError(t, c.RequestToken(ctx))
assert.NotEmpty(t, c.Token.AccessToken)
}
func TestClientRequestTokenLive(t *testing.T) {
if os.Getenv("DWOLLA_API_KEY") == "" || os.Getenv("DWOLLA_API_SECRET") == "" {
t.Skip("Test requires DWOLLA_API_KEY and DWOLLA_API_SECRET environment variables")
}
c := New(os.Getenv("DWOLLA_API_KEY"), os.Getenv("DWOLLA_API_SECRET"), Sandbox)
assert.NoError(t, c.RequestToken(ctx))
assert.NotEmpty(t, c.Token.AccessToken)
}
func TestClientRoot(t *testing.T) {
c := newMockClient(200, filepath.Join("testdata", "root.json"))
res, err := c.Root(ctx)
assert.Nil(t, err)
assert.NotNil(t, res)
}
func TestClientRootLive(t *testing.T) {
if os.Getenv("DWOLLA_API_KEY") == "" || os.Getenv("DWOLLA_API_SECRET") == "" {
t.Skip("Test requires DWOLLA_API_KEY and DWOLLA_API_SECRET environment variables")
}
c := New(os.Getenv("DWOLLA_API_KEY"), os.Getenv("DWOLLA_API_SECRET"), Sandbox)
res, err := c.Root(ctx)
assert.Nil(t, err)
assert.NotNil(t, res)
}
func TestTokenExpired(t *testing.T) {
token := &Token{}
assert.True(t, token.Expired())
token = &Token{ExpiresIn: 0, startTime: time.Now()}
assert.True(t, token.Expired())
token = &Token{ExpiresIn: 1, startTime: time.Now()}
assert.False(t, token.Expired())
token = &Token{ExpiresIn: 3600, startTime: time.Now()}
assert.False(t, token.Expired())
}