@@ -57,10 +57,91 @@ func TestCreateWorkPackagePrintsDryRunJSONWithParent(t *testing.T) {
5757 printCreatedWorkPackageAsJSON = true
5858 dryRunCreateWorkPackage = true
5959 typeFlag = ""
60+ descriptionFlag = ""
61+ descriptionFlagChanged = false
6062
6163 createWorkPackage (nil , []string {"Build reusable skill" })
6264
63- expected := "{\" valid\" :true,\" operation\" :\" create\" ,\" project_id\" :1482,\" parent_id\" :74316,\" work_package\" :{\" subject\" :\" Build reusable skill\" ,\" type\" :\" \" }}\n "
65+ expected := "{\" valid\" :true,\" operation\" :\" create\" ,\" project_id\" :1482,\" parent_id\" :74316,\" work_package\" :{\" subject\" :\" Build reusable skill\" ,\" type\" :\" \" ,\" description\" :\" \" }}\n "
66+ if activePrinter .Result != expected {
67+ t .Fatalf ("expected %s, got %s" , expected , activePrinter .Result )
68+ }
69+ }
70+
71+ func TestCreateWorkPackagePrintsDryRunJSONWithDescription (t * testing.T ) {
72+ server := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
73+ switch r .URL .Path {
74+ case "/api/v3/work_packages/74316" :
75+ _ , _ = io .WriteString (w , `{
76+ "id": 74316,
77+ "subject": "Expand op CLI to support scripted work package workflows",
78+ "_embedded": {
79+ "project": {
80+ "id": 1482,
81+ "identifier": "cli",
82+ "name": "CLI"
83+ }
84+ },
85+ "_links": {
86+ "self": {"href": "/api/v3/work_packages/74316"},
87+ "project": {"href": "/api/v3/projects/1482", "title": "CLI"},
88+ "status": {"href": "/api/v3/statuses/1", "title": "new"},
89+ "type": {"href": "/api/v3/types/6", "title": "Feature"},
90+ "assignee": {"href": null, "title": ""}
91+ }
92+ }` )
93+ case "/api/v3/projects/1482" :
94+ _ , _ = io .WriteString (w , `{
95+ "id": 1482,
96+ "identifier": "cli",
97+ "name": "CLI",
98+ "_links": {
99+ "types": {"href": "/api/v3/projects/1482/types/available"}
100+ }
101+ }` )
102+ case "/api/v3/projects/1482/types/available" :
103+ _ , _ = io .WriteString (w , `{
104+ "_embedded": {
105+ "elements": [
106+ {
107+ "id": 7,
108+ "name": "Implementation",
109+ "_links": {
110+ "self": {"href": "/api/v3/types/7"}
111+ }
112+ }
113+ ]
114+ }
115+ }` )
116+ default :
117+ t .Fatalf ("unexpected path %s" , r .URL .Path )
118+ }
119+ }))
120+ defer server .Close ()
121+
122+ host , err := url .Parse (server .URL )
123+ if err != nil {
124+ t .Fatal (err )
125+ }
126+
127+ requests .Init (host , "token" , false )
128+ routes .Init (host )
129+
130+ activePrinter := & printer.TestingPrinter {}
131+ printer .Init (activePrinter )
132+
133+ projectId = 0
134+ parentWorkPackageID = 74316
135+ shouldOpenWorkPackageInBrowser = false
136+ printCreatedWorkPackageAsJSON = true
137+ dryRunCreateWorkPackage = true
138+ typeFlag = "Implementation"
139+ descriptionFlag = "Body"
140+ descriptionFlagChanged = true
141+
142+ createWorkPackage (nil , []string {"Add explicit work package description support" })
143+
144+ expected := "{\" valid\" :true,\" operation\" :\" create\" ,\" project_id\" :1482,\" parent_id\" :74316,\" work_package\" :{\" subject\" :\" Add explicit work package description support\" ,\" type\" :\" Implementation\" ,\" description\" :\" Body\" }}\n "
64145 if activePrinter .Result != expected {
65146 t .Fatalf ("expected %s, got %s" , expected , activePrinter .Result )
66147 }
@@ -76,6 +157,8 @@ func TestCreateWorkPackagePrintsJSONErrorForFlagConflict(t *testing.T) {
76157 printCreatedWorkPackageAsJSON = true
77158 dryRunCreateWorkPackage = false
78159 typeFlag = ""
160+ descriptionFlag = ""
161+ descriptionFlagChanged = false
79162
80163 createWorkPackage (nil , []string {"Build reusable skill" })
81164
@@ -92,6 +175,8 @@ func TestValidateCreateWorkPackageFlagsRejectsDryRunWithoutJSON(t *testing.T) {
92175 printCreatedWorkPackageAsJSON = false
93176 dryRunCreateWorkPackage = true
94177 typeFlag = ""
178+ descriptionFlag = ""
179+ descriptionFlagChanged = false
95180
96181 err := validateCreateWorkPackageFlags ()
97182 if err == nil {
@@ -207,6 +292,8 @@ func TestCreateWorkPackagePrintsInvalidArgumentForValidationError(t *testing.T)
207292 printCreatedWorkPackageAsJSON = true
208293 dryRunCreateWorkPackage = false
209294 typeFlag = ""
295+ descriptionFlag = ""
296+ descriptionFlagChanged = false
210297
211298 createWorkPackage (nil , []string {"Build reusable skill" })
212299
@@ -245,6 +332,8 @@ func TestCreateWorkPackagePrintsAPIErrorForDryRunParentLookupFailure(t *testing.
245332 printCreatedWorkPackageAsJSON = true
246333 dryRunCreateWorkPackage = true
247334 typeFlag = ""
335+ descriptionFlag = ""
336+ descriptionFlagChanged = false
248337
249338 createWorkPackage (nil , []string {"Build reusable skill" })
250339
@@ -318,6 +407,8 @@ func TestCreateWorkPackagePrintsPostApplyInspectFailure(t *testing.T) {
318407 printCreatedWorkPackageAsJSON = true
319408 dryRunCreateWorkPackage = false
320409 typeFlag = "Implementation"
410+ descriptionFlag = ""
411+ descriptionFlagChanged = false
321412
322413 createWorkPackage (nil , []string {"Build reusable skill" })
323414
0 commit comments