Improve tests

This commit is contained in:
Marcus Moore 2024-10-22 17:50:40 -07:00
parent 3d28a9090c
commit 4217d7402b
No known key found for this signature in database
2 changed files with 49 additions and 8 deletions

View file

@ -0,0 +1,43 @@
<?php
namespace Tests\Feature\ReportTemplates;
use App\Models\ReportTemplate;
use App\Models\User;
use Tests\Concerns\TestsPermissionsRequirement;
use Tests\TestCase;
class EditReportTemplateTest extends TestCase implements TestsPermissionsRequirement
{
public function testRequiresPermission()
{
$this->markTestIncomplete('Returning 404 instead of 403...');
$this->actingAs(User::factory()->create())
->get(route('report-templates.edit', ReportTemplate::factory()->create()))
->assertForbidden();
}
public function testCannotLoadEditPageForAnotherUsersReportTemplate()
{
$this->markTestIncomplete('Returns 404...');
$user = User::factory()->canViewReports()->create();
$reportTemplate = ReportTemplate::factory()->create();
$this->actingAs($user)
->get(route('report-templates.edit', $reportTemplate))
->assertSessionHas('error')
->assertRedirect(route('reports/custom'));
}
public function testCanLoadEditReportTemplatePage()
{
$user = User::factory()->canViewReports()->create();
$reportTemplate = ReportTemplate::factory()->for($user)->create();
$this->actingAs($user)
->get(route('report-templates.edit', $reportTemplate))
->assertOk();
}
}

View file

@ -12,18 +12,16 @@ class UpdateReportTemplateTest extends TestCase implements TestsPermissionsRequi
public function testRequiresPermission()
{
$this->actingAs(User::factory()->create())
->post(route('report-templates.update', 1))
->post(route('report-templates.update', ReportTemplate::factory()->create()))
->assertForbidden();
}
public function testCanLoadEditReportTemplatePage()
public function testCannotUpdateAnotherUsersReportTemplate()
{
$user = User::factory()->canViewReports()->create();
$reportTemplate = ReportTemplate::factory()->for($user)->create();
$this->actingAs($user)
->get(route('report-templates.edit', $reportTemplate))
->assertOk();
$this->actingAs(User::factory()->canViewReports()->create())
->post(route('report-templates.update', ReportTemplate::factory()->create()))
->assertSessionHas('error')
->assertRedirect(route('reports/custom'));
}
public function testCanUpdateAReportTemplate()