From e6ef7a59631234fb7ec8a4c1c2b30923486d2f9d Mon Sep 17 00:00:00 2001 From: YCK1130 Date: Tue, 13 Aug 2024 01:20:29 +0200 Subject: [PATCH] chore: add move to epic testcase --- application/jira/v0/component_test.go | 181 +++++++++++++++++++---- application/jira/v0/mock_database.go | 17 ++- application/jira/v0/mock_server.go | 2 + application/jira/v0/mock_update_issue.go | 4 + 4 files changed, 173 insertions(+), 31 deletions(-) diff --git a/application/jira/v0/component_test.go b/application/jira/v0/component_test.go index 4a6a3ef6..344003b9 100644 --- a/application/jira/v0/component_test.go +++ b/application/jira/v0/component_test.go @@ -125,7 +125,8 @@ func TestComponent_GetIssueTask(t *testing.T) { ID: "4", Key: "KAN-4", Fields: map[string]interface{}{ - "summary": "Test issue 4", + "summary": "Test issue 4", + "description": "Test description 4", "status": map[string]interface{}{ "name": "Done", }, @@ -133,10 +134,11 @@ func TestComponent_GetIssueTask(t *testing.T) { "name": "Epic", }, }, - Self: "https://test.atlassian.net/rest/agile/1.0/issue/4", - Summary: "Test issue 4", - Status: "Done", - IssueType: "Epic", + Self: "https://test.atlassian.net/rest/agile/1.0/issue/4", + Summary: "Test issue 4", + Description: "Test description 4", + Status: "Done", + IssueType: "Epic", }, }, }, @@ -144,7 +146,7 @@ func TestComponent_GetIssueTask(t *testing.T) { _type: "nok", name: "404 - Not Found", input: GetIssueInput{ - IssueKey: "5", + IssueKey: "100", UpdateHistory: true, }, wantErr: "unsuccessful HTTP response.*", @@ -207,7 +209,7 @@ func TestComponent_ListIssuesTask(t *testing.T) { }, }, wantResp: ListIssuesOutput{ - Total: 1, + Total: 2, StartAt: 0, MaxResults: 10, Issues: []Issue{ @@ -215,7 +217,8 @@ func TestComponent_ListIssuesTask(t *testing.T) { ID: "4", Key: "KAN-4", Fields: map[string]interface{}{ - "summary": "Test issue 4", + "summary": "Test issue 4", + "description": "Test description 4", "status": map[string]interface{}{ "name": "Done", }, @@ -223,10 +226,30 @@ func TestComponent_ListIssuesTask(t *testing.T) { "name": "Epic", }, }, - IssueType: "Epic", - Self: "https://test.atlassian.net/rest/agile/1.0/issue/4", - Status: "Done", - Summary: "Test issue 4", + IssueType: "Epic", + Self: "https://test.atlassian.net/rest/agile/1.0/issue/4", + Description: "Test description 4", + Status: "Done", + Summary: "Test issue 4", + }, + { + ID: "5", + Key: "KAN-5", + Fields: map[string]interface{}{ + "summary": "Test issue 5", + "description": "Test description 5", + "status": map[string]interface{}{ + "name": "Done", + }, + "issuetype": map[string]interface{}{ + "name": "Task", + }, + }, + IssueType: "Task", + Self: "https://test.atlassian.net/rest/agile/1.0/issue/5", + Description: "Test description 5", + Status: "Done", + Summary: "Test issue 5", }, }, }, @@ -243,7 +266,7 @@ func TestComponent_ListIssuesTask(t *testing.T) { }, }, wantResp: ListIssuesOutput{ - Total: 1, + Total: 2, StartAt: 0, MaxResults: 10, Issues: []Issue{ @@ -251,7 +274,8 @@ func TestComponent_ListIssuesTask(t *testing.T) { ID: "4", Key: "KAN-4", Fields: map[string]interface{}{ - "summary": "Test issue 4", + "summary": "Test issue 4", + "description": "Test description 4", "status": map[string]interface{}{ "name": "Done", }, @@ -259,10 +283,30 @@ func TestComponent_ListIssuesTask(t *testing.T) { "name": "Epic", }, }, - IssueType: "Epic", - Self: "https://test.atlassian.net/rest/agile/1.0/issue/4", - Status: "Done", - Summary: "Test issue 4", + IssueType: "Epic", + Self: "https://test.atlassian.net/rest/agile/1.0/issue/4", + Description: "Test description 4", + Status: "Done", + Summary: "Test issue 4", + }, + { + ID: "5", + Key: "KAN-5", + Fields: map[string]interface{}{ + "summary": "Test issue 5", + "description": "Test description 5", + "status": map[string]interface{}{ + "name": "Done", + }, + "issuetype": map[string]interface{}{ + "name": "Task", + }, + }, + IssueType: "Epic", + Self: "https://test.atlassian.net/rest/agile/1.0/issue/5", + Description: "Test description 5", + Status: "Done", + Summary: "Test issue 5", }, }, }, @@ -279,7 +323,7 @@ func TestComponent_ListIssuesTask(t *testing.T) { }, }, wantResp: ListIssuesOutput{ - Total: 1, + Total: 2, StartAt: 0, MaxResults: 10, Issues: []Issue{ @@ -287,7 +331,8 @@ func TestComponent_ListIssuesTask(t *testing.T) { ID: "4", Key: "KAN-4", Fields: map[string]interface{}{ - "summary": "Test issue 4", + "summary": "Test issue 4", + "description": "Test description 4", "status": map[string]interface{}{ "name": "Done", }, @@ -295,10 +340,30 @@ func TestComponent_ListIssuesTask(t *testing.T) { "name": "Epic", }, }, - IssueType: "Epic", - Self: "https://test.atlassian.net/rest/agile/1.0/issue/4", - Status: "Done", - Summary: "Test issue 4", + IssueType: "Epic", + Self: "https://test.atlassian.net/rest/agile/1.0/issue/4", + Description: "Test description 4", + Status: "Done", + Summary: "Test issue 4", + }, + { + ID: "5", + Key: "KAN-5", + Fields: map[string]interface{}{ + "summary": "Test issue 5", + "description": "Test description 5", + "status": map[string]interface{}{ + "name": "Done", + }, + "issuetype": map[string]interface{}{ + "name": "Task", + }, + }, + IssueType: "Task", + Self: "https://test.atlassian.net/rest/agile/1.0/issue/5", + Description: "Test description 5", + Status: "Done", + Summary: "Test issue 5", }, }, }, @@ -315,7 +380,7 @@ func TestComponent_ListIssuesTask(t *testing.T) { }, }, wantResp: ListIssuesOutput{ - Total: 1, + Total: 2, StartAt: 0, MaxResults: 10, Issues: []Issue{ @@ -323,7 +388,8 @@ func TestComponent_ListIssuesTask(t *testing.T) { ID: "4", Key: "KAN-4", Fields: map[string]interface{}{ - "summary": "Test issue 4", + "summary": "Test issue 4", + "description": "Test description 4", "status": map[string]interface{}{ "name": "Done", }, @@ -331,10 +397,30 @@ func TestComponent_ListIssuesTask(t *testing.T) { "name": "Epic", }, }, - IssueType: "Epic", - Self: "https://test.atlassian.net/rest/agile/1.0/issue/4", - Status: "Done", - Summary: "Test issue 4", + IssueType: "Epic", + Self: "https://test.atlassian.net/rest/agile/1.0/issue/4", + Description: "Test description 4", + Status: "Done", + Summary: "Test issue 4", + }, + { + ID: "5", + Key: "KAN-5", + Fields: map[string]interface{}{ + "summary": "Test issue 5", + "description": "Test description 5", + "status": map[string]interface{}{ + "name": "Done", + }, + "issuetype": map[string]interface{}{ + "name": "Task", + }, + }, + IssueType: "Task", + Self: "https://test.atlassian.net/rest/agile/1.0/issue/5", + Description: "Test description 5", + Status: "Done", + Summary: "Test issue 5", }, }, }, @@ -584,6 +670,41 @@ func TestComponent_UpdateIssueTask(t *testing.T) { }, }, }, + { + _type: "ok", + name: "move issue to epic", + input: UpdateIssueInput{ + IssueKey: "KAN-5", + Update: Update{ + UpdateType: "Move Issue to Epic", + EpicKey: "KAN-4", + }, + }, + wantResp: UpdateIssueOutput{ + Issue{ + ID: "5", + Key: "KAN-5", + Fields: map[string]interface{}{ + "summary": "Test issue 5", + "description": "Test description 5", + "status": map[string]interface{}{ + "name": "Done", + }, + "issuetype": map[string]interface{}{ + "name": "Task", + }, + "parent": map[string]interface{}{ + "key": "KAN-4", + }, + }, + Self: "https://test.atlassian.net/rest/agile/1.0/issue/5", + Summary: "Test issue 5", + Status: "Done", + Description: "Test description 5", + IssueType: "Task", + }, + }, + }, { _type: "nok", name: "400 - Bad Request", diff --git a/application/jira/v0/mock_database.go b/application/jira/v0/mock_database.go index 34b2339c..461997ff 100644 --- a/application/jira/v0/mock_database.go +++ b/application/jira/v0/mock_database.go @@ -100,7 +100,8 @@ var fakeIssues = []FakeIssue{ ID: "4", Key: "KAN-4", Fields: map[string]interface{}{ - "summary": "Test issue 4", + "summary": "Test issue 4", + "description": "Test description 4", "status": map[string]interface{}{ "name": "Done", }, @@ -109,6 +110,20 @@ var fakeIssues = []FakeIssue{ }, }, }, + { + ID: "5", + Key: "KAN-5", + Fields: map[string]interface{}{ + "summary": "Test issue 5", + "description": "Test description 5", + "status": map[string]interface{}{ + "name": "Done", + }, + "issuetype": map[string]interface{}{ + "name": "Task", + }, + }, + }, } type FakeSprint struct { diff --git a/application/jira/v0/mock_server.go b/application/jira/v0/mock_server.go index ea0d5ca8..699048fb 100644 --- a/application/jira/v0/mock_server.go +++ b/application/jira/v0/mock_server.go @@ -22,6 +22,8 @@ func router(middlewares ...func(http.Handler) http.Handler) http.Handler { w.WriteHeader(http.StatusOK) _, _ = w.Write([]byte(`{"cloudId":"12345678-1234-1234-1234-123456789012"}`)) }) + + r.Post("/rest/agile/1.0/epic/{epic-key}/issue", mockMoveIssueToEpic) r.Get("/rest/agile/1.0/issue/{issueIdOrKey:[a-zA-z0-9-]+}", mockGetIssue) r.Get("/rest/agile/1.0/sprint/{sprintId}", mockGetSprint) r.Put("/rest/agile/1.0/sprint/{sprintId}", mockUpdateSprint) diff --git a/application/jira/v0/mock_update_issue.go b/application/jira/v0/mock_update_issue.go index e7f7d045..51bef3e8 100644 --- a/application/jira/v0/mock_update_issue.go +++ b/application/jira/v0/mock_update_issue.go @@ -92,3 +92,7 @@ func mockUpdateIssue(res http.ResponseWriter, req *http.Request) { return } } + +func mockMoveIssueToEpic(res http.ResponseWriter, _ *http.Request) { + http.Error(res, "The request contains a next-gen issue", http.StatusBadRequest) +}