feature test su institution
This commit is contained in:
30
backend/tests/Feature/Models/InstitutionLinkTest.php
Normal file
30
backend/tests/Feature/Models/InstitutionLinkTest.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Models;
|
||||
|
||||
use App\Enums\InstitutionLinkType;
|
||||
use App\Models\Institution;
|
||||
use App\Models\InstitutionLink;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Tests\TestCase;
|
||||
|
||||
class InstitutionLinkTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_type_is_cast_to_enum(): void
|
||||
{
|
||||
$link = InstitutionLink::factory()->create(['type' => InstitutionLinkType::Ticketing]);
|
||||
|
||||
$this->assertInstanceOf(InstitutionLinkType::class, $link->fresh()->type);
|
||||
$this->assertSame(InstitutionLinkType::Ticketing, $link->fresh()->type);
|
||||
}
|
||||
|
||||
public function test_it_belongs_to_an_institution(): void
|
||||
{
|
||||
$institution = Institution::factory()->create();
|
||||
$link = InstitutionLink::factory()->create(['institution_id' => $institution->id]);
|
||||
|
||||
$this->assertTrue($link->institution->is($institution));
|
||||
}
|
||||
}
|
||||
99
backend/tests/Feature/Models/InstitutionTest.php
Normal file
99
backend/tests/Feature/Models/InstitutionTest.php
Normal file
@@ -0,0 +1,99 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Models;
|
||||
|
||||
use App\Models\Institution;
|
||||
use App\Models\InstitutionLink;
|
||||
use App\Models\Lists\InstitutionCategory;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Str;
|
||||
use Tests\TestCase;
|
||||
|
||||
class InstitutionTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_uuid_is_generated_on_create(): void
|
||||
{
|
||||
$institution = Institution::factory()->create();
|
||||
|
||||
$this->assertNotEmpty($institution->uuid);
|
||||
$this->assertSame(36, strlen((string) $institution->uuid));
|
||||
}
|
||||
|
||||
public function test_two_institutions_get_distinct_uuids(): void
|
||||
{
|
||||
$a = Institution::factory()->create();
|
||||
$b = Institution::factory()->create();
|
||||
|
||||
$this->assertNotSame($a->uuid, $b->uuid);
|
||||
}
|
||||
|
||||
public function test_a_provided_uuid_is_not_overwritten(): void
|
||||
{
|
||||
$uuid = (string) Str::uuid();
|
||||
|
||||
$institution = Institution::factory()->make();
|
||||
$institution->uuid = $uuid;
|
||||
$institution->save();
|
||||
|
||||
$this->assertSame($uuid, $institution->fresh()->uuid);
|
||||
}
|
||||
|
||||
public function test_route_key_is_the_uuid(): void
|
||||
{
|
||||
$this->assertSame('uuid', (new Institution)->getRouteKeyName());
|
||||
}
|
||||
|
||||
public function test_attributes_are_cast(): void
|
||||
{
|
||||
$institution = Institution::factory()->create([
|
||||
'is_storage_place' => 1,
|
||||
'lat' => '55.700000',
|
||||
'lon' => '13.190000',
|
||||
'legacy_id' => '42',
|
||||
]);
|
||||
|
||||
$fresh = $institution->fresh();
|
||||
|
||||
$this->assertIsBool($fresh->is_storage_place);
|
||||
$this->assertIsFloat($fresh->lat);
|
||||
$this->assertIsFloat($fresh->lon);
|
||||
$this->assertSame(42, $fresh->legacy_id);
|
||||
}
|
||||
|
||||
public function test_it_belongs_to_a_category(): void
|
||||
{
|
||||
$category = InstitutionCategory::factory()->create();
|
||||
$institution = Institution::factory()->create(['category_id' => $category->id]);
|
||||
|
||||
$this->assertTrue($institution->category->is($category));
|
||||
}
|
||||
|
||||
public function test_a_category_has_many_institutions(): void
|
||||
{
|
||||
$category = InstitutionCategory::factory()->create();
|
||||
Institution::factory()->count(2)->create(['category_id' => $category->id]);
|
||||
|
||||
$this->assertCount(2, $category->institutions);
|
||||
}
|
||||
|
||||
public function test_it_has_many_links(): void
|
||||
{
|
||||
$institution = Institution::factory()->create();
|
||||
InstitutionLink::factory()->create(['institution_id' => $institution->id]);
|
||||
|
||||
$this->assertCount(1, $institution->refresh()->links);
|
||||
}
|
||||
|
||||
public function test_it_is_soft_deleted(): void
|
||||
{
|
||||
$institution = Institution::factory()->create();
|
||||
|
||||
$institution->delete();
|
||||
|
||||
$this->assertSoftDeleted($institution);
|
||||
$this->assertSame(0, Institution::count());
|
||||
$this->assertSame(1, Institution::withTrashed()->count());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user