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

Function TestIssueCreate_nonLegacyTemplate

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

Source from the content-addressed store, hash-verified

1651}
1652
1653func TestIssueCreate_nonLegacyTemplate(t *testing.T) {
1654 http := &httpmock.Registry{}
1655 defer http.Verify(t)
1656
1657 http.Register(
1658 httpmock.GraphQL(`query IssueRepositoryInfo\b`),
1659 httpmock.StringResponse(`
1660 { "data": { "repository": {
1661 "id": "REPOID",
1662 "hasIssuesEnabled": true
1663 } } }`),
1664 )
1665 http.Register(
1666 httpmock.GraphQL(`query IssueTemplates\b`),
1667 httpmock.StringResponse(`
1668 { "data": { "repository": { "issueTemplates": [
1669 { "name": "Bug report",
1670 "body": "Does not work :((" },
1671 { "name": "Submit a request",
1672 "body": "I have a suggestion for an enhancement" }
1673 ] } } }`),
1674 )
1675 http.Register(
1676 httpmock.GraphQL(`mutation IssueCreate\b`),
1677 httpmock.GraphQLMutation(`
1678 { "data": { "createIssue": { "issue": {
1679 "URL": "https://github.com/OWNER/REPO/issues/12"
1680 } } } }`,
1681 func(inputs map[string]any) {
1682 assert.Equal(t, inputs["repositoryId"], "REPOID")
1683 assert.Equal(t, inputs["title"], "hello")
1684 assert.Equal(t, inputs["body"], "I have a suggestion for an enhancement")
1685 }),
1686 )
1687
1688 pm := &prompter.PrompterMock{}
1689 pm.MarkdownEditorFunc = func(p, d string, ba bool) (string, error) {
1690 if p == "Body" {
1691 return d, nil
1692 } else {
1693 return "", prompter.NoSuchPromptErr(p)
1694 }
1695 }
1696 pm.SelectFunc = func(p, _ string, opts []string) (int, error) {
1697 switch p {
1698 case "What's next?":
1699 return prompter.IndexFor(opts, "Submit")
1700 case "Choose a template":
1701 return prompter.IndexFor(opts, "Submit a request")
1702 default:
1703 return -1, prompter.NoSuchPromptErr(p)
1704 }
1705 }
1706
1707 output, err := runCommandWithRootDirOverridden(http, true, `-t hello`, "./fixtures/repoWithNonLegacyIssueTemplates", pm)
1708 if err != nil {
1709 t.Errorf("error running command `issue create`: %v", err)
1710 }

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