Skip to content

Commit

Permalink
test title and body separately
Browse files Browse the repository at this point in the history
  • Loading branch information
Danny Ranson committed Aug 14, 2024
1 parent 1fcc16b commit 877b5f0
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 2 deletions.
47 changes: 45 additions & 2 deletions cmd/create_prs/create_prs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"github.com/skyscanner/turbolift/internal/prompt"
"github.com/skyscanner/turbolift/internal/testsupport"
"github.com/stretchr/testify/assert"
"path/filepath"
"testing"
)

Expand All @@ -33,8 +34,50 @@ func TestItWarnsIfDescriptionFileTemplateIsUnchanged(t *testing.T) {
fakePrompt := prompt.NewFakePromptNo()
p = fakePrompt

dir := testsupport.PrepareTempCampaign(true, "org/repo1", "org/repo2")
testsupport.UseDefaultPrDescription(dir)
dirName := testsupport.PrepareTempCampaign(true, "org/repo1", "org/repo2")
testsupport.UseDefaultPrDescription(dirName)

out, err := runCommand()
assert.NoError(t, err)
assert.NotContains(t, out, "Creating PR in org/repo1")
assert.NotContains(t, out, "Creating PR in org/repo2")
assert.NotContains(t, out, "turbolift create-prs completed")
assert.NotContains(t, out, "2 OK, 0 skipped")

fakePrompt.AssertCalledWith(t, "It looks like the PR title and/or description may not have been updated in README.md. Are you sure you want to proceed?")
}

func TestItWarnsIfOnlyPrTitleIsUnchanged(t *testing.T) {
fakeGitHub := github.NewAlwaysFailsFakeGitHub()
gh = fakeGitHub
fakeGit := git.NewAlwaysSucceedsFakeGit()
g = fakeGit
fakePrompt := prompt.NewFakePromptNo()
p = fakePrompt

dirName := testsupport.PrepareTempCampaign(true, "org/repo1", "org/repo2")
testsupport.UsePrTitleTodoOnly(filepath.Base(dirName))

out, err := runCommand()
assert.NoError(t, err)
assert.NotContains(t, out, "Creating PR in org/repo1")
assert.NotContains(t, out, "Creating PR in org/repo2")
assert.NotContains(t, out, "turbolift create-prs completed")
assert.NotContains(t, out, "2 OK, 0 skipped")

fakePrompt.AssertCalledWith(t, "It looks like the PR title and/or description may not have been updated in README.md. Are you sure you want to proceed?")
}

func TestItWarnsIfOnlyPrBodyIsUnchanged(t *testing.T) {
fakeGitHub := github.NewAlwaysFailsFakeGitHub()
gh = fakeGitHub
fakeGit := git.NewAlwaysSucceedsFakeGit()
g = fakeGit
fakePrompt := prompt.NewFakePromptNo()
p = fakePrompt

testsupport.PrepareTempCampaign(true, "org/repo1", "org/repo2")
testsupport.UsePrBodyTodoOnly()

out, err := runCommand()
assert.NoError(t, err)
Expand Down
8 changes: 8 additions & 0 deletions internal/testsupport/testsupport.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,11 @@ func UseDefaultPrDescription(dirName string) {
originalPrBodyTodo := "TODO: This file will serve as both a README and the description of the PR."
CreateOrUpdatePrDescriptionFile("README.md", originalPrTitleTodo, originalPrBodyTodo)
}

func UsePrTitleTodoOnly(dirName string) {
CreateOrUpdatePrDescriptionFile("README.md", fmt.Sprintf("TODO: Title of Pull Request (%s)", dirName), "updated PR body")
}

func UsePrBodyTodoOnly() {
CreateOrUpdatePrDescriptionFile("README.md", "updated PR title", "TODO: This file will serve as both a README and the description of the PR.")
}

0 comments on commit 877b5f0

Please sign in to comment.