user affiliation schema completed
This commit is contained in:
@@ -5,6 +5,7 @@ namespace Tests\Feature\Models;
|
||||
use App\Models\Institution;
|
||||
use App\Models\InstitutionLink;
|
||||
use App\Models\Lists\InstitutionCategory;
|
||||
use App\Models\UserAffiliation;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Str;
|
||||
use Tests\TestCase;
|
||||
@@ -86,6 +87,14 @@ class InstitutionTest extends TestCase
|
||||
$this->assertCount(1, $institution->refresh()->links);
|
||||
}
|
||||
|
||||
public function test_it_has_many_affiliations(): void
|
||||
{
|
||||
$institution = Institution::factory()->create();
|
||||
UserAffiliation::factory()->create(['institution_id' => $institution->id]);
|
||||
|
||||
$this->assertCount(1, $institution->refresh()->affiliations);
|
||||
}
|
||||
|
||||
public function test_it_is_soft_deleted(): void
|
||||
{
|
||||
$institution = Institution::factory()->create();
|
||||
|
||||
21
backend/tests/Feature/Models/UserTest.php
Normal file
21
backend/tests/Feature/Models/UserTest.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Models;
|
||||
|
||||
use App\Models\User;
|
||||
use App\Models\UserAffiliation;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Tests\TestCase;
|
||||
|
||||
class UserTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_it_has_many_affiliations(): void
|
||||
{
|
||||
$user = User::factory()->create();
|
||||
UserAffiliation::factory()->create(['user_id' => $user->id]);
|
||||
|
||||
$this->assertCount(1, $user->refresh()->affiliations);
|
||||
}
|
||||
}
|
||||
@@ -339,6 +339,28 @@ class UserAffiliationControllerTest extends TestCase
|
||||
$this->assertNotSoftDeleted($trashed);
|
||||
}
|
||||
|
||||
public function test_restore_succeeds_for_a_closed_affiliation_even_when_another_one_is_open(): void
|
||||
{
|
||||
$this->actingAs($this->operationalUser(), 'sanctum');
|
||||
$institution = Institution::factory()->create();
|
||||
$user = User::factory()->create();
|
||||
$trashed = UserAffiliation::factory()->create([
|
||||
'institution_id' => $institution->id,
|
||||
'user_id' => $user->id,
|
||||
'end_year' => 2019,
|
||||
]);
|
||||
$trashed->delete();
|
||||
UserAffiliation::factory()->create([
|
||||
'institution_id' => $institution->id,
|
||||
'user_id' => $user->id,
|
||||
'end_year' => null,
|
||||
]);
|
||||
|
||||
$this->postJson(self::BASE_ROUTE."/{$trashed->id}/restore")->assertOk();
|
||||
|
||||
$this->assertNotSoftDeleted($trashed);
|
||||
}
|
||||
|
||||
public function test_operational_user_can_force_delete_an_affiliation(): void
|
||||
{
|
||||
$this->actingAs($this->operationalUser(), 'sanctum');
|
||||
|
||||
Reference in New Issue
Block a user