-
Notifications
You must be signed in to change notification settings - Fork 11
/
user_test.go
49 lines (45 loc) · 1.14 KB
/
user_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
package harvest
import "testing"
func testUser(t *testing.T) *User {
a := testAPI()
userResponse := mockResponse("users", "user-example.json")
a.BaseURL = userResponse.URL
user, err := a.GetUser(508343, Defaults())
if err != nil {
t.Fatal(err)
}
if user.Email != "[email protected]" {
t.Errorf("Incorrect Email '%s'", user.Email)
}
if user.FirstName != "Harvest" {
t.Errorf("Incorrect First Name '%s'", user.FirstName)
}
return user
}
func TestGetUser(t *testing.T) {
user := testUser(t)
if user == nil {
t.Fatal("testUser() returned nil instead of user")
}
if user.ID != 508343 {
t.Errorf("Incorrect user ID '%v'", user.ID)
}
}
func TestGetUsers(t *testing.T) {
a := testAPI()
userResponse := mockResponse("users", "users-example.json")
a.BaseURL = userResponse.URL
users, err := a.GetUsers(Defaults())
if err != nil {
t.Fatal(err)
}
if len(users) != 2 {
t.Errorf("Incorrect number of users '%v'", len(users))
}
if users[1].LastName != "User" {
t.Errorf("Incorrect Last Name '%s'", users[1].LastName)
}
if users[0].Timezone != "Eastern Time (US & Canada)" {
t.Errorf("Incorrect Time Zone '%s'", users[0].Timezone)
}
}