Skip to content

Commit

Permalink
Merge pull request #57 from LiveOakLabs/changelog-attrs
Browse files Browse the repository at this point in the history
changelog type is optional
  • Loading branch information
joshbeard authored Feb 14, 2024
2 parents ded4a7b + 2724fce commit a04485e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
6 changes: 3 additions & 3 deletions readme/changelog.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ type ChangelogParams struct {
// validChangelogType validates the 'type' field when creating or updating a changelog.
func validChangelogType(changelogType string) bool {
switch changelogType {
case "added", "fixed", "improved", "deprecated", "removed":
case "", "added", "fixed", "improved", "deprecated", "removed":
return true
}

Expand Down Expand Up @@ -144,7 +144,7 @@ func (c ChangelogClient) Create(params ChangelogParams) (Changelog, *APIResponse
return Changelog{}, nil, fmt.Errorf("title must be provided")
}
if !validChangelogType(params.Type) {
return Changelog{}, nil, fmt.Errorf("type must be added, fixed, improved, deprecated, or removed")
return Changelog{}, nil, fmt.Errorf("type must be added, fixed, improved, deprecated, removed, or left unspecified")
}

payload, err := json.Marshal(params)
Expand Down Expand Up @@ -174,7 +174,7 @@ func (c ChangelogClient) Update(slug string, params ChangelogParams) (Changelog,
return Changelog{}, nil, fmt.Errorf("title must be provided")
}
if !validChangelogType(params.Type) {
return Changelog{}, nil, fmt.Errorf("type must be added, fixed, improved, deprecated, or removed")
return Changelog{}, nil, fmt.Errorf("type must be added, fixed, improved, deprecated, removed, or left unspecified")
}

payload, err := json.Marshal(params)
Expand Down
24 changes: 22 additions & 2 deletions readme/changelog_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func Test_Changelog_Create(t *testing.T) {

// Assert
assert.ErrorContains(t, err,
"type must be added, fixed, improved, deprecated, or removed",
"type must be added, fixed, improved, deprecated, removed, or left unspecified",
"it returns the expected error",
)
assert.True(t, gock.IsDone(), "it makes the expected API call")
Expand Down Expand Up @@ -155,10 +155,30 @@ func Test_Changelog_Update(t *testing.T) {

// Assert
assert.ErrorContains(t, err,
"type must be added, fixed, improved, deprecated, or removed",
"type must be added, fixed, improved, deprecated, removed, or left unspecified",
"it returns the expected error",
)
})

t.Run("when called with no type", func(t *testing.T) {
// Arrange
expect := testdata.Changelogs[0]
gock.New(TestClient.APIURL).
Put(readme.ChangelogEndpoint + "/" + expect.Slug).
Reply(200).
JSON(testdata.Changelogs[0])
defer gock.Off()

// Act
_, _, err := TestClient.Changelog.Update("some-test", readme.ChangelogParams{
Title: testdata.Changelogs[0].Title,
Body: testdata.Changelogs[0].Body,
Hidden: &testdata.Changelogs[0].Hidden,
})

// Assert
assert.NoError(t, err, "it does not return an error")
})
}

func Test_Changelog_Delete(t *testing.T) {
Expand Down

0 comments on commit a04485e

Please sign in to comment.