Tests for tests

This commit is contained in:
David Bomba 2023-09-14 16:38:59 +10:00
parent b3ac20826b
commit 4c46f9397b
4 changed files with 73 additions and 6 deletions

View File

@ -55,7 +55,7 @@ class VendorExport extends BaseExport
if (count($this->input['report_keys']) == 0) {
$this->input['report_keys'] = array_values($this->vendor_report_keys);
}
$query = Vendor::query()->with('contacts')
->withTrashed()
->where('company_id', $this->company->id)

View File

@ -39,8 +39,8 @@ class PreviewReport implements ShouldQueue
/** @var \App\Export\CSV\CreditExport $export */
$export = new $this->report_class($this->company, $this->request);
$report = $export->returnJson();
nlog($report);
nlog($this->report_class);
// nlog($report);
// nlog($this->report_class);
// nlog($report);
Cache::put($this->hash, $report, 60 * 60);
}

View File

@ -47,7 +47,7 @@ class InvoicesTest extends TestCase
$user = User::factory()->create(
['account_id' => $account->id, 'email' => $this->faker->safeEmail()]
);
echo "1";
$company = Company::factory()->create(['account_id' => $account->id]);
$company->settings->language_id = '1';
$company->save();
@ -89,24 +89,31 @@ class InvoicesTest extends TestCase
'due_date' => '',
'status_id' => Invoice::STATUS_UNPAID,
]);
echo "2";
$sent->load('client');
$paid->load('client');
$unpaid->load('client');
echo "3";
$this->actingAs($client->contacts()->first(), 'contact');
echo "4";
Livewire::test(InvoicesTable::class, ['company_id' => $company->id, 'db' => $company->db])
->assertSee($sent->number)
->assertSee($paid->number)
->assertSee($unpaid->number);
echo "5";
Livewire::test(InvoicesTable::class, ['company_id' => $company->id, 'db' => $company->db])
->set('status', ['paid'])
->assertSee($paid->number)
->assertDontSee($unpaid->number);
echo "6";
$account->delete();
echo "7";
}
}

View File

@ -18,15 +18,17 @@ use App\Models\Credit;
use League\Csv\Reader;
use App\Models\Account;
use App\Models\Company;
use App\Models\Expense;
use App\Models\Invoice;
use Tests\MockAccountData;
use App\Models\CompanyToken;
use App\Models\ClientContact;
use App\Export\CSV\TaskExport;
use App\Utils\Traits\MakesHash;
use App\Export\CSV\VendorExport;
use App\DataMapper\CompanySettings;
use App\Factory\CompanyUserFactory;
use App\Factory\InvoiceItemFactory;
use App\Models\Expense;
use App\Services\Report\ARDetailReport;
use Illuminate\Routing\Middleware\ThrottleRequests;
@ -293,7 +295,7 @@ class ReportCsvGenerationTest extends TestCase
])->post('/api/v1/reports/vendors', $data);
$csv = $response->streamedContent();
nlog($csv);
$this->assertEquals('Vendor 1', $this->getFirstValueByColumn($csv, 'Vendor Name'));
$this->assertEquals('1234', $this->getFirstValueByColumn($csv, 'Vendor Number'));
$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('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()
@ -348,6 +372,22 @@ nlog($csv);
$this->assertEquals('Vendor 1', $this->getFirstValueByColumn($csv, 'Vendor Name'));
$this->assertEquals('1234', $this->getFirstValueByColumn($csv, 'Vendor Number'));
$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(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 = [
'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)
{
$reader = Reader::createFromString($csv);