MCPcopy
hub / github.com/cli/cli / TestIssueCreate_nonLegacyTemplate

Function TestIssueCreate_nonLegacyTemplate

pkg/cmd/issue/create/create_test.go:1142–1203  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1140}
1141
1142func TestIssueCreate_nonLegacyTemplate(t *testing.T) {
1143 http := &httpmock.Registry{}
1144 defer http.Verify(t)
1145
1146 http.Register(
1147 httpmock.GraphQL(`query IssueRepositoryInfo\b`),
1148 httpmock.StringResponse(`
1149 { "data": { "repository": {
1150 "id": "REPOID",
1151 "hasIssuesEnabled": true
1152 } } }`),
1153 )
1154 http.Register(
1155 httpmock.GraphQL(`query IssueTemplates\b`),
1156 httpmock.StringResponse(`
1157 { "data": { "repository": { "issueTemplates": [
1158 { "name": "Bug report",
1159 "body": "Does not work :((" },
1160 { "name": "Submit a request",
1161 "body": "I have a suggestion for an enhancement" }
1162 ] } } }`),
1163 )
1164 http.Register(
1165 httpmock.GraphQL(`mutation IssueCreate\b`),
1166 httpmock.GraphQLMutation(`
1167 { "data": { "createIssue": { "issue": {
1168 "URL": "https://github.com/OWNER/REPO/issues/12"
1169 } } } }`,
1170 func(inputs map[string]interface{}) {
1171 assert.Equal(t, inputs["repositoryId"], "REPOID")
1172 assert.Equal(t, inputs["title"], "hello")
1173 assert.Equal(t, inputs["body"], "I have a suggestion for an enhancement")
1174 }),
1175 )
1176
1177 pm := &prompter.PrompterMock{}
1178 pm.MarkdownEditorFunc = func(p, d string, ba bool) (string, error) {
1179 if p == "Body" {
1180 return d, nil
1181 } else {
1182 return "", prompter.NoSuchPromptErr(p)
1183 }
1184 }
1185 pm.SelectFunc = func(p, _ string, opts []string) (int, error) {
1186 switch p {
1187 case "What's next?":
1188 return prompter.IndexFor(opts, "Submit")
1189 case "Choose a template":
1190 return prompter.IndexFor(opts, "Submit a request")
1191 default:
1192 return -1, prompter.NoSuchPromptErr(p)
1193 }
1194 }
1195
1196 output, err := runCommandWithRootDirOverridden(http, true, `-t hello`, "./fixtures/repoWithNonLegacyIssueTemplates", pm)
1197 if err != nil {
1198 t.Errorf("error running command `issue create`: %v", err)
1199 }

Callers

nothing calls this directly

Calls 11

VerifyMethod · 0.95
RegisterMethod · 0.95
GraphQLFunction · 0.92
StringResponseFunction · 0.92
GraphQLMutationFunction · 0.92
NoSuchPromptErrFunction · 0.92
IndexForFunction · 0.92
EqualMethod · 0.80
ErrorfMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected