diff --git a/app/Jobs/Import/CSVImport.php b/app/Jobs/Import/CSVImport.php index 23b287364d0e..5ca5d4d746b2 100644 --- a/app/Jobs/Import/CSVImport.php +++ b/app/Jobs/Import/CSVImport.php @@ -90,6 +90,8 @@ class CSVImport implements ShouldQueue ksort($this->column_map); $this->{"import".ucfirst($this->entity_type)}(); + + info(print_r($this->maps,1)); } public function failed($exception) @@ -100,7 +102,7 @@ class CSVImport implements ShouldQueue private function importProduct() { - info("importing product"); + info("importing products"); $product_repository = new ProductRepository(); $product_transformer = new ProductTransformer($this->maps); @@ -113,16 +115,12 @@ class CSVImport implements ShouldQueue { $keys = $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 = $product_transformer->transform($product_data); - $validator = Validator::make($client, (new StoreProductRequest())->rules()); + $validator = Validator::make($product, (new StoreProductRequest())->rules()); if ($validator->fails()) { $this->error_array[] = ['product' => $product, 'error' => json_encode($validator->errors())]; diff --git a/tests/Feature/Import/ImportCsvTest.php b/tests/Feature/Import/ImportCsvTest.php index 7926a6a40491..1ab264fbfc84 100644 --- a/tests/Feature/Import/ImportCsvTest.php +++ b/tests/Feature/Import/ImportCsvTest.php @@ -11,6 +11,8 @@ namespace Tests\Feature\Import; use App\Jobs\Import\CSVImport; +use App\Models\Client; +use App\Models\Product; use App\Utils\Traits\MakesHash; use Illuminate\Routing\Middleware\ThrottleRequests; use Illuminate\Support\Facades\Cache; @@ -74,10 +76,13 @@ class ImportCsvTest extends TestCase 'entity_type'=> 'client', ]; + $pre_import = Client::count(); + 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'); $hash = Str::random(32); + $column_map = [ - 1 => 'product.product_key', 2 => 'product.notes', 3 => 'product.cost', - 4 => 'product.user_id', ]; $data = [ @@ -99,10 +103,14 @@ class ImportCsvTest extends TestCase 'entity_type'=> 'product', ]; + $pre_import = Product::count(); + Cache::put($hash, base64_encode($csv), 360); - $this->markTestSkipped(); CSVImport::dispatchNow($data, $this->company); + + $this->assertGreaterThan($pre_import, Product::count()); + } private function getCsvData($csvfile)