Skip to content

A free open source IT asset/license management system

Improve tests

Marcus Moore4217d7402b52
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 @@
+<?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();
+ }
+}
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()