mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-24 02:14:21 -04:00
Tests for importing CSV files
This commit is contained in:
parent
584bef52fc
commit
3419d7900f
@ -38,6 +38,17 @@ class ImportController extends Controller
|
||||
* @OA\Parameter(ref="#/components/parameters/X-Api-Token"),
|
||||
* @OA\Parameter(ref="#/components/parameters/X-Requested-With"),
|
||||
* @OA\Parameter(ref="#/components/parameters/include"),
|
||||
* @OA\RequestBody(
|
||||
* description="The CSV file",
|
||||
* required=true,
|
||||
* @OA\MediaType(
|
||||
* mediaType="multipart/form-data",
|
||||
* @OA\Schema(
|
||||
* type="string",
|
||||
* format="binary"
|
||||
* )
|
||||
* )
|
||||
* ),
|
||||
* @OA\Response(
|
||||
* response=200,
|
||||
* description="Returns a reference to the file",
|
||||
@ -68,6 +79,13 @@ class ImportController extends Controller
|
||||
|
||||
//parse CSV
|
||||
$csv_array = $this->getCsvData(file_get_contents($request->file('file')->getPathname()));
|
||||
|
||||
$data['data'] = [
|
||||
'hash' => $hash,
|
||||
'headers' => array_slice($csv_array, 0, 2)
|
||||
];
|
||||
|
||||
return response()->json($data);
|
||||
}
|
||||
|
||||
|
||||
@ -79,7 +97,6 @@ class ImportController extends Controller
|
||||
}
|
||||
|
||||
$csv = Reader::createFromString($csvfile);
|
||||
//$csv->setHeaderOffset(0); //set the CSV header offset
|
||||
$stmt = new Statement();
|
||||
$data = iterator_to_array($stmt->process($csv));
|
||||
|
||||
|
@ -37,10 +37,9 @@ class ImportCsvTest extends TestCase
|
||||
ThrottleRequests::class
|
||||
);
|
||||
|
||||
$this->faker = \Faker\Factory::create();
|
||||
// $this->faker = \Faker\Factory::create();
|
||||
|
||||
|
||||
$this->makeTestData();
|
||||
// $this->makeTestData();
|
||||
|
||||
$this->withoutExceptionHandling();
|
||||
}
|
||||
@ -49,7 +48,7 @@ class ImportCsvTest extends TestCase
|
||||
{
|
||||
$csv = file_get_contents(base_path().'/tests/Feature/Import/invoice.csv');
|
||||
|
||||
return $this->getCsvData($csv);
|
||||
$this->assertTrue(is_array($this->getCsvData($csv)));
|
||||
}
|
||||
|
||||
|
||||
@ -61,7 +60,6 @@ class ImportCsvTest extends TestCase
|
||||
}
|
||||
|
||||
$csv = Reader::createFromString($csvfile);
|
||||
//$csv->setHeaderOffset(0); //set the CSV header offset
|
||||
$stmt = new Statement();
|
||||
$data = iterator_to_array($stmt->process($csv));
|
||||
|
||||
@ -78,7 +76,7 @@ class ImportCsvTest extends TestCase
|
||||
}
|
||||
}
|
||||
}
|
||||
info(print_r($data,1));
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user