39 lines
1021 B
PHP
39 lines
1021 B
PHP
<?php
|
|
|
|
namespace Tests\Unit\Services\SchoolIds;
|
|
|
|
use App\Models\User;
|
|
use App\Services\SchoolIds\SchoolIdAssignmentService;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Tests\TestCase;
|
|
|
|
class SchoolIdAssignmentServiceTest extends TestCase
|
|
{
|
|
use RefreshDatabase;
|
|
|
|
public function test_assigns_school_id_when_missing(): void
|
|
{
|
|
$user = User::factory()->create([
|
|
'school_id' => null,
|
|
]);
|
|
|
|
$service = app(SchoolIdAssignmentService::class);
|
|
$schoolId = $service->assignToUser($user->id);
|
|
|
|
$this->assertNotNull($schoolId);
|
|
$this->assertSame($schoolId, User::query()->findOrFail($user->id)->school_id);
|
|
}
|
|
|
|
public function test_assign_returns_existing_school_id(): void
|
|
{
|
|
$user = User::factory()->create([
|
|
'school_id' => '2500001',
|
|
]);
|
|
|
|
$service = app(SchoolIdAssignmentService::class);
|
|
$schoolId = $service->assignToUser($user->id);
|
|
|
|
$this->assertSame('2500001', $schoolId);
|
|
}
|
|
}
|