Add simple test around custom asset report response

This commit is contained in:
Marcus Moore 2023-08-08 17:10:36 -07:00
parent 32d8d8c50e
commit 1405e17251
No known key found for this signature in database
2 changed files with 42 additions and 0 deletions

View file

@ -432,4 +432,13 @@ class UserFactory extends Factory
];
});
}
public function canViewReports()
{
return $this->state(function () {
return [
'permissions' => '{"reports.view":"1"}',
];
});
}
}

View file

@ -0,0 +1,33 @@
<?php
namespace Tests\Feature\Reports;
use App\Models\Asset;
use App\Models\User;
use League\Csv\Reader;
use Tests\Support\InteractsWithSettings;
use Tests\TestCase;
class CustomReportTest extends TestCase
{
use InteractsWithSettings;
public function testCustomAssetReport()
{
Asset::factory()->create(['name' => 'Asset A']);
Asset::factory()->create(['name' => 'Asset B']);
$response = $this->actingAs(User::factory()->canViewReports()->create())
->post('reports/custom', [
'asset_name' => '1',
'asset_tag' => '1',
'serial' => '1',
])->assertOk()
->assertHeader('content-type', 'text/csv; charset=UTF-8');
$reader = Reader::createFromString($response->streamedContent());
$this->assertTrue(collect($reader->getRecords())->pluck(0)->contains('Asset A'));
$this->assertTrue(collect($reader->getRecords())->pluck(0)->contains('Asset B'));
}
}