(t *testing.T)
| 1634 | } |
| 1635 | |
| 1636 | func TestIssueCreate_nonLegacyTemplate(t *testing.T) { |
| 1637 | http := &httpmock.Registry{} |
| 1638 | defer http.Verify(t) |
| 1639 | |
| 1640 | http.Register( |
| 1641 | httpmock.GraphQL(`query IssueRepositoryInfo\b`), |
| 1642 | httpmock.StringResponse(` |
| 1643 | { "data": { "repository": { |
| 1644 | "id": "REPOID", |
| 1645 | "hasIssuesEnabled": true |
| 1646 | } } }`), |
| 1647 | ) |
| 1648 | http.Register( |
| 1649 | httpmock.GraphQL(`query IssueTemplates\b`), |
| 1650 | httpmock.StringResponse(` |
| 1651 | { "data": { "repository": { "issueTemplates": [ |
| 1652 | { "name": "Bug report", |
| 1653 | "body": "Does not work :((" }, |
| 1654 | { "name": "Submit a request", |
| 1655 | "body": "I have a suggestion for an enhancement" } |
| 1656 | ] } } }`), |
| 1657 | ) |
| 1658 | http.Register( |
| 1659 | httpmock.GraphQL(`mutation IssueCreate\b`), |
| 1660 | httpmock.GraphQLMutation(` |
| 1661 | { "data": { "createIssue": { "issue": { |
| 1662 | "URL": "https://github.com/OWNER/REPO/issues/12" |
| 1663 | } } } }`, |
| 1664 | func(inputs map[string]any) { |
| 1665 | assert.Equal(t, inputs["repositoryId"], "REPOID") |
| 1666 | assert.Equal(t, inputs["title"], "hello") |
| 1667 | assert.Equal(t, inputs["body"], "I have a suggestion for an enhancement") |
| 1668 | }), |
| 1669 | ) |
| 1670 | |
| 1671 | pm := &prompter.PrompterMock{} |
| 1672 | pm.MarkdownEditorFunc = func(p, d string, ba bool) (string, error) { |
| 1673 | if p == "Body" { |
| 1674 | return d, nil |
| 1675 | } else { |
| 1676 | return "", prompter.NoSuchPromptErr(p) |
| 1677 | } |
| 1678 | } |
| 1679 | pm.SelectFunc = func(p, _ string, opts []string) (int, error) { |
| 1680 | switch p { |
| 1681 | case "What's next?": |
| 1682 | return prompter.IndexFor(opts, "Submit") |
| 1683 | case "Choose a template": |
| 1684 | return prompter.IndexFor(opts, "Submit a request") |
| 1685 | default: |
| 1686 | return -1, prompter.NoSuchPromptErr(p) |
| 1687 | } |
| 1688 | } |
| 1689 | |
| 1690 | output, err := runCommandWithRootDirOverridden(http, true, `-t hello`, "./fixtures/repoWithNonLegacyIssueTemplates", pm) |
| 1691 | if err != nil { |
| 1692 | t.Errorf("error running command `issue create`: %v", err) |
| 1693 | } |
nothing calls this directly
no test coverage detected