mirror of
https://github.com/snipe/snipe-it.git
synced 2025-02-02 08:21:09 -08:00
Add simple test around custom asset report response
This commit is contained in:
parent
32d8d8c50e
commit
1405e17251
|
@ -432,4 +432,13 @@ class UserFactory extends Factory
|
|||
];
|
||||
});
|
||||
}
|
||||
|
||||
public function canViewReports()
|
||||
{
|
||||
return $this->state(function () {
|
||||
return [
|
||||
'permissions' => '{"reports.view":"1"}',
|
||||
];
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
33
tests/Feature/Reports/CustomReportTest.php
Normal file
33
tests/Feature/Reports/CustomReportTest.php
Normal 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'));
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue