forked from cli/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtemplates_test.go
More file actions
74 lines (64 loc) · 1.79 KB
/
templates_test.go
File metadata and controls
74 lines (64 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package shared
import (
"io/ioutil"
"net/http"
"os"
"path/filepath"
"testing"
"github.com/cli/cli/v2/internal/ghrepo"
"github.com/cli/cli/v2/pkg/httpmock"
"github.com/cli/cli/v2/pkg/prompt"
"github.com/stretchr/testify/assert"
)
func TestTemplateManager_hasAPI(t *testing.T) {
rootDir := t.TempDir()
legacyTemplateFile := filepath.Join(rootDir, ".github", "ISSUE_TEMPLATE.md")
_ = os.MkdirAll(filepath.Dir(legacyTemplateFile), 0755)
_ = ioutil.WriteFile(legacyTemplateFile, []byte("LEGACY"), 0644)
tr := httpmock.Registry{}
httpClient := &http.Client{Transport: &tr}
defer tr.Verify(t)
tr.Register(
httpmock.GraphQL(`query IssueTemplates_fields\b`),
httpmock.StringResponse(`{"data":{
"Repository": {
"fields": [
{"name": "foo"},
{"name": "issueTemplates"}
]
},
"CreateIssueInput": {
"inputFields": [
{"name": "foo"},
{"name": "issueTemplate"}
]
}
}}`))
tr.Register(
httpmock.GraphQL(`query IssueTemplates\b`),
httpmock.StringResponse(`{"data":{"repository":{
"issueTemplates": [
{"name": "Bug report", "body": "I found a problem"},
{"name": "Feature request", "body": "I need a feature"}
]
}}}`))
m := templateManager{
repo: ghrepo.NewWithHost("OWNER", "REPO", "example.com"),
rootDir: rootDir,
allowFS: true,
isPR: false,
httpClient: httpClient,
cachedClient: httpClient,
}
hasTemplates, err := m.HasTemplates()
assert.NoError(t, err)
assert.True(t, hasTemplates)
assert.Equal(t, "LEGACY", string(m.LegacyBody()))
as, askRestore := prompt.InitAskStubber()
defer askRestore()
as.StubOne(1) // choose "Feature Request"
tpl, err := m.Choose()
assert.NoError(t, err)
assert.Equal(t, "Feature request", tpl.NameForSubmit())
assert.Equal(t, "I need a feature", string(tpl.Body()))
}