Skip to content

Commit 8f108f1

Browse files
authored
fix: availableFrom now set to correct month for Import Previews (#788)
Resolves #786.
1 parent 68ebbb9 commit 8f108f1

File tree

4 files changed

+31
-4
lines changed

4 files changed

+31
-4
lines changed

pkg/controllers/import_test.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"path"
1212
"testing"
1313

14+
"github.com/envelope-zero/backend/v3/internal/types"
1415
"github.com/envelope-zero/backend/v3/pkg/controllers"
1516
"github.com/envelope-zero/backend/v3/pkg/models"
1617
"github.com/envelope-zero/backend/v3/test"
@@ -175,6 +176,22 @@ func (suite *TestSuiteStandard) TestYnabImportPreviewDuplicateDetection() {
175176
suite.Assert().Equal(transaction.Data.ID, preview.Data[0].DuplicateTransactionIDs[0], "Duplicate transaction ID is not ID of the transaction that is duplicated")
176177
}
177178

179+
func (suite *TestSuiteStandard) TestYnabImportAvailableFrom() {
180+
// Create test account
181+
account := suite.createTestAccount(models.AccountCreate{Name: "TestYnabImportAvailableFrom"})
182+
preview := parseCSV(suite, account.Data.ID, "available-from-test.csv")
183+
184+
dates := []types.Month{
185+
types.NewMonth(2019, 2),
186+
types.NewMonth(2019, 4),
187+
types.NewMonth(2019, 5),
188+
}
189+
190+
for i, transaction := range preview.Data {
191+
assert.Equal(suite.T(), dates[i], transaction.Transaction.AvailableFrom)
192+
}
193+
}
194+
178195
func parseCSV(suite *TestSuiteStandard, accountID uuid.UUID, file string) controllers.ImportPreviewList {
179196
path := fmt.Sprintf("ynab-import-preview?accountId=%s", accountID.String())
180197

pkg/importer/parser/ynab-import/parse.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"strings"
99
"time"
1010

11+
"github.com/envelope-zero/backend/v3/internal/types"
1112
"github.com/envelope-zero/backend/v3/pkg/importer"
1213
"github.com/envelope-zero/backend/v3/pkg/importer/helpers"
1314
"github.com/envelope-zero/backend/v3/pkg/models"
@@ -45,10 +46,11 @@ func Parse(f io.Reader, account models.Account) ([]importer.TransactionPreview,
4546

4647
t := importer.TransactionPreview{
4748
Transaction: models.TransactionCreate{
48-
Date: date,
49-
ImportHash: helpers.Sha256String(strings.Join(record, ",")),
50-
Note: record[Memo],
51-
BudgetID: account.BudgetID,
49+
Date: date,
50+
AvailableFrom: types.NewMonth(date.Year(), date.Month()),
51+
ImportHash: helpers.Sha256String(strings.Join(record, ",")),
52+
Note: record[Memo],
53+
BudgetID: account.BudgetID,
5254
},
5355
}
5456

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Date,Payee,Memo,Outflow,Inflow
2+
02/28/2019,EDEKA Schmidt,Glob Test,59.97,
3+
04/30/2019,DB Vertrieb GmbH,Glob Train ticket,80.00,
4+
05/25/2019,Some Company,Glob Salary April 2019,,2350
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Date,Payee,Memo,Outflow,Inflow
2+
04/01/2019,EDEKA Schmidt,Glob Test,59.97,
3+
04/01/2019,DB Vertrieb GmbH,Glob Train ticket,80.00,
4+
04/25/2019,Some Company,Glob Salary April 2019,,2350

0 commit comments

Comments
 (0)