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

Function TestIssueCreate_nonLegacyTemplate

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

Source from the content-addressed store, hash-verified

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

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