Skip to content

Commit 00ca412

Browse files
authored
fix: clean up MonthConfigs with DELETE /v1 (#442)
1 parent 402df4d commit 00ca412

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

pkg/controllers/cleanup.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,5 +51,11 @@ func (co Controller) DeleteAll(c *gin.Context) {
5151
return
5252
}
5353

54+
err = co.DB.Unscoped().Where("true").Delete(&models.MonthConfig{}).Error
55+
if err != nil {
56+
httperrors.Handler(c, err)
57+
return
58+
}
59+
5460
c.JSON(http.StatusNoContent, gin.H{})
5561
}

pkg/controllers/cleanup_test.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,23 @@ package controllers_test
22

33
import (
44
"net/http"
5+
"testing"
6+
"time"
57

68
"github.com/envelope-zero/backend/pkg/models"
79
"github.com/envelope-zero/backend/test"
810
"github.com/shopspring/decimal"
11+
"github.com/stretchr/testify/assert"
912
)
1013

1114
func (suite *TestSuiteStandard) TestCleanup() {
1215
_ = suite.createTestBudget(models.BudgetCreate{})
1316
_ = suite.createTestAccount(models.AccountCreate{})
1417
_ = suite.createTestCategory(models.CategoryCreate{})
15-
_ = suite.createTestEnvelope(models.EnvelopeCreate{})
18+
envelope := suite.createTestEnvelope(models.EnvelopeCreate{})
1619
_ = suite.createTestAllocation(models.AllocationCreate{})
1720
_ = suite.createTestTransaction(models.TransactionCreate{Amount: decimal.NewFromFloat(17.32)})
21+
_ = suite.createTestMonthConfig(envelope.Data.ID, time.Now(), models.MonthConfigCreate{})
1822

1923
tests := []string{
2024
"http://example.com/v1/budgets",
@@ -23,6 +27,7 @@ func (suite *TestSuiteStandard) TestCleanup() {
2327
"http://example.com/v1/transactions",
2428
"http://example.com/v1/envelopes",
2529
"http://example.com/v1/allocations",
30+
"http://example.com/v1/month-configs",
2631
}
2732

2833
// Delete
@@ -31,7 +36,7 @@ func (suite *TestSuiteStandard) TestCleanup() {
3136

3237
// Verify
3338
for _, tt := range tests {
34-
suite.Run(tt, func() {
39+
suite.T().Run(tt, func(t *testing.T) {
3540
recorder := test.Request(suite.controller, suite.T(), http.MethodGet, tt, "")
3641
suite.assertHTTPStatus(&recorder, http.StatusOK)
3742

@@ -40,7 +45,7 @@ func (suite *TestSuiteStandard) TestCleanup() {
4045
}
4146

4247
suite.decodeResponse(&recorder, &response)
43-
suite.Assert().Len(response.Data, 0, "There are resources left for type %s", tt)
48+
assert.Len(t, response.Data, 0, "There are resources left for type %s", tt)
4449
})
4550
}
4651
}

0 commit comments

Comments
 (0)