From 2e98e8a4a7b3944ff45929590977353cac9491f8 Mon Sep 17 00:00:00 2001 From: Chris Westra Date: Thu, 8 Sep 2022 17:17:06 -0400 Subject: [PATCH] Get that test mostly working --- api/queries_branch_issue_reference.go | 19 +++++++++++---- pkg/cmd/issue/develop/develop_test.go | 34 ++++++++++++++++++++++----- 2 files changed, 43 insertions(+), 10 deletions(-) diff --git a/api/queries_branch_issue_reference.go b/api/queries_branch_issue_reference.go index 2dd9cffcc..a3681421d 100644 --- a/api/queries_branch_issue_reference.go +++ b/api/queries_branch_issue_reference.go @@ -21,6 +21,9 @@ func CreateBranchIssueReference(client *Client, repo *Repository, params map[str }) { linkedBranch { id + ref { + name + } } } } @@ -38,17 +41,25 @@ func CreateBranchIssueReference(client *Client, repo *Repository, params map[str result := struct { createLinkedBranch struct { - BranchIssueReference BranchIssueReference + LinkedBranch struct { + ID int + Ref struct { + Name string + } + } } }{} - fmt.Printf("query variables %#v", inputParams) err := client.GraphQL(repo.RepoHost(), query, inputParams, &result) if err != nil { return nil, err } - ref := &result.createLinkedBranch.BranchIssueReference - return ref, nil + fmt.Printf("result %#v", &result) + ref := BranchIssueReference{ + ID: result.createLinkedBranch.LinkedBranch.ID, + BranchName: result.createLinkedBranch.LinkedBranch.Ref.Name, + } + return &ref, nil } diff --git a/pkg/cmd/issue/develop/develop_test.go b/pkg/cmd/issue/develop/develop_test.go index 5967cedac..9ab2a15c5 100644 --- a/pkg/cmd/issue/develop/develop_test.go +++ b/pkg/cmd/issue/develop/develop_test.go @@ -8,7 +8,9 @@ import ( "github.com/cli/cli/v2/internal/ghrepo" "github.com/cli/cli/v2/internal/run" "github.com/cli/cli/v2/pkg/httpmock" + "github.com/cli/cli/v2/pkg/iostreams" "github.com/cli/cli/v2/pkg/prompt" + "github.com/cli/cli/v2/test" "github.com/stretchr/testify/assert" ) @@ -34,25 +36,32 @@ func Test_developRun(t *testing.T) { }, httpStubs: func(reg *httpmock.Registry, t *testing.T) { reg.StubRepoResponse("OWNER", "REPO") + + reg.Register( + httpmock.GraphQL(`query RepositoryInfo\b`), + httpmock.StringResponse(` + { "data": { "repository": { + "id": "REPOID", + "hasIssuesEnabled": true + } } }`), + ) reg.Register( httpmock.GraphQL(`query IssueByNumber\b`), - httpmock.StringResponse(`{"data":{"repository":{ - "hasIssuesEnabled": true, - "issue":{"id":1, "number":123, "title":"my issue"}, - }}}`)) + httpmock.StringResponse(`{"data":{"repository":{ "hasIssuesEnabled": true, "issue":{"id": "yar", "number":123, "title":"my issue"} }}}`)) reg.Register( httpmock.GraphQL(`query BranchIssueReferenceFindBaseOid\b`), httpmock.StringResponse(`{"data":{"repository":{"ref":{"target":{"oid":"123"}}}}}`)) reg.Register( httpmock.GraphQL(`mutation CreateLinkedBranch\b`), - httpmock.GraphQLMutation(` - { "data": { "createLinkedBranch": { "linkedBranch": 1 } } }`, + httpmock.GraphQLMutation(`{ "data": { "createLinkedBranch": { "linkedBranch": {"id": 2, "ref": {"name": "my-branch"} } } } }`, func(inputs map[string]interface{}) { + }), ) }, + expectedOut: "Created my-branch\n", }, } for _, tt := range tests { @@ -65,6 +74,13 @@ func Test_developRun(t *testing.T) { opts := DevelopOptions{} + ios, _, stdout, stderr := iostreams.Test() + + ios.SetStdoutTTY(tt.tty) + ios.SetStdinTTY(tt.tty) + ios.SetStderrTTY(tt.tty) + opts.IO = ios + opts.BaseRepo = func() (ghrepo.Interface, error) { return ghrepo.New("OWNER", "REPO"), nil } @@ -81,10 +97,16 @@ func Test_developRun(t *testing.T) { defer cleanSetup() err := developRun(&opts) + output := &test.CmdOut{ + OutBuf: stdout, + ErrBuf: stderr, + } if tt.wantErr != "" { assert.EqualError(t, err, tt.wantErr) } else { assert.NoError(t, err) + assert.Equal(t, tt.expectedOut, output.String()) + assert.Equal(t, tt.expectedErrOut, output.Stderr()) } }) }