A free open source IT asset/license management system
Add simple test around custom asset report response
Marcus Moore1405e17251b9
diff --git a/database/factories/UserFactory.php b/database/factories/UserFactory.phpindex 2445a351f3..db13224616 100644--- a/database/factories/UserFactory.php+++ b/database/factories/UserFactory.php@@ -432,4 +432,13 @@ class UserFactory extends Factory];});}++ public function canViewReports()+ {+ return $this->state(function () {+ return [+ 'permissions' => '{"reports.view":"1"}',+ ];+ });+ }}diff --git a/tests/Feature/Reports/CustomReportTest.php b/tests/Feature/Reports/CustomReportTest.phpnew file mode 100644index 0000000000..b8d7009942--- /dev/null+++ b/tests/Feature/Reports/CustomReportTest.php@@ -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'));+ }+}