Model RoomUser Test
This commit is contained in:
parent
d32b835cae
commit
e8f0620600
|
|
@ -9,6 +9,9 @@ use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|||
class RoomUser extends Model
|
||||
{
|
||||
protected $table = 'room_user';
|
||||
|
||||
protected $guarded = [];
|
||||
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
|
|
@ -16,7 +19,7 @@ class RoomUser extends Model
|
|||
|
||||
public function judge(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
return $this->belongsTo(User::class, 'user_id');
|
||||
}
|
||||
|
||||
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