forked from toggl/go-freshbooks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfreshbooks_test.go
59 lines (54 loc) · 1.45 KB
/
freshbooks_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
package freshbooks
import (
"encoding/json"
"github.com/tambet/oauthplain"
"io/ioutil"
"testing"
)
type authConfig struct {
AccountName string
AuthToken string // Token-Based authentication (deprecated)
ConsumerKey string // OAuth authentication
ConsumerSecret string // OAuth authentication
OAuthToken string // OAuth authentication
OAuthTokenSecret string // OAuth authentication
}
func loadTestConfig(t *testing.T) *authConfig {
file, e := ioutil.ReadFile("test-config.json")
if e != nil {
t.Fatal("Unable to load 'test-config.json'")
}
var config authConfig
if err := json.Unmarshal(file, &config); err != nil {
t.Fatal("Unable to unmarshal 'test-config.json'")
}
return &config
}
func TestGetUsers(t *testing.T) {
conf := loadTestConfig(t)
api := NewApi(conf.AccountName, conf.AuthToken)
users, err := api.Users()
if err != nil {
t.Fatal("Freshbooks retured an error:", err.Error())
}
if len(users) < 1 {
t.Fatal("There should be at least one user")
}
}
func TestOAuth(t *testing.T) {
conf := loadTestConfig(t)
token := &oauthplain.Token{
ConsumerKey: conf.ConsumerKey,
ConsumerSecret: conf.ConsumerSecret,
OAuthToken: conf.OAuthToken,
OAuthTokenSecret: conf.OAuthTokenSecret,
}
api := NewApi(conf.AccountName, token)
users, err := api.Users()
if err != nil {
t.Fatal("Freshbooks retured an error:", err.Error())
}
if len(users) < 1 {
t.Fatal("There should be at least one user")
}
}