From 4217d7402b52c4f8c93d70be1783a87b90451b78 Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Tue, 22 Oct 2024 17:50:40 -0700 Subject: [PATCH] Improve tests --- .../EditReportTemplateTest.php | 43 +++++++++++++++++++ .../UpdateReportTemplateTest.php | 14 +++--- 2 files changed, 49 insertions(+), 8 deletions(-) create mode 100644 tests/Feature/ReportTemplates/EditReportTemplateTest.php diff --git a/tests/Feature/ReportTemplates/EditReportTemplateTest.php b/tests/Feature/ReportTemplates/EditReportTemplateTest.php new file mode 100644 index 0000000000..964c0c8662 --- /dev/null +++ b/tests/Feature/ReportTemplates/EditReportTemplateTest.php @@ -0,0 +1,43 @@ +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(); + } +} diff --git a/tests/Feature/ReportTemplates/UpdateReportTemplateTest.php b/tests/Feature/ReportTemplates/UpdateReportTemplateTest.php index bade8f9c50..6fb411df52 100644 --- a/tests/Feature/ReportTemplates/UpdateReportTemplateTest.php +++ b/tests/Feature/ReportTemplates/UpdateReportTemplateTest.php @@ -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()