Skip to content

Firefly III: a personal finances manager

New tests.

James Cole7ecd691ee203
diff --git a/app/Http/Controllers/ImportController.php b/app/Http/Controllers/ImportController.php
index bbf09436c2..d854f141d9 100644
--- a/app/Http/Controllers/ImportController.php
+++ b/app/Http/Controllers/ImportController.php
@@ -318,7 +318,8 @@ class ImportController extends Controller
{
set_time_limit(0);
if ($job->status == 'settings_complete') {
- ImportProcedure::runImport($job);
+ $importProcedure = new ImportProcedure;
+ $importProcedure->runImport($job);
}
}
diff --git a/app/Import/ImportProcedure.php b/app/Import/ImportProcedure.php
index ae6b2cf910..dd3878a01b 100644
--- a/app/Import/ImportProcedure.php
+++ b/app/Import/ImportProcedure.php
@@ -31,7 +31,7 @@ class ImportProcedure
*
* @return Collection
*/
- public static function runImport(ImportJob $job): Collection
+ public function runImport(ImportJob $job): Collection
{
// update job to say we started.
$job->status = 'import_running';
diff --git a/app/Support/Migration/TestData.php b/app/Support/Migration/TestData.php
index d6f510642f..dab024765c 100644
--- a/app/Support/Migration/TestData.php
+++ b/app/Support/Migration/TestData.php
@@ -292,9 +292,12 @@ class TestData
*/
private function createImportJobs()
{
+
+ $disk = Storage::disk('upload');
$insert = [];
foreach ($this->data['import-jobs'] as $job) {
- $insert[] = [
+ $insert[]
+ = [
'created_at' => $this->time,
'updated_at' => $this->time,
'user_id' => $job['user_id'],
@@ -304,6 +307,8 @@ class TestData
'extended_status' => json_encode($job['extended_status']),
'configuration' => json_encode($job['configuration']),
];
+
+ $disk->put($job['key'] . '.upload', Crypt::encrypt(''));
}
DB::table('import_jobs')->insert($insert);
}
diff --git a/resources/seeds/seed.testing.json b/resources/seeds/seed.testing.json
index 7f1f8a811d..5411ed03a1 100644
--- a/resources/seeds/seed.testing.json
+++ b/resources/seeds/seed.testing.json
@@ -1085,6 +1085,10 @@
"importTag": 0
},
"configuration": {
+ "has-headers": false,
+ "date-format": "Ymd",
+ "delimiter": ",",
+ "import-account": 1
}
},
{
diff --git a/resources/stubs/csv.csv b/resources/stubs/csv.csv
new file mode 100644
index 0000000000..05de7d7338
--- /dev/null
+++ b/resources/stubs/csv.csv
@@ -0,0 +1,3 @@
+Header
+Value
+Value
\ No newline at end of file
diff --git a/tests/acceptance/Controllers/ImportControllerTest.php b/tests/acceptance/Controllers/ImportControllerTest.php
index 8437b851e9..bec5fc7dd9 100644
--- a/tests/acceptance/Controllers/ImportControllerTest.php
+++ b/tests/acceptance/Controllers/ImportControllerTest.php
@@ -9,6 +9,7 @@
* See the LICENSE file for details.
*/
use FireflyIII\Import\Setup\CsvSetup;
+use Illuminate\Http\UploadedFile;
/**
@@ -124,7 +125,6 @@ class ImportControllerTest extends TestCase
/**
* @covers \FireflyIII\Http\Controllers\ImportController::settings
- * Implement testSettings().
*/
public function testSettings()
{
@@ -139,14 +139,12 @@ class ImportControllerTest extends TestCase
/**
* @covers \FireflyIII\Http\Controllers\ImportController::start
- * Implement testStart().
*/
public function testStart()
{
- // Remove the following lines when you implement this test.
- $this->markTestIncomplete(
- 'This test has not been implemented yet.'
- );
+ $this->be($this->user());
+ $this->call('post', route('import.start', ['complete']));
+ $this->assertResponseStatus(200);
}
/**
@@ -155,21 +153,20 @@ class ImportControllerTest extends TestCase
*/
public function testStatus()
{
- // Remove the following lines when you implement this test.
- $this->markTestIncomplete(
- 'This test has not been implemented yet.'
- );
+ // complete
+ $this->be($this->user());
+ $this->call('get', route('import.status', ['complete']));
+ $this->assertResponseStatus(302);
}
/**
* @covers \FireflyIII\Http\Controllers\ImportController::upload
- * Implement testUpload().
*/
public function testUpload()
{
- // Remove the following lines when you implement this test.
- $this->markTestIncomplete(
- 'This test has not been implemented yet.'
- );
+ $path = resource_path('stubs/csv.csv');
+ $file = new UploadedFile($path, 'upload.csv', filesize($path), 'text/csv', null, true);
+ $this->call('POST', route('import.upload'), [], [], ['import_file' => $file], ['Accept' => 'application/json']);
+ $this->assertResponseStatus(302);
}
}