@@ -3,6 +3,7 @@ package jira
3
3
import (
4
4
"fmt"
5
5
"net/http"
6
+ "strings"
6
7
"testing"
7
8
)
8
9
@@ -378,6 +379,84 @@ func TestIssueService_GetCreateMeta_Success(t *testing.T) {
378
379
379
380
}
380
381
382
+ func TestIssueService_GetEditMeta_Success (t * testing.T ) {
383
+ setup ()
384
+ defer teardown ()
385
+
386
+ testAPIEndpoint := "/rest/api/2/issue/PROJ-9001/editmeta"
387
+
388
+ testMux .HandleFunc (testAPIEndpoint , func (w http.ResponseWriter , r * http.Request ) {
389
+ testMethod (t , r , "GET" )
390
+ testRequestURL (t , r , testAPIEndpoint )
391
+
392
+ fmt .Fprint (w , `{
393
+ "fields": {
394
+ "summary": {
395
+ "required": true,
396
+ "schema": {
397
+ "type": "string",
398
+ "system": "summary"
399
+ },
400
+ "name": "Summary",
401
+ "hasDefaultValue": false,
402
+ "operations": [
403
+ "set"
404
+ ]
405
+ },
406
+ "attachment": {
407
+ "required": false,
408
+ "schema": {
409
+ "type": "array",
410
+ "items": "attachment",
411
+ "system": "attachment"
412
+ },
413
+ "name": "Attachment",
414
+ "hasDefaultValue": false,
415
+ "operations": [
416
+
417
+ ]
418
+ }
419
+ }
420
+ }` )
421
+ })
422
+
423
+ editMeta , _ , err := testClient .Issue .GetEditMeta (& Issue {Key : "PROJ-9001" })
424
+ if err != nil {
425
+ t .Errorf ("Expected nil error but got %s" , err )
426
+ }
427
+
428
+ requiredFields := 0
429
+ fields := editMeta .Fields
430
+ for _ , value := range fields {
431
+ for key , value := range value .(map [string ]interface {}) {
432
+ if key == "required" && value == true {
433
+ requiredFields = requiredFields + 1
434
+ }
435
+ }
436
+
437
+ }
438
+ summary := fields ["summary" ].(map [string ]interface {})
439
+ attachment := fields ["attachment" ].(map [string ]interface {})
440
+ if summary ["required" ] != true {
441
+ t .Error ("Expected summary to be required" )
442
+ }
443
+ if attachment ["required" ] != false {
444
+ t .Error ("Expected attachment to not be required" )
445
+ }
446
+ }
447
+
448
+ func TestIssueService_GetEditMeta_Fail (t * testing.T ) {
449
+ _ , _ , err := testClient .Issue .GetEditMeta (& Issue {Key : "PROJ-9001" })
450
+ if err == nil {
451
+ t .Error ("Expected to receive an error, received nil instead" )
452
+ }
453
+
454
+ expectedError := "connection refused"
455
+ if ! strings .Contains (err .Error (), expectedError ) {
456
+ t .Errorf ("Expected to receive error containing %s, received %v instead" , expectedError , err .Error ())
457
+ }
458
+ }
459
+
381
460
func TestMetaIssueType_GetCreateMetaWithOptions (t * testing.T ) {
382
461
setup ()
383
462
defer teardown ()
0 commit comments