actually add tests for computing defaults
This commit is contained in:
parent
fba4f4d19e
commit
1b7840326c
1 changed files with 91 additions and 18 deletions
|
|
@ -270,22 +270,7 @@ func (as *askStubber) StubWithDefaults() {
|
|||
as.Stubs = append(as.Stubs, nil)
|
||||
}
|
||||
|
||||
/*
|
||||
there are going to be calls to:
|
||||
- git status
|
||||
- git push
|
||||
- git rev-parse
|
||||
- git log
|
||||
|
||||
I can handle all that with the new CmdStubber.
|
||||
|
||||
For survey, there is going to be:
|
||||
- potentially template select Ask
|
||||
- title, body Ask
|
||||
- Confirm Action Ask
|
||||
|
||||
*/
|
||||
func TestPRCreate_survey_preview_defaults(t *testing.T) {
|
||||
func TestPRCreate_survey_defaults_multicommit(t *testing.T) {
|
||||
initBlankContext("OWNER/REPO", "feature")
|
||||
http := initFakeHTTP()
|
||||
http.StubRepoResponse("OWNER", "REPO")
|
||||
|
|
@ -345,11 +330,99 @@ func TestPRCreate_survey_preview_defaults(t *testing.T) {
|
|||
}{}
|
||||
json.Unmarshal(bodyBytes, &reqBody)
|
||||
|
||||
expectedBody := "---\n2 commits:\n\n- 12345 commit 0\n- 23456 commit 1\n"
|
||||
|
||||
eq(t, reqBody.Variables.Input.RepositoryID, "REPOID")
|
||||
eq(t, reqBody.Variables.Input.Title, "my title")
|
||||
eq(t, reqBody.Variables.Input.Body, "my body lies")
|
||||
eq(t, reqBody.Variables.Input.Title, "feature")
|
||||
eq(t, reqBody.Variables.Input.Body, expectedBody)
|
||||
eq(t, reqBody.Variables.Input.BaseRefName, "master")
|
||||
eq(t, reqBody.Variables.Input.HeadRefName, "feature")
|
||||
|
||||
eq(t, output.String(), "https://github.com/OWNER/REPO/pull/12\n")
|
||||
}
|
||||
|
||||
func TestPRCreate_survey_defaults_monocommit(t *testing.T) {
|
||||
initBlankContext("OWNER/REPO", "feature")
|
||||
http := initFakeHTTP()
|
||||
http.StubRepoResponse("OWNER", "REPO")
|
||||
http.StubResponse(200, bytes.NewBufferString(`
|
||||
{ "data": { "createPullRequest": { "pullRequest": {
|
||||
"URL": "https://github.com/OWNER/REPO/pull/12"
|
||||
} } } }
|
||||
`))
|
||||
|
||||
cs, cmdTeardown := initCmdStubber()
|
||||
defer cmdTeardown()
|
||||
|
||||
cs.Stub("") // git status
|
||||
cs.Stub("1234567890,the sky above the port") // git log
|
||||
cs.Stub("was the color of a television, turned to a dead channel") // git show
|
||||
cs.Stub("") // git rev-parse
|
||||
cs.Stub("") // git push
|
||||
|
||||
as, surveyTeardown := initAskStubber()
|
||||
defer surveyTeardown()
|
||||
|
||||
as.Stub([]*QuestionStub{
|
||||
&QuestionStub{
|
||||
Name: "title",
|
||||
Default: true,
|
||||
},
|
||||
&QuestionStub{
|
||||
Name: "body",
|
||||
Default: true,
|
||||
},
|
||||
})
|
||||
as.Stub([]*QuestionStub{
|
||||
&QuestionStub{
|
||||
Name: "confirmation",
|
||||
Value: 1,
|
||||
},
|
||||
})
|
||||
|
||||
output, err := RunCommand(prCreateCmd, `pr create`)
|
||||
eq(t, err, nil)
|
||||
|
||||
bodyBytes, _ := ioutil.ReadAll(http.Requests[1].Body)
|
||||
reqBody := struct {
|
||||
Variables struct {
|
||||
Input struct {
|
||||
RepositoryID string
|
||||
Title string
|
||||
Body string
|
||||
BaseRefName string
|
||||
HeadRefName string
|
||||
}
|
||||
}
|
||||
}{}
|
||||
json.Unmarshal(bodyBytes, &reqBody)
|
||||
|
||||
expectedBody := "was the color of a television, turned to a dead channel"
|
||||
|
||||
eq(t, reqBody.Variables.Input.RepositoryID, "REPOID")
|
||||
eq(t, reqBody.Variables.Input.Title, "the sky above the port")
|
||||
eq(t, reqBody.Variables.Input.Body, expectedBody)
|
||||
eq(t, reqBody.Variables.Input.BaseRefName, "master")
|
||||
eq(t, reqBody.Variables.Input.HeadRefName, "feature")
|
||||
|
||||
eq(t, output.String(), "https://github.com/OWNER/REPO/pull/12\n")
|
||||
}
|
||||
|
||||
func TestPRCreate_survey_defaults_no_changes(t *testing.T) {
|
||||
initBlankContext("OWNER/REPO", "feature")
|
||||
|
||||
http := initFakeHTTP()
|
||||
http.StubRepoResponse("OWNER", "REPO")
|
||||
|
||||
cs, cmdTeardown := initCmdStubber()
|
||||
defer cmdTeardown()
|
||||
|
||||
cs.Stub("") // git status
|
||||
cs.Stub("") // git log
|
||||
|
||||
_, err := RunCommand(prCreateCmd, `pr create`)
|
||||
if err == nil {
|
||||
t.Error("expected error")
|
||||
}
|
||||
eq(t, err.Error(), "could not compute title or body defaults: could not find any commits between master and feature")
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue