Skip to content

Commit f246a9e

Browse files
authored
feat(bug): make defect severity level configurable (#48)
* feat(bug): introduce `BugSeverity` type and update related fields * test(api): add test cases for BugSeverity string and human representations * feat(api): add BugSeverity enum support for severity field in bug requests * refactor(webhook): update BugSeverity type to use tapd package * docs(api): add documentation link for BugSeverity field
1 parent cfec309 commit f246a9e

File tree

6 files changed

+1379
-1317
lines changed

6 files changed

+1379
-1317
lines changed

.testdata/api/bug/get_bugs.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"title": "计算不正确",
88
"description": "<strong>前置条件</div><br />",
99
"priority": "",
10-
"severity": "",
10+
"severity": "normal",
1111
"module": "",
1212
"status": "closed",
1313
"reporter": "测试人员",

.testdata/api/bug/update_bug.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"description": null,
88
"project_id": "111222333",
99
"priority": "",
10-
"severity": "",
10+
"severity": "normal",
1111
"module": null,
1212
"status": "new",
1313
"reporter": "张三",

api_bug.go

+699-665
Large diffs are not rendered by default.

api_bug_test.go

+27-2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,28 @@ import (
99
"github.com/stretchr/testify/require"
1010
)
1111

12+
func TestBugService_BugSeverity(t *testing.T) {
13+
tests := []struct {
14+
severity BugSeverity
15+
wantString string
16+
wantHuman string
17+
}{
18+
{BugSeverityFatal, "fatal", "致命"},
19+
{BugSeveritySerious, "serious", "严重"},
20+
{BugSeverityNormal, "normal", "一般"},
21+
{BugSeverityPrompt, "prompt", "提示"},
22+
{BugSeverityAdvice, "advice", "建议"},
23+
{BugSeverity(""), "", ""},
24+
}
25+
26+
for _, tt := range tests {
27+
t.Run(tt.severity.String(), func(t *testing.T) {
28+
assert.Equal(t, tt.wantString, tt.severity.String())
29+
assert.Equal(t, tt.wantHuman, tt.severity.Human())
30+
})
31+
}
32+
}
33+
1234
func TestBugService_GetBugs(t *testing.T) {
1335
_, client := createServerClient(t, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
1436
assert.Equal(t, http.MethodGet, r.Method)
@@ -32,7 +54,7 @@ func TestBugService_GetBugs(t *testing.T) {
3254
assert.Equal(t, "计算不正确", bug.Title)
3355
assert.Equal(t, "<strong>前置条件</div><br />", bug.Description)
3456
assert.Equal(t, "", bug.Priority)
35-
assert.Equal(t, "", bug.Severity)
57+
assert.Equal(t, BugSeverityNormal, bug.Severity)
3658
assert.Equal(t, "", bug.Module)
3759
assert.Equal(t, "closed", bug.Status)
3860
assert.Equal(t, "测试人员", bug.Reporter)
@@ -56,11 +78,13 @@ func TestBugService_UpdateBug(t *testing.T) {
5678
WorkspaceID int `json:"workspace_id"`
5779
ID int `json:"id"`
5880
PriorityLabel PriorityLabel `json:"priority_label"`
81+
Severity string `json:"severity"`
5982
}
6083
require.NoError(t, json.NewDecoder(r.Body).Decode(&req))
6184
assert.Equal(t, 11112222, req.WorkspaceID)
6285
assert.Equal(t, 11111222330268, req.ID)
6386
assert.Equal(t, PriorityLabelHigh, req.PriorityLabel)
87+
assert.Equal(t, "fatal|serious", req.Severity)
6488

6589
_, _ = w.Write(loadData(t, ".testdata/api/bug/update_bug.json"))
6690
}))
@@ -69,12 +93,13 @@ func TestBugService_UpdateBug(t *testing.T) {
6993
WorkspaceID: Ptr(11112222),
7094
ID: Ptr(11111222330268),
7195
PriorityLabel: Ptr(PriorityLabelHigh),
96+
Severity: NewEnum(BugSeverityFatal, BugSeveritySerious),
7297
})
7398
require.NoError(t, err)
7499

75100
assert.Equal(t, "11111222333001037077", bug.ID)
76101
assert.Equal(t, "计算不正确222", bug.Title)
77102
assert.Equal(t, "", bug.Description)
78103
assert.Equal(t, "", bug.Priority)
79-
assert.Equal(t, "", bug.Severity)
104+
assert.Equal(t, BugSeverityNormal, bug.Severity)
80105
}

0 commit comments

Comments
 (0)