|
| 1 | +package controllers_test |
| 2 | + |
| 3 | +import ( |
| 4 | + "net/http" |
| 5 | + |
| 6 | + "github.com/envelope-zero/backend/pkg/models" |
| 7 | + "github.com/envelope-zero/backend/pkg/test" |
| 8 | + "github.com/shopspring/decimal" |
| 9 | +) |
| 10 | + |
| 11 | +func (suite *TestSuiteEnv) TestCleanup() { |
| 12 | + _ = createTestBudget(suite.T(), models.BudgetCreate{}) |
| 13 | + _ = createTestAccount(suite.T(), models.AccountCreate{}) |
| 14 | + _ = createTestCategory(suite.T(), models.CategoryCreate{}) |
| 15 | + _ = createTestEnvelope(suite.T(), models.EnvelopeCreate{}) |
| 16 | + _ = createTestAllocation(suite.T(), models.AllocationCreate{}) |
| 17 | + _ = createTestTransaction(suite.T(), models.TransactionCreate{Amount: decimal.NewFromFloat(17.32)}) |
| 18 | + |
| 19 | + tests := []string{ |
| 20 | + "http://example.com/v1/budgets", |
| 21 | + "http://example.com/v1/accounts", |
| 22 | + "http://example.com/v1/categories", |
| 23 | + "http://example.com/v1/transactions", |
| 24 | + "http://example.com/v1/envelopes", |
| 25 | + "http://example.com/v1/allocations", |
| 26 | + } |
| 27 | + |
| 28 | + // Delete |
| 29 | + recorder := test.Request(suite.T(), http.MethodDelete, "http://example.com/v1", "") |
| 30 | + test.AssertHTTPStatus(suite.T(), http.StatusNoContent, &recorder) |
| 31 | + |
| 32 | + // Verify |
| 33 | + for _, tt := range tests { |
| 34 | + suite.Run(tt, func() { |
| 35 | + recorder := test.Request(suite.T(), http.MethodGet, tt, "") |
| 36 | + test.AssertHTTPStatus(suite.T(), http.StatusOK, &recorder) |
| 37 | + |
| 38 | + var response struct { |
| 39 | + Data []any `json:"data"` |
| 40 | + } |
| 41 | + |
| 42 | + test.DecodeResponse(suite.T(), &recorder, &response) |
| 43 | + suite.Assert().Len(response.Data, 0, "There are resources left for type %s", tt) |
| 44 | + }) |
| 45 | + } |
| 46 | +} |
0 commit comments