-
Notifications
You must be signed in to change notification settings - Fork 11
/
user-assignment_test.go
103 lines (92 loc) · 2.71 KB
/
user-assignment_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
102
103
package harvest
import "testing"
func TestGetUserAssignments(t *testing.T) {
a := testAPI()
userAssignmentResponse := mockResponse("userassignments", "user-assignments-example.json")
a.BaseURL = userAssignmentResponse.URL
userassignments, err := a.GetUserAssignments(9876543, Defaults())
if err != nil {
t.Fatal(err)
}
if len(userassignments) != 2 {
t.Errorf("Incorrect number of user assignments '%v'", len(userassignments))
}
if userassignments[1].UserID != 611911 {
t.Errorf("Incorrect user ID '%v'", userassignments[1].UserID)
}
if userassignments[0].IsProjectManager != false {
t.Errorf("User Is Project Manager incorrectly set to '%v'", userassignments[0].IsProjectManager)
}
}
func TestGetUserAssignment(t *testing.T) {
a := testAPI()
userAssignmentResponse := mockResponse("userassignments", "user-assignment-example.json")
a.BaseURL = userAssignmentResponse.URL
userassignment, err := a.GetUserAssignment(9876543, 88888888, Defaults())
if err != nil {
t.Fatal(err)
}
if userassignment.UserID != 1000000 {
t.Errorf("Incorrect user ID '%v'", userassignment.UserID)
}
}
func TestCreateUserAssignment(t *testing.T) {
a := testAPI()
res := mockResponse("userassignments", "user-assignment-example.json")
a.BaseURL = res.URL
ta := UserAssignment{UserID: 123456, ProjectID: 12345}
err := a.CreateUserAssignment(&ta, Defaults())
if err != nil {
t.Fatal(err)
}
if ta.ID != 88888888 {
t.Errorf("Expected ID=%d, got ID=%d", 88888888, ta.ID)
}
}
func TestUpdateUserAssignment(t *testing.T) {
a := testAPI()
res := mockResponse("userassignments", "user-assignment-example.json")
a.BaseURL = res.URL
ta := UserAssignment{UserID: 12456, ProjectID: 12345}
err := a.UpdateUserAssignment(&ta, Defaults())
if err != nil {
t.Fatal(err)
}
if ta.ID != 88888888 {
t.Errorf("Expected ID=%d, got ID=%d", 88888888, ta.ID)
}
}
func TestDeleteUserAssignment(t *testing.T) {
a := testAPI()
err := a.DeleteUserAssignment(&UserAssignment{ID: 123456, ProjectID: 12345}, Defaults())
if err != nil {
t.Fatal(err)
}
}
func TestCopyUserAssignments(t *testing.T) {
a := testAPI()
res := mockDynamicPathResponse()
a.BaseURL = res.URL
err := a.CopyUserAssignments(2, 1)
if err != nil {
t.Fatal(err)
}
}
func TestContainsUserIDPresent(t *testing.T) {
ids := []*UserAssignment{
&UserAssignment{UserID: 1},
&UserAssignment{UserID: 2},
}
if ContainsUserID(1, ids) != true {
t.Errorf("ContainsUserID should be true for 1 when ids contains UserID: 1")
}
}
func TestContainsUserIDMissing(t *testing.T) {
ids := []*UserAssignment{
&UserAssignment{UserID: 1},
&UserAssignment{UserID: 2},
}
if ContainsUserID(10, ids) != false {
t.Errorf("ContainsUserID should be false for 10 when ids has no UserID: 10")
}
}