mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Tests for tests
This commit is contained in:
parent
b3ac20826b
commit
4c46f9397b
@ -55,7 +55,7 @@ class VendorExport extends BaseExport
|
|||||||
if (count($this->input['report_keys']) == 0) {
|
if (count($this->input['report_keys']) == 0) {
|
||||||
$this->input['report_keys'] = array_values($this->vendor_report_keys);
|
$this->input['report_keys'] = array_values($this->vendor_report_keys);
|
||||||
}
|
}
|
||||||
|
|
||||||
$query = Vendor::query()->with('contacts')
|
$query = Vendor::query()->with('contacts')
|
||||||
->withTrashed()
|
->withTrashed()
|
||||||
->where('company_id', $this->company->id)
|
->where('company_id', $this->company->id)
|
||||||
|
@ -39,8 +39,8 @@ class PreviewReport implements ShouldQueue
|
|||||||
/** @var \App\Export\CSV\CreditExport $export */
|
/** @var \App\Export\CSV\CreditExport $export */
|
||||||
$export = new $this->report_class($this->company, $this->request);
|
$export = new $this->report_class($this->company, $this->request);
|
||||||
$report = $export->returnJson();
|
$report = $export->returnJson();
|
||||||
nlog($report);
|
// nlog($report);
|
||||||
nlog($this->report_class);
|
// nlog($this->report_class);
|
||||||
// nlog($report);
|
// nlog($report);
|
||||||
Cache::put($this->hash, $report, 60 * 60);
|
Cache::put($this->hash, $report, 60 * 60);
|
||||||
}
|
}
|
||||||
|
@ -47,7 +47,7 @@ class InvoicesTest extends TestCase
|
|||||||
$user = User::factory()->create(
|
$user = User::factory()->create(
|
||||||
['account_id' => $account->id, 'email' => $this->faker->safeEmail()]
|
['account_id' => $account->id, 'email' => $this->faker->safeEmail()]
|
||||||
);
|
);
|
||||||
|
echo "1";
|
||||||
$company = Company::factory()->create(['account_id' => $account->id]);
|
$company = Company::factory()->create(['account_id' => $account->id]);
|
||||||
$company->settings->language_id = '1';
|
$company->settings->language_id = '1';
|
||||||
$company->save();
|
$company->save();
|
||||||
@ -89,24 +89,31 @@ class InvoicesTest extends TestCase
|
|||||||
'due_date' => '',
|
'due_date' => '',
|
||||||
'status_id' => Invoice::STATUS_UNPAID,
|
'status_id' => Invoice::STATUS_UNPAID,
|
||||||
]);
|
]);
|
||||||
|
echo "2";
|
||||||
|
|
||||||
$sent->load('client');
|
$sent->load('client');
|
||||||
$paid->load('client');
|
$paid->load('client');
|
||||||
$unpaid->load('client');
|
$unpaid->load('client');
|
||||||
|
|
||||||
|
echo "3";
|
||||||
|
|
||||||
$this->actingAs($client->contacts()->first(), 'contact');
|
$this->actingAs($client->contacts()->first(), 'contact');
|
||||||
|
|
||||||
|
echo "4";
|
||||||
Livewire::test(InvoicesTable::class, ['company_id' => $company->id, 'db' => $company->db])
|
Livewire::test(InvoicesTable::class, ['company_id' => $company->id, 'db' => $company->db])
|
||||||
->assertSee($sent->number)
|
->assertSee($sent->number)
|
||||||
->assertSee($paid->number)
|
->assertSee($paid->number)
|
||||||
->assertSee($unpaid->number);
|
->assertSee($unpaid->number);
|
||||||
|
echo "5";
|
||||||
|
|
||||||
Livewire::test(InvoicesTable::class, ['company_id' => $company->id, 'db' => $company->db])
|
Livewire::test(InvoicesTable::class, ['company_id' => $company->id, 'db' => $company->db])
|
||||||
->set('status', ['paid'])
|
->set('status', ['paid'])
|
||||||
->assertSee($paid->number)
|
->assertSee($paid->number)
|
||||||
->assertDontSee($unpaid->number);
|
->assertDontSee($unpaid->number);
|
||||||
|
echo "6";
|
||||||
|
|
||||||
$account->delete();
|
$account->delete();
|
||||||
|
echo "7";
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,15 +18,17 @@ use App\Models\Credit;
|
|||||||
use League\Csv\Reader;
|
use League\Csv\Reader;
|
||||||
use App\Models\Account;
|
use App\Models\Account;
|
||||||
use App\Models\Company;
|
use App\Models\Company;
|
||||||
|
use App\Models\Expense;
|
||||||
use App\Models\Invoice;
|
use App\Models\Invoice;
|
||||||
use Tests\MockAccountData;
|
use Tests\MockAccountData;
|
||||||
use App\Models\CompanyToken;
|
use App\Models\CompanyToken;
|
||||||
use App\Models\ClientContact;
|
use App\Models\ClientContact;
|
||||||
|
use App\Export\CSV\TaskExport;
|
||||||
use App\Utils\Traits\MakesHash;
|
use App\Utils\Traits\MakesHash;
|
||||||
|
use App\Export\CSV\VendorExport;
|
||||||
use App\DataMapper\CompanySettings;
|
use App\DataMapper\CompanySettings;
|
||||||
use App\Factory\CompanyUserFactory;
|
use App\Factory\CompanyUserFactory;
|
||||||
use App\Factory\InvoiceItemFactory;
|
use App\Factory\InvoiceItemFactory;
|
||||||
use App\Models\Expense;
|
|
||||||
use App\Services\Report\ARDetailReport;
|
use App\Services\Report\ARDetailReport;
|
||||||
use Illuminate\Routing\Middleware\ThrottleRequests;
|
use Illuminate\Routing\Middleware\ThrottleRequests;
|
||||||
|
|
||||||
@ -293,7 +295,7 @@ class ReportCsvGenerationTest extends TestCase
|
|||||||
])->post('/api/v1/reports/vendors', $data);
|
])->post('/api/v1/reports/vendors', $data);
|
||||||
|
|
||||||
$csv = $response->streamedContent();
|
$csv = $response->streamedContent();
|
||||||
nlog($csv);
|
|
||||||
$this->assertEquals('Vendor 1', $this->getFirstValueByColumn($csv, 'Vendor Name'));
|
$this->assertEquals('Vendor 1', $this->getFirstValueByColumn($csv, 'Vendor Name'));
|
||||||
$this->assertEquals('1234', $this->getFirstValueByColumn($csv, 'Vendor Number'));
|
$this->assertEquals('1234', $this->getFirstValueByColumn($csv, 'Vendor Number'));
|
||||||
$this->assertEquals('city', $this->getFirstValueByColumn($csv, 'Vendor City'));
|
$this->assertEquals('city', $this->getFirstValueByColumn($csv, 'Vendor City'));
|
||||||
@ -305,6 +307,28 @@ nlog($csv);
|
|||||||
$this->assertEquals('public_notes', $this->getFirstValueByColumn($csv, 'Vendor Public Notes'));
|
$this->assertEquals('public_notes', $this->getFirstValueByColumn($csv, 'Vendor Public Notes'));
|
||||||
$this->assertEquals('website', $this->getFirstValueByColumn($csv, 'Vendor Website'));
|
$this->assertEquals('website', $this->getFirstValueByColumn($csv, 'Vendor Website'));
|
||||||
|
|
||||||
|
$data = [
|
||||||
|
'date_range' => 'all',
|
||||||
|
// 'end_date' => 'bail|required_if:date_range,custom|nullable|date',
|
||||||
|
// 'start_date' => 'bail|required_if:date_range,custom|nullable|date',
|
||||||
|
'report_keys' => [],
|
||||||
|
'send_email' => false,
|
||||||
|
// 'status' => 'sometimes|string|nullable|in:all,draft,sent,viewed,paid,unpaid,overdue',
|
||||||
|
];
|
||||||
|
|
||||||
|
$export = new VendorExport($this->company, $data);
|
||||||
|
$data = $export->returnJson();
|
||||||
|
|
||||||
|
$this->assertNotNull($data);
|
||||||
|
|
||||||
|
$this->assertEquals(0, $this->traverseJson($data, 'columns.0.identifier'));
|
||||||
|
$this->assertEquals('Vendor Name', $this->traverseJson($data, 'columns.9.display_value'));
|
||||||
|
$this->assertEquals('vendor', $this->traverseJson($data, '0.0.entity'));
|
||||||
|
$this->assertEquals('address1', $this->traverseJson($data, '0.0.id'));
|
||||||
|
$this->assertNull($this->traverseJson($data, '0.0.hashed_id'));
|
||||||
|
$this->assertEquals('address1', $this->traverseJson($data, '0.0.value'));
|
||||||
|
$this->assertEquals('vendor.address1', $this->traverseJson($data, '0.0.identifier'));
|
||||||
|
$this->assertEquals('address1', $this->traverseJson($data, '0.0.display_value'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testVendorCustomColumnCsvGeneration()
|
public function testVendorCustomColumnCsvGeneration()
|
||||||
@ -348,6 +372,22 @@ nlog($csv);
|
|||||||
$this->assertEquals('Vendor 1', $this->getFirstValueByColumn($csv, 'Vendor Name'));
|
$this->assertEquals('Vendor 1', $this->getFirstValueByColumn($csv, 'Vendor Name'));
|
||||||
$this->assertEquals('1234', $this->getFirstValueByColumn($csv, 'Vendor Number'));
|
$this->assertEquals('1234', $this->getFirstValueByColumn($csv, 'Vendor Number'));
|
||||||
$this->assertEquals('city', $this->getFirstValueByColumn($csv, 'Vendor City'));
|
$this->assertEquals('city', $this->getFirstValueByColumn($csv, 'Vendor City'));
|
||||||
|
|
||||||
|
$export = new VendorExport($this->company, $data);
|
||||||
|
$data = $export->returnJson();
|
||||||
|
|
||||||
|
$this->assertNotNull($data);
|
||||||
|
|
||||||
|
$this->assertEquals(0, $this->traverseJson($data, 'columns.0.identifier'));
|
||||||
|
$this->assertEquals('Vendor Name', $this->traverseJson($data, 'columns.0.display_value'));
|
||||||
|
$this->assertEquals('vendor', $this->traverseJson($data, '0.0.entity'));
|
||||||
|
$this->assertEquals('name', $this->traverseJson($data, '0.0.id'));
|
||||||
|
$this->assertNull($this->traverseJson($data, '0.0.hashed_id'));
|
||||||
|
$this->assertEquals('Vendor 1', $this->traverseJson($data, '0.0.value'));
|
||||||
|
$this->assertEquals('vendor.name', $this->traverseJson($data, '0.0.identifier'));
|
||||||
|
$this->assertEquals('Vendor 1', $this->traverseJson($data, '0.0.display_value'));
|
||||||
|
$this->assertEquals('number', $this->traverseJson($data, '0.2.id'));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -423,6 +463,19 @@ nlog($csv);
|
|||||||
$this->assertEquals('123456', $this->getFirstValueByColumn($csv, 'Invoice Invoice Number'));
|
$this->assertEquals('123456', $this->getFirstValueByColumn($csv, 'Invoice Invoice Number'));
|
||||||
$this->assertEquals(1000, $this->getFirstValueByColumn($csv, 'Invoice Amount'));
|
$this->assertEquals(1000, $this->getFirstValueByColumn($csv, 'Invoice Amount'));
|
||||||
|
|
||||||
|
$export = new TaskExport($this->company, $data);
|
||||||
|
$data = $export->returnJson();
|
||||||
|
|
||||||
|
$this->assertNotNull($data);
|
||||||
|
|
||||||
|
$this->assertEquals(0, $this->traverseJson($data, 'columns.0.identifier'));
|
||||||
|
$this->assertEquals('Client Name', $this->traverseJson($data, 'columns.0.display_value'));
|
||||||
|
$this->assertEquals('client', $this->traverseJson($data, '0.0.entity'));
|
||||||
|
$this->assertEquals('name', $this->traverseJson($data, '0.0.id'));
|
||||||
|
$this->assertNotNull($this->traverseJson($data, '0.0.hashed_id'));
|
||||||
|
$this->assertEquals('bob', $this->traverseJson($data, '0.0.value'));
|
||||||
|
$this->assertEquals('client.name', $this->traverseJson($data, '0.0.identifier'));
|
||||||
|
$this->assertEquals('bob', $this->traverseJson($data, '0.0.display_value'));
|
||||||
|
|
||||||
$data = [
|
$data = [
|
||||||
'date_range' => 'all',
|
'date_range' => 'all',
|
||||||
@ -1364,6 +1417,13 @@ nlog($csv);
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function traverseJson($array, $keys)
|
||||||
|
{
|
||||||
|
$value = data_get($array, $keys, false);
|
||||||
|
|
||||||
|
return $value;
|
||||||
|
}
|
||||||
|
|
||||||
private function getFirstValueByColumn($csv, $column)
|
private function getFirstValueByColumn($csv, $column)
|
||||||
{
|
{
|
||||||
$reader = Reader::createFromString($csv);
|
$reader = Reader::createFromString($csv);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user