|
5 | 5 | "testing" |
6 | 6 | "time" |
7 | 7 |
|
| 8 | + "github.com/envelope-zero/backend/v3/internal/types" |
8 | 9 | "github.com/envelope-zero/backend/v3/pkg/models" |
9 | 10 | "github.com/google/uuid" |
10 | 11 | "github.com/stretchr/testify/assert" |
@@ -120,3 +121,24 @@ func (suite *TestSuiteStandard) TestTransactionReconciled() { |
120 | 121 | func (suite *TestSuiteStandard) TestTransactionSelf() { |
121 | 122 | assert.Equal(suite.T(), "Transaction", models.Transaction{}.Self()) |
122 | 123 | } |
| 124 | + |
| 125 | +// Regression test for https://github.com/envelope-zero/backend/issues/768 |
| 126 | +func (suite *TestSuiteStandard) TestTransactionAvailableFromDate() { |
| 127 | + budget := suite.createTestBudget(models.BudgetCreate{}) |
| 128 | + internalAccount := suite.createTestAccount(models.AccountCreate{External: false, BudgetID: budget.ID}) |
| 129 | + externalAccount := suite.createTestAccount(models.AccountCreate{External: true, BudgetID: budget.ID}) |
| 130 | + |
| 131 | + transaction := models.Transaction{ |
| 132 | + TransactionCreate: models.TransactionCreate{ |
| 133 | + SourceAccountID: externalAccount.ID, |
| 134 | + DestinationAccountID: internalAccount.ID, |
| 135 | + Note: "TestTransactionAvailableFromDate", |
| 136 | + AvailableFrom: types.NewMonth(2023, 9), |
| 137 | + Date: time.Date(2023, 10, 7, 0, 0, 0, 0, time.UTC), |
| 138 | + }, |
| 139 | + } |
| 140 | + |
| 141 | + err := suite.db.Save(&transaction).Error |
| 142 | + suite.Assert().NotNil(err, "Saving a transaction with an AvailableFrom date in a month before the transaction date should not be possible") |
| 143 | + suite.Assert().Contains(err.Error(), "availability month must not be earlier than the month of the transaction") |
| 144 | +} |
0 commit comments