-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathapi_task_test.go
145 lines (124 loc) · 4.54 KB
/
api_task_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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
package tapd
import (
"context"
"net/http"
"testing"
"github.com/stretchr/testify/assert"
)
func TestTaskService_GetTasks(t *testing.T) {
_, client := createServerClient(t, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
assert.Equal(t, http.MethodGet, r.Method)
assert.Equal(t, "/tasks", r.URL.Path)
_, _ = w.Write(loadData(t, "internal/testdata/api/task/get_tasks.json"))
}))
tasks, _, err := client.TaskService.GetTasks(ctx, &GetTasksRequest{
WorkspaceID: Ptr(11112222),
Status: NewEnum(TaskStatusOpen.String(), TaskStatusDone.String()),
Fields: NewMulti("id", "workspace_id"),
})
assert.NoError(t, err)
assert.True(t, len(tasks) > 0)
}
func TestTaskService_GetTasksCount(t *testing.T) {
_, client := createServerClient(t, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
assert.Equal(t, http.MethodGet, r.Method)
assert.Equal(t, "/tasks/count", r.URL.Path)
assert.Equal(t, "11112222", r.URL.Query().Get("workspace_id"))
assert.Equal(t, "open|done", r.URL.Query().Get("status"))
_, _ = w.Write(loadData(t, "internal/testdata/api/task/get_tasks_count.json"))
}))
count, _, err := client.TaskService.GetTasksCount(ctx, &GetTasksCountRequest{
WorkspaceID: Ptr(11112222),
Status: NewEnum(TaskStatusOpen, TaskStatusDone),
})
assert.NoError(t, err)
assert.Equal(t, 36, count)
}
func TestTaskService_GetTaskChanges(t *testing.T) {
_, client := createServerClient(t, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
assert.Equal(t, http.MethodGet, r.Method)
assert.Equal(t, "/task_changes", r.URL.Path)
assert.Equal(t, "11112222", r.URL.Query().Get("workspace_id"))
_, _ = w.Write(loadData(t, "internal/testdata/api/task/get_task_changes.json"))
}))
changes, _, err := client.TaskService.GetTaskChanges(context.Background(), &GetTaskChangesRequest{
WorkspaceID: Ptr(11112222),
})
assert.NoError(t, err)
assert.True(t, len(changes) > 0)
var flag1, flag2 bool
for _, change := range changes {
if change.ID == "1111112222001019140" {
for _, fieldChange := range change.FieldChanges {
if fieldChange.Field == "remain" {
assert.Equal(t, "1", fieldChange.ValueBefore)
assert.Equal(t, "0", fieldChange.ValueAfter)
assert.Equal(t, "剩余工时", fieldChange.FieldLabel)
flag1 = true
}
if fieldChange.Field == "effort_completed" {
assert.Equal(t, "0", fieldChange.ValueBefore)
assert.Equal(t, "1", fieldChange.ValueAfter)
assert.Equal(t, "完成工时", fieldChange.FieldLabel)
flag2 = true
}
}
}
}
assert.True(t, flag1)
assert.True(t, flag2)
}
func TestTaskService_GetTaskChangesCount(t *testing.T) {
_, client := createServerClient(t, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
assert.Equal(t, http.MethodGet, r.Method)
assert.Equal(t, "/task_changes/count", r.URL.Path)
assert.Equal(t, "11112222", r.URL.Query().Get("workspace_id"))
_, _ = w.Write(loadData(t, "internal/testdata/api/task/get_task_changes_count.json"))
}))
count, _, err := client.TaskService.GetTaskChangesCount(context.Background(), &GetTaskChangesCountRequest{
WorkspaceID: Ptr(11112222),
})
assert.NoError(t, err)
assert.Equal(t, 189, count)
}
func TestTaskService_GetTaskFieldsInfo(t *testing.T) {
_, client := createServerClient(t, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
assert.Equal(t, http.MethodGet, r.Method)
assert.Equal(t, "/tasks/get_fields_info", r.URL.Path)
assert.Equal(t, "11112222", r.URL.Query().Get("workspace_id"))
_, _ = w.Write(loadData(t, "internal/testdata/api/task/get_task_fields_info.json"))
}))
fields, _, err := client.TaskService.GetTaskFieldsInfo(ctx, &GetTaskFieldsInfoRequest{
WorkspaceID: Ptr(11112222),
})
assert.NoError(t, err)
assert.True(t, len(fields) > 0)
var flag1, flag2 bool
// slice with id name
for _, field := range fields {
if field.Name == "id" {
assert.Equal(t, TaskFieldsInfoHTMLTypeInput, field.HTMLType)
assert.Equal(t, "ID", field.Label)
flag1 = true
}
if field.Name == "iteration_id" {
flag2 = true
assert.Equal(t, "迭代", field.Label)
assert.Equal(t, TaskFieldsInfoHTMLTypeSelect, field.HTMLType)
assert.Contains(t, field.Options, TaskFieldsInfoOption{
Value: "1111112222001001246",
Label: "迭代2",
})
assert.Contains(t, field.PureOptions, TaskFieldsInfoPureOption{
ParentID: "0",
WorkspaceID: "11112222",
Sort: "100124600000",
Value: "1111112222001001246",
Label: "迭代2",
Panel: 0,
})
}
}
assert.True(t, flag1)
assert.True(t, flag2)
}