-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathtask-assignment_test.go
103 lines (92 loc) · 2.68 KB
/
task-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 TestGetTaskAssignments(t *testing.T) {
a := testAPI()
taskAssignmentResponse := mockResponse("taskassignments", "task-assignments-example.json")
a.BaseURL = taskAssignmentResponse.URL
taskassignments, err := a.GetTaskAssignments(9292184, Defaults())
if err != nil {
t.Fatal(err)
}
if len(taskassignments) != 4 {
t.Errorf("Incorrect number of task assignments '%v'", len(taskassignments))
}
if taskassignments[0].ID != 101061850 {
t.Errorf("Incorrect task assignment ID '%v'", taskassignments[0].ID)
}
if taskassignments[2].Task.ID != 733904 {
t.Errorf("Incorrect TaskID '%v'", taskassignments[2].Task.ID)
}
}
func TestGetTaskAssignment(t *testing.T) {
a := testAPI()
taskAssignmentResponse := mockResponse("taskassignments", "task-assignment-example.json")
a.BaseURL = taskAssignmentResponse.URL
taskassignment, err := a.GetTaskAssignment(3554414, 37453419, Defaults())
if err != nil {
t.Fatal(err)
}
if taskassignment.Task.ID != 2086199 {
t.Errorf("Incorrect task ID '%v'", taskassignment.Task.ID)
}
}
func TestCreateTaskAssignment(t *testing.T) {
a := testAPI()
res := mockResponse("taskassignments", "task-assignment-example.json")
a.BaseURL = res.URL
ta := TaskAssignment{ID: 123456}
err := a.CreateTaskAssignment(12345, &ta, Defaults())
if err != nil {
t.Fatal(err)
}
if ta.ID != 37453419 {
t.Errorf("Expected ID=%d, got ID=%d", 37453419, ta.ID)
}
}
func TestUpdateTaskAssignment(t *testing.T) {
a := testAPI()
res := mockResponse("taskassignments", "task-assignment-example.json")
a.BaseURL = res.URL
ta := TaskAssignment{ID: 12456}
err := a.UpdateTaskAssignment(12345, &ta, Defaults())
if err != nil {
t.Fatal(err)
}
if ta.ID != 37453419 {
t.Errorf("Expected ID=%d, got ID=%d", 37453419, ta.ID)
}
}
func TestDeleteTaskAssignment(t *testing.T) {
a := testAPI()
err := a.DeleteTaskAssignment(12345, &TaskAssignment{ID: 123456}, Defaults())
if err != nil {
t.Fatal(err)
}
}
func TestCopyTaskAssignments(t *testing.T) {
a := testAPI()
res := mockDynamicPathResponse()
a.BaseURL = res.URL
err := a.CopyTaskAssignments(1, 2)
if err != nil {
t.Fatal(err)
}
}
func TestContainsTaskIDPresent(t *testing.T) {
ids := []*TaskAssignment{
&TaskAssignment{Task: TaskStub{ID: 1}},
&TaskAssignment{Task: TaskStub{ID: 2}},
}
if ContainsTaskID(1, ids) != true {
t.Errorf("ContainsTaskID should be true for 1 when ids contains TaskID: 1")
}
}
func TestContainsTaskIDMissing(t *testing.T) {
ids := []*TaskAssignment{
&TaskAssignment{Task: TaskStub{ID: 1}},
&TaskAssignment{Task: TaskStub{ID: 2}},
}
if ContainsTaskID(10, ids) != false {
t.Errorf("ContainsTaskID should be false for 10 when ids has no TaskID: 10")
}
}