Implement some tests

This commit is contained in:
Marcus Moore 2024-01-17 16:25:28 -08:00
parent 0ac1dd314a
commit 691e81d827
No known key found for this signature in database
5 changed files with 56 additions and 9 deletions

View file

@ -5,6 +5,7 @@ namespace App\Models;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Watson\Validating\ValidatingTrait;
class ReportTemplate extends Model
@ -42,6 +43,11 @@ class ReportTemplate extends Model
});
}
public function user(): BelongsTo
{
return $this->belongsTo(User::class);
}
public function checkmarkValue(string $property): string
{
// Assuming we're using the null object pattern,

View file

@ -15,7 +15,9 @@ class ReportTemplateFactory extends Factory
{
return [
'name' => $this->faker->word(),
'options' => [],
'options' => [
'id' => '1',
],
];
}
}

View file

@ -1,7 +1,9 @@
<?php
namespace Feature\ReportTemplates;
namespace Tests\Feature\ReportTemplates;
use App\Models\ReportTemplate;
use App\Models\User;
use Tests\Support\InteractsWithSettings;
use Tests\TestCase;
@ -11,11 +13,20 @@ class DeleteReportTemplateTest extends TestCase
public function testDeletingReportTemplateRequiresCorrectPermission()
{
$this->markTestIncomplete();
$this->actingAs(User::factory()->create())
->post(route('report-templates.destroy', 1))
->assertForbidden();
}
public function testCanDeleteAReportTemplate()
{
$this->markTestIncomplete();
$user = User::factory()->canViewReports()->create();
$reportTemplate = ReportTemplate::factory()->for($user)->create();
$this->actingAs($user)
->delete(route('report-templates.destroy', $reportTemplate))
->assertRedirect(route('reports/custom'));
$this->assertFalse($reportTemplate->exists());
}
}

View file

@ -1,6 +1,6 @@
<?php
namespace Feature\ReportTemplates;
namespace Tests\Feature\ReportTemplates;
use App\Models\ReportTemplate;
use App\Models\User;

View file

@ -1,6 +1,6 @@
<?php
namespace Feature\ReportTemplates;
namespace Tests\Feature\ReportTemplates;
use App\Models\ReportTemplate;
use App\Models\User;
@ -13,12 +13,29 @@ class UpdateReportTemplateTest extends TestCase
public function testUpdatingReportTemplateRequiresCorrectPermission()
{
$this->markTestIncomplete();
$this->actingAs(User::factory()->create())
->post(route('report-templates.update', 1))
->assertForbidden();
}
public function testCanLoadEditReportTemplatePage()
{
$user = User::factory()->canViewReports()->create();
$reportTemplate = ReportTemplate::factory()->for($user)->create();
$this->actingAs($user)
->get(route('report-templates.edit', $reportTemplate))
->assertOk();
}
public function testUpdatingReportTemplateRequiresValidFields()
{
$this->markTestIncomplete();
$this->actingAs(User::factory()->canViewReports()->create())
->post(route('report-templates.update', ReportTemplate::factory()->create()))
// @todo: name isn't being passed in this case
->assertSessionHasErrors('name');
}
public function testCanUpdateAReportTemplate()
@ -27,12 +44,23 @@ class UpdateReportTemplateTest extends TestCase
$user = User::factory()->canViewReports()->create();
$reportTemplate = ReportTemplate::factory()->for($user)->create();
$reportTemplate = ReportTemplate::factory()->for($user)->create([
'options' => [
'id' => 1,
'company' => 1,
'by_company_id' => [1, 2],
],
]);
$this->actingAs($user)
->get(route('report-templates.edit', $reportTemplate))
->post(route('report-templates.update', $reportTemplate), [
'id' => 1,
'by_company_id' => [3],
])
->assertOk();
// @todo:
$reportTemplate->fresh();
dd($reportTemplate->options);
}
}