-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathacitivities_test.go
68 lines (60 loc) · 1.52 KB
/
acitivities_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
package openproject
import (
"fmt"
"net/http"
"os"
"testing"
)
func TestActivitiesServiceGet(t *testing.T) {
setup()
defer teardown()
testAPIEdpoint := "/api/v3/activities/357978"
raw, err := os.ReadFile("./mocks/get/get-activity.json")
if err != nil {
t.Error(err.Error())
return
}
testMux.HandleFunc(testAPIEdpoint, func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
testRequestURL(t, r, testAPIEdpoint)
fmt.Fprint(w, string(raw))
})
activity, _, err := testClient.Activities.Get("357978")
if err != nil {
t.Errorf("Error given: %s", err)
}
if activity == nil {
t.Error("Expected activities. Activities is nil")
return
}
if activity.Id != 357978 {
t.Errorf("Unexpected activity id %d", activity.Id)
}
}
func TestActivitiesService_GetFromWPHref(t *testing.T) {
setup()
defer teardown()
testAPIEdpoint := "/api/v3/work_packages/36353/activities"
raw, err := os.ReadFile("./mocks/get/get-activities.json")
if err != nil {
t.Error(err.Error())
return
}
testMux.HandleFunc(testAPIEdpoint, func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
testRequestURL(t, r, testAPIEdpoint)
fmt.Fprint(w, string(raw))
})
activities, _, err := testClient.Activities.GetFromWPHref("/api/v3/work_packages/36353/activities")
if err != nil {
t.Errorf("Error given: %s", err)
return
}
if activities == nil {
t.Error("Expected activities. Activities is nil")
return
}
if activities.Count != 6 {
t.Errorf("Unexpected activities count %d", activities.Count)
}
}