(t *testing.T)
| 1592 | } |
| 1593 | |
| 1594 | func 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 | } |
nothing calls this directly
no test coverage detected