From a7e3ffb3a6f55a6aa9da511dee829e118418c4c7 Mon Sep 17 00:00:00 2001 From: Dara Keon Date: Tue, 17 Sep 2024 19:57:17 +0100 Subject: [PATCH] tests: ensure exported file can be imported --- .../H.Attendant/f.ImportMovesFile.feature | 27 +++++++++++++++++++ .../Tests/BusinessLogic/Steps/_D.RobotStep.cs | 20 ++++++++++++-- docs/todo/importer-exporter.md | 2 +- 3 files changed, 46 insertions(+), 3 deletions(-) diff --git a/core/Tests/BusinessLogic/H.Attendant/f.ImportMovesFile.feature b/core/Tests/BusinessLogic/H.Attendant/f.ImportMovesFile.feature index 4d89e21c5..fe4730fb2 100644 --- a/core/Tests/BusinessLogic/H.Attendant/f.ImportMovesFile.feature +++ b/core/Tests/BusinessLogic/H.Attendant/f.ImportMovesFile.feature @@ -817,3 +817,30 @@ Scenario: Hf84. Too long file name Then I will receive this core error: InvalidArchiveName And the pre-import data will not be recorded And the lines will not be queued + +Scenario: Hf85. Import exported file + Given I have moves of + | Description | Date | Category | Nature | Out | In | Value | Conversion | Detail | + | Sample Move Out | 2024-09-16 | Category | Out | Account Out | | 1 | | | + | Sample Move Out with Details | 2024-09-16 | Category | Out | Account Out | | 1 | | D1 | + | Sample Move In | 2024-09-16 | Category | In | | Account In | 1 | | | + | Sample Move In with Details | 2024-09-16 | Category | In | | Account In | 1 | | D1 | + | Sample Move Transfer | 2024-09-16 | Category | Transfer | Account Out | Account In | 1 | | | + | Sample Move Transfer with Details | 2024-09-16 | Category | Transfer | Account Out | Account In | 1 | | D1 | + | Sample Move Transfer with Conversion | 2024-09-16 | Category | Transfer | Account Out EUR | Account In BRL | 1 | 10 | | + | Sample Move Transfer with Conversion and Details | 2024-09-16 | Category | Transfer | Account Out EUR | Account In BRL | 1 | 10 | D1 | + And order start date 2024-09-16 + And order end date 2024-09-16 + And order account account_out + And order account account_in + And order account account_out_eur + And order account account_in_brl + And order category Category + And an export is ordered + And robot export the order + And test user login + And the order file is chosen to import + When import moves file + Then I will receive no core error + And the pre-import data will be recorded + And the lines will be queued diff --git a/core/Tests/BusinessLogic/Steps/_D.RobotStep.cs b/core/Tests/BusinessLogic/Steps/_D.RobotStep.cs index 748174dc0..140e61e67 100644 --- a/core/Tests/BusinessLogic/Steps/_D.RobotStep.cs +++ b/core/Tests/BusinessLogic/Steps/_D.RobotStep.cs @@ -745,6 +745,19 @@ public void GivenTheFileNameIsCharactersLong(Int32 nameSize) csvName = $"{new String('D', nameSize - 4)}.csv"; } + [Given(@"the order file is chosen to import")] + public void GivenTheOrderFileIsChosenToImport() + { + var user = repos.User.GetByEmail(userEmail); + var order = repos.Order.ByUser(user).Single(); + + csvName = order.Path; + + var fakeS3Path = Path.Combine(Cfg.S3.Directory, order.Path); + + csvContent = File.ReadAllText(fakeS3Path); + } + [When(@"import moves file")] public void WhenImportMovesFile() { @@ -780,8 +793,11 @@ public void ThenThePreImportDataWillBeRecorded() var actual = CSVHelper.ToCsv(line, hasConversion); var expected = csvLines[l + 1]; - while (expected.EndsWith(",,,")) - expected = expected.Substring(0, expected.Length - 3); + while (expected.EndsWith(",")) + expected = expected[..^1]; + + while (actual.EndsWith(",")) + actual = actual[..^1]; Assert.That(actual, Is.EqualTo(expected)); } diff --git a/docs/todo/importer-exporter.md b/docs/todo/importer-exporter.md index 47446f2a0..3332466f0 100644 --- a/docs/todo/importer-exporter.md +++ b/docs/todo/importer-exporter.md @@ -28,7 +28,7 @@ - [x] Allow retry orders - [x] Allow cancel orders - [x] Record order creation / export and show -- [ ] Exported can be imported +- [x] Exported can be imported - [ ] Integrate to site - [ ] Integrate to robot