Model RoomUser Test

This commit is contained in:
Matt Young 2024-07-01 11:22:57 -05:00
parent d32b835cae
commit e8f0620600
2 changed files with 30 additions and 1 deletions

View File

@ -9,6 +9,9 @@ use Illuminate\Database\Eloquent\Relations\BelongsTo;
class RoomUser extends Model class RoomUser extends Model
{ {
protected $table = 'room_user'; protected $table = 'room_user';
protected $guarded = [];
public function user(): BelongsTo public function user(): BelongsTo
{ {
return $this->belongsTo(User::class); return $this->belongsTo(User::class);
@ -16,7 +19,7 @@ class RoomUser extends Model
public function judge(): BelongsTo public function judge(): BelongsTo
{ {
return $this->belongsTo(User::class); return $this->belongsTo(User::class, 'user_id');
} }
public function room(): BelongsTo public function room(): BelongsTo

View File

@ -0,0 +1,26 @@
<?php
use App\Models\Room;
use App\Models\RoomUser;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
uses(RefreshDatabase::class);
beforeEach(function () {
$this->user = User::factory()->create();
$this->room = Room::factory()->create();
$this->roomUser = RoomUser::create(['user_id' => $this->user->id, 'room_id' => $this->room->id]);
});
it('has a user', function () {
expect($this->roomUser->user->first_name)->toBe($this->user->first_name);
});
it('has a judge', function () {
expect($this->roomUser->judge->first_name)->toBe($this->user->first_name);
});
it('has a room', function () {
expect($this->roomUser->room->name)->toBe($this->room->name);
});