|
4 | 4 | "fmt" |
5 | 5 | "net/http" |
6 | 6 | "testing" |
| 7 | + "time" |
7 | 8 |
|
8 | 9 | "github.com/envelope-zero/backend/pkg/controllers" |
9 | 10 | "github.com/envelope-zero/backend/pkg/models" |
@@ -107,6 +108,25 @@ func (suite *TestSuiteEnv) TestCreateTransaction() { |
107 | 108 | _ = createTestTransaction(suite.T(), models.TransactionCreate{Note: "More tests something something", Amount: decimal.NewFromFloat(1253.17)}) |
108 | 109 | } |
109 | 110 |
|
| 111 | +func (suite *TestSuiteEnv) TestTransactionSorting() { |
| 112 | + tFebrurary := createTestTransaction(suite.T(), models.TransactionCreate{Note: "Should be second in the list", Amount: decimal.NewFromFloat(1253.17), Date: time.Date(2022, 2, 15, 0, 0, 0, 0, time.UTC)}) |
| 113 | + |
| 114 | + tMarch := createTestTransaction(suite.T(), models.TransactionCreate{Note: "Should be first in the list", Amount: decimal.NewFromFloat(1253.17), Date: time.Date(2022, 3, 15, 0, 0, 0, 0, time.UTC)}) |
| 115 | + |
| 116 | + tJanuary := createTestTransaction(suite.T(), models.TransactionCreate{Note: "Should be third in the list", Amount: decimal.NewFromFloat(1253.17), Date: time.Date(2022, 1, 15, 0, 0, 0, 0, time.UTC)}) |
| 117 | + |
| 118 | + r := test.Request(suite.T(), http.MethodGet, "http://example.com/v1/transactions", "") |
| 119 | + test.AssertHTTPStatus(suite.T(), http.StatusOK, &r) |
| 120 | + |
| 121 | + var transactions controllers.TransactionListResponse |
| 122 | + test.DecodeResponse(suite.T(), &r, &transactions) |
| 123 | + |
| 124 | + assert.Len(suite.T(), transactions.Data, 3, "There are not exactly three transactions") |
| 125 | + assert.Equal(suite.T(), tMarch.Data.Date, transactions.Data[0].Date, "The first transaction is not the March transaction") |
| 126 | + assert.Equal(suite.T(), tFebrurary.Data.Date, transactions.Data[1].Date, "The second transaction is not the February transaction") |
| 127 | + assert.Equal(suite.T(), tJanuary.Data.Date, transactions.Data[2].Date, "The third transaction is not the January transaction") |
| 128 | +} |
| 129 | + |
110 | 130 | func (suite *TestSuiteEnv) TestCreateTransactionMissingReference() { |
111 | 131 | budget := createTestBudget(suite.T(), models.BudgetCreate{}) |
112 | 132 | category := createTestCategory(suite.T(), models.CategoryCreate{BudgetID: budget.Data.ID}) |
|
0 commit comments