MCPcopy Create free account
hub / github.com/cli/cli / TestIssueCreate_nonLegacyTemplate

Function TestIssueCreate_nonLegacyTemplate

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

Source from the content-addressed store, hash-verified

1592}
1593
1594func TestIssueCreate_nonLegacyTemplate(t *testing.T) {
1595 http := &httpmock.Registry{}
1596 defer http.Verify(t)
1597
1598 http.Register(
1599 httpmock.GraphQL(`query IssueRepositoryInfo\b`),
1600 httpmock.StringResponse(`
1601 { "data": { "repository": {
1602 "id": "REPOID",
1603 "hasIssuesEnabled": true
1604 } } }`),
1605 )
1606 http.Register(
1607 httpmock.GraphQL(`query IssueTemplates\b`),
1608 httpmock.StringResponse(`
1609 { "data": { "repository": { "issueTemplates": [
1610 { "name": "Bug report",
1611 "body": "Does not work :((" },
1612 { "name": "Submit a request",
1613 "body": "I have a suggestion for an enhancement" }
1614 ] } } }`),
1615 )
1616 http.Register(
1617 httpmock.GraphQL(`mutation IssueCreate\b`),
1618 httpmock.GraphQLMutation(`
1619 { "data": { "createIssue": { "issue": {
1620 "URL": "https://github.com/OWNER/REPO/issues/12"
1621 } } } }`,
1622 func(inputs map[string]any) {
1623 assert.Equal(t, inputs["repositoryId"], "REPOID")
1624 assert.Equal(t, inputs["title"], "hello")
1625 assert.Equal(t, inputs["body"], "I have a suggestion for an enhancement")
1626 }),
1627 )
1628
1629 pm := &prompter.PrompterMock{}
1630 pm.MarkdownEditorFunc = func(p, d string, ba bool) (string, error) {
1631 if p == "Body" {
1632 return d, nil
1633 } else {
1634 return "", prompter.NoSuchPromptErr(p)
1635 }
1636 }
1637 pm.SelectFunc = func(p, _ string, opts []string) (int, error) {
1638 switch p {
1639 case "What's next?":
1640 return prompter.IndexFor(opts, "Submit")
1641 case "Choose a template":
1642 return prompter.IndexFor(opts, "Submit a request")
1643 default:
1644 return -1, prompter.NoSuchPromptErr(p)
1645 }
1646 }
1647
1648 output, err := runCommandWithRootDirOverridden(http, true, `-t hello`, "./fixtures/repoWithNonLegacyIssueTemplates", pm)
1649 if err != nil {
1650 t.Errorf("error running command `issue create`: %v", err)
1651 }

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.65

Tested by

no test coverage detected