1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 13:12:50 +01:00

Fixes for tests

This commit is contained in:
David Bomba 2020-12-20 12:21:40 +11:00
parent e3f48f9b8b
commit 4df646f93b
3 changed files with 60 additions and 0 deletions

View File

@ -17,6 +17,7 @@ use App\Http\ValidationRules\Project\ValidProjectForClient;
use App\Models\Invoice;
use App\Utils\Traits\CleanLineItems;
use App\Utils\Traits\MakesHash;
use Illuminate\Validation\Rule;
class StoreInvoiceRequest extends Request
{

View File

@ -171,8 +171,14 @@ class CSVImport implements ShouldQueue
}
$unique_array_filter = array_unique($records[$invoice_number_key]);
info(print_r($unique_array_filter,1));
$unique_invoices = array_intersect_key( $records, $unique_array_filter );
info(print_r($unique_invoices,1));
foreach($unique_invoices as $unique)
{
@ -190,6 +196,8 @@ class CSVImport implements ShouldQueue
}
info(print_r($invoices,1));
$this->processInvoice($invoices, $invoice);
}

View File

@ -12,6 +12,7 @@ namespace Tests\Feature\Import;
use App\Jobs\Import\CSVImport;
use App\Models\Client;
use App\Models\Invoice;
use App\Models\Product;
use App\Utils\Traits\MakesHash;
use Illuminate\Routing\Middleware\ThrottleRequests;
@ -53,6 +54,56 @@ class ImportCsvTest extends TestCase
$this->assertTrue(is_array($this->getCsvData($csv)));
}
public function testInvoiceCsvImport()
{
$csv = file_get_contents(base_path().'/tests/Feature/Import/invoice.csv');
$hash = Str::random(32);
$column_map = [
0 => 'invoice.number',
4 => 'invoice.client_id',
7 => 'invoice.date',
8 => 'invoice.due_date',
9 => 'invoice.terms',
10 => 'invoice.public_notes',
11 => 'invoice.is_sent',
12 => 'invoice.private_notes',
13 => 'invoice.uses_inclusive_taxes',
14 => 'invoice.tax_name1',
15 => 'invoice.tax_rate1',
16 => 'invoice.tax_name2',
17 => 'invoice.tax_rate2',
18 => 'invoice.tax_name3',
19 => 'invoice.tax_rate3',
21 => 'invoice.footer',
22 => 'invoice.partial',
23 => 'invoice.partial_due_date',
33 => 'payment.date',
34 => 'payment.amount',
35 => 'payment.transaction_reference',
36 => 'item.quantity',
37 => 'item.cost',
38 => 'item.product_key',
39 => 'item.notes',
40 => 'item.discount',
41 => 'item.is_amount_discount',
];
$data = [
'hash' => $hash,
'column_map' => $column_map,
'skip_header' => true,
'entity_type'=> 'invoice',
];
$pre_import = Invoice::count();
Cache::put($hash, base64_encode($csv), 360);
CSVImport::dispatchNow($data, $this->company);
$this->assertGreaterThan($pre_import, Client::count());
}
public function testClientCsvImport()
{