mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Fixes for import test
This commit is contained in:
parent
5a1df67e11
commit
09c2c40903
@ -90,6 +90,8 @@ class CSVImport implements ShouldQueue
|
|||||||
ksort($this->column_map);
|
ksort($this->column_map);
|
||||||
|
|
||||||
$this->{"import".ucfirst($this->entity_type)}();
|
$this->{"import".ucfirst($this->entity_type)}();
|
||||||
|
|
||||||
|
info(print_r($this->maps,1));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function failed($exception)
|
public function failed($exception)
|
||||||
@ -100,7 +102,7 @@ class CSVImport implements ShouldQueue
|
|||||||
|
|
||||||
private function importProduct()
|
private function importProduct()
|
||||||
{
|
{
|
||||||
info("importing product");
|
info("importing products");
|
||||||
$product_repository = new ProductRepository();
|
$product_repository = new ProductRepository();
|
||||||
$product_transformer = new ProductTransformer($this->maps);
|
$product_transformer = new ProductTransformer($this->maps);
|
||||||
|
|
||||||
@ -113,16 +115,12 @@ class CSVImport implements ShouldQueue
|
|||||||
{
|
{
|
||||||
$keys = $this->column_map;
|
$keys = $this->column_map;
|
||||||
$values = array_intersect_key($record, $this->column_map);
|
$values = array_intersect_key($record, $this->column_map);
|
||||||
|
|
||||||
|
|
||||||
info(print_r($keys,1));
|
|
||||||
info(print_r($values,1));
|
|
||||||
|
|
||||||
$product_data = array_combine($keys, $values);
|
$product_data = array_combine($keys, $values);
|
||||||
|
|
||||||
$product = $product_transformer->transform($product_data);
|
$product = $product_transformer->transform($product_data);
|
||||||
|
|
||||||
$validator = Validator::make($client, (new StoreProductRequest())->rules());
|
$validator = Validator::make($product, (new StoreProductRequest())->rules());
|
||||||
|
|
||||||
if ($validator->fails()) {
|
if ($validator->fails()) {
|
||||||
$this->error_array[] = ['product' => $product, 'error' => json_encode($validator->errors())];
|
$this->error_array[] = ['product' => $product, 'error' => json_encode($validator->errors())];
|
||||||
|
@ -11,6 +11,8 @@
|
|||||||
namespace Tests\Feature\Import;
|
namespace Tests\Feature\Import;
|
||||||
|
|
||||||
use App\Jobs\Import\CSVImport;
|
use App\Jobs\Import\CSVImport;
|
||||||
|
use App\Models\Client;
|
||||||
|
use App\Models\Product;
|
||||||
use App\Utils\Traits\MakesHash;
|
use App\Utils\Traits\MakesHash;
|
||||||
use Illuminate\Routing\Middleware\ThrottleRequests;
|
use Illuminate\Routing\Middleware\ThrottleRequests;
|
||||||
use Illuminate\Support\Facades\Cache;
|
use Illuminate\Support\Facades\Cache;
|
||||||
@ -74,10 +76,13 @@ class ImportCsvTest extends TestCase
|
|||||||
'entity_type'=> 'client',
|
'entity_type'=> 'client',
|
||||||
];
|
];
|
||||||
|
|
||||||
|
$pre_import = Client::count();
|
||||||
|
|
||||||
Cache::put($hash, base64_encode($csv), 360);
|
Cache::put($hash, base64_encode($csv), 360);
|
||||||
|
|
||||||
$this->markTestSkipped();
|
CSVImport::dispatchNow($data, $this->company);
|
||||||
// CSVImport::dispatchNow($data, $this->company);
|
|
||||||
|
$this->assertGreaterThan($pre_import, Client::count());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -85,11 +90,10 @@ class ImportCsvTest extends TestCase
|
|||||||
{
|
{
|
||||||
$csv = file_get_contents(base_path().'/tests/Feature/Import/products.csv');
|
$csv = file_get_contents(base_path().'/tests/Feature/Import/products.csv');
|
||||||
$hash = Str::random(32);
|
$hash = Str::random(32);
|
||||||
|
|
||||||
$column_map = [
|
$column_map = [
|
||||||
1 => 'product.product_key',
|
|
||||||
2 => 'product.notes',
|
2 => 'product.notes',
|
||||||
3 => 'product.cost',
|
3 => 'product.cost',
|
||||||
4 => 'product.user_id',
|
|
||||||
];
|
];
|
||||||
|
|
||||||
$data = [
|
$data = [
|
||||||
@ -99,10 +103,14 @@ class ImportCsvTest extends TestCase
|
|||||||
'entity_type'=> 'product',
|
'entity_type'=> 'product',
|
||||||
];
|
];
|
||||||
|
|
||||||
|
$pre_import = Product::count();
|
||||||
|
|
||||||
Cache::put($hash, base64_encode($csv), 360);
|
Cache::put($hash, base64_encode($csv), 360);
|
||||||
$this->markTestSkipped();
|
|
||||||
|
|
||||||
CSVImport::dispatchNow($data, $this->company);
|
CSVImport::dispatchNow($data, $this->company);
|
||||||
|
|
||||||
|
$this->assertGreaterThan($pre_import, Product::count());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getCsvData($csvfile)
|
private function getCsvData($csvfile)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user