mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-08 13:44:31 -04:00
Tests for importing Products from csv
This commit is contained in:
parent
b2f8479abf
commit
4322a31aeb
@ -78,12 +78,13 @@ class InvoiceTransformer extends BaseTransformer {
|
|||||||
'archived' => $status === 'archived',
|
'archived' => $status === 'archived',
|
||||||
];
|
];
|
||||||
|
|
||||||
|
/* If we can't find the client, then lets try and create a client */
|
||||||
if(!$transformed['client_id']){
|
if(!$transformed['client_id']){
|
||||||
|
|
||||||
$client_transformer = new ClientTransformer($this->company);
|
$client_transformer = new ClientTransformer($this->company);
|
||||||
|
|
||||||
$transformed['client'] = $client_transformer->transform($invoice_data);
|
$transformed['client'] = $client_transformer->transform($invoice_data);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -54,7 +54,39 @@ class CsvImportTest extends TestCase
|
|||||||
$this->withoutExceptionHandling();
|
$this->withoutExceptionHandling();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testCsvFeature()
|
public function testProductImport()
|
||||||
|
{
|
||||||
|
$csv = file_get_contents( base_path() . '/tests/Feature/Import/products.csv' );
|
||||||
|
$hash = Str::random( 32 );
|
||||||
|
Cache::put( $hash . '-product', base64_encode( $csv ), 360 );
|
||||||
|
|
||||||
|
$column_map = [
|
||||||
|
1 => 'product.product_key',
|
||||||
|
2 => 'product.notes',
|
||||||
|
3 => 'product.cost',
|
||||||
|
];
|
||||||
|
|
||||||
|
$data = [
|
||||||
|
'hash' => $hash,
|
||||||
|
'column_map' => [ 'product' => [ 'mapping' => $column_map ] ],
|
||||||
|
'skip_header' => true,
|
||||||
|
'import_type' => 'csv',
|
||||||
|
];
|
||||||
|
|
||||||
|
$csv_importer = new Csv($data, $this->company);
|
||||||
|
|
||||||
|
$this->assertInstanceOf(Csv::class, $csv_importer);
|
||||||
|
|
||||||
|
$csv_importer->import('product');
|
||||||
|
|
||||||
|
$base_transformer = new BaseTransformer($this->company);
|
||||||
|
|
||||||
|
$this->assertTrue($base_transformer->hasProduct('officiis'));
|
||||||
|
$this->assertTrue($base_transformer->hasProduct('maxime'));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testClientImport()
|
||||||
{
|
{
|
||||||
$csv = file_get_contents(base_path().'/tests/Feature/Import/clients.csv');
|
$csv = file_get_contents(base_path().'/tests/Feature/Import/clients.csv');
|
||||||
$hash = Str::random(32);
|
$hash = Str::random(32);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user