mirror of
https://github.com/snipe/snipe-it.git
synced 2025-01-12 14:27:33 -08:00
Implement some tests
This commit is contained in:
parent
0ac1dd314a
commit
691e81d827
|
@ -5,6 +5,7 @@ namespace App\Models;
|
||||||
use Illuminate\Database\Eloquent\Builder;
|
use Illuminate\Database\Eloquent\Builder;
|
||||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||||
use Watson\Validating\ValidatingTrait;
|
use Watson\Validating\ValidatingTrait;
|
||||||
|
|
||||||
class ReportTemplate extends Model
|
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
|
public function checkmarkValue(string $property): string
|
||||||
{
|
{
|
||||||
// Assuming we're using the null object pattern,
|
// Assuming we're using the null object pattern,
|
||||||
|
|
|
@ -15,7 +15,9 @@ class ReportTemplateFactory extends Factory
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'name' => $this->faker->word(),
|
'name' => $this->faker->word(),
|
||||||
'options' => [],
|
'options' => [
|
||||||
|
'id' => '1',
|
||||||
|
],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Feature\ReportTemplates;
|
namespace Tests\Feature\ReportTemplates;
|
||||||
|
|
||||||
|
use App\Models\ReportTemplate;
|
||||||
|
use App\Models\User;
|
||||||
use Tests\Support\InteractsWithSettings;
|
use Tests\Support\InteractsWithSettings;
|
||||||
use Tests\TestCase;
|
use Tests\TestCase;
|
||||||
|
|
||||||
|
@ -11,11 +13,20 @@ class DeleteReportTemplateTest extends TestCase
|
||||||
|
|
||||||
public function testDeletingReportTemplateRequiresCorrectPermission()
|
public function testDeletingReportTemplateRequiresCorrectPermission()
|
||||||
{
|
{
|
||||||
$this->markTestIncomplete();
|
$this->actingAs(User::factory()->create())
|
||||||
|
->post(route('report-templates.destroy', 1))
|
||||||
|
->assertForbidden();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testCanDeleteAReportTemplate()
|
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());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Feature\ReportTemplates;
|
namespace Tests\Feature\ReportTemplates;
|
||||||
|
|
||||||
use App\Models\ReportTemplate;
|
use App\Models\ReportTemplate;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Feature\ReportTemplates;
|
namespace Tests\Feature\ReportTemplates;
|
||||||
|
|
||||||
use App\Models\ReportTemplate;
|
use App\Models\ReportTemplate;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
|
@ -13,12 +13,29 @@ class UpdateReportTemplateTest extends TestCase
|
||||||
|
|
||||||
public function testUpdatingReportTemplateRequiresCorrectPermission()
|
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()
|
public function testUpdatingReportTemplateRequiresValidFields()
|
||||||
{
|
{
|
||||||
$this->markTestIncomplete();
|
$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()
|
public function testCanUpdateAReportTemplate()
|
||||||
|
@ -27,12 +44,23 @@ class UpdateReportTemplateTest extends TestCase
|
||||||
|
|
||||||
$user = User::factory()->canViewReports()->create();
|
$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)
|
$this->actingAs($user)
|
||||||
->get(route('report-templates.edit', $reportTemplate))
|
->post(route('report-templates.update', $reportTemplate), [
|
||||||
|
'id' => 1,
|
||||||
|
'by_company_id' => [3],
|
||||||
|
])
|
||||||
->assertOk();
|
->assertOk();
|
||||||
|
|
||||||
// @todo:
|
// @todo:
|
||||||
|
$reportTemplate->fresh();
|
||||||
|
dd($reportTemplate->options);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue