Write tests - Write tests for what was done to this point that will be kept #11
|
|
@ -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
|
||||||
|
|
|
||||||
|
|
@ -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);
|
||||||
|
});
|
||||||
Loading…
Reference in New Issue