Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
garrettladley committed Jan 21, 2024
1 parent 326338a commit 0fb99d0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 18 deletions.
4 changes: 2 additions & 2 deletions backend/tests/api/category_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func CreateSampleCategory(t *testing.T, categoryName string) ExistingAppAssert {
Body: &map[string]interface{}{
"category_name": categoryName,
},
}.TestOnStatusAndDBKeepDB(t, nil,
}.TestOnStatusAndDB(t, nil,
DBTesterWithStatus{
Status: 201,
DBTester: func(app TestApp, assert *assert.A, resp *http.Response) {
Expand Down Expand Up @@ -137,7 +137,7 @@ func TestCreateCategoryFailsIfCategoryWithThatNameAlreadyExists(t *testing.T) {
Body: &map[string]interface{}{
"category_name": permutation,
},
}.TestOnStatusMessageAndDBKeepDB(t, &existingAppAssert,
}.TestOnStatusMessageAndDB(t, &existingAppAssert,
StatusMessageDBTester{
MessageWithStatus: MessageWithStatus{
Status: 400,
Expand Down
20 changes: 4 additions & 16 deletions backend/tests/api/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,11 +192,7 @@ type MessageWithStatus struct {
Message string
}

func (request TestRequest) TestOnStatusAndMessage(t *testing.T, existingAppAssert *ExistingAppAssert, messagedStatus MessageWithStatus) {
request.TestOnStatusAndMessageKeepDB(t, existingAppAssert, messagedStatus)
}

func (request TestRequest) TestOnStatusAndMessageKeepDB(t *testing.T, existingAppAssert *ExistingAppAssert, messagedStatus MessageWithStatus) ExistingAppAssert {
func (request TestRequest) TestOnStatusAndMessage(t *testing.T, existingAppAssert *ExistingAppAssert, messagedStatus MessageWithStatus) ExistingAppAssert {
appAssert, resp := request.TestWithJSONBody(t, existingAppAssert)
assert := appAssert.Assert

Expand All @@ -220,12 +216,8 @@ type StatusMessageDBTester struct {
DBTester DBTester
}

func (request TestRequest) TestOnStatusMessageAndDB(t *testing.T, existingAppAssert *ExistingAppAssert, statusMessageDBTester StatusMessageDBTester) {
request.TestOnStatusMessageAndDBKeepDB(t, existingAppAssert, statusMessageDBTester)
}

func (request TestRequest) TestOnStatusMessageAndDBKeepDB(t *testing.T, existingAppAssert *ExistingAppAssert, statusMessageDBTester StatusMessageDBTester) ExistingAppAssert {
appAssert := request.TestOnStatusAndMessageKeepDB(t, existingAppAssert, statusMessageDBTester.MessageWithStatus)
func (request TestRequest) TestOnStatusMessageAndDB(t *testing.T, existingAppAssert *ExistingAppAssert, statusMessageDBTester StatusMessageDBTester) ExistingAppAssert {
appAssert := request.TestOnStatusAndMessage(t, existingAppAssert, statusMessageDBTester.MessageWithStatus)
statusMessageDBTester.DBTester(appAssert.App, appAssert.Assert, nil)
return appAssert
}
Expand All @@ -237,11 +229,7 @@ type DBTesterWithStatus struct {
DBTester
}

func (request TestRequest) TestOnStatusAndDB(t *testing.T, existingAppAssert *ExistingAppAssert, dbTesterStatus DBTesterWithStatus) {
request.TestOnStatusAndDBKeepDB(t, existingAppAssert, dbTesterStatus)
}

func (request TestRequest) TestOnStatusAndDBKeepDB(t *testing.T, existingAppAssert *ExistingAppAssert, dbTesterStatus DBTesterWithStatus) ExistingAppAssert {
func (request TestRequest) TestOnStatusAndDB(t *testing.T, existingAppAssert *ExistingAppAssert, dbTesterStatus DBTesterWithStatus) ExistingAppAssert {
appAssert, resp := request.TestWithJSONBody(t, existingAppAssert)
app, assert := appAssert.App, appAssert.Assert
defer resp.Body.Close()
Expand Down

0 comments on commit 0fb99d0

Please sign in to comment.