mirror of
https://github.com/usetrmnl/byos_laravel.git
synced 2026-01-13 15:07:49 +00:00
tests: add test for models Plugin, Playlist, PlaylistItem
This commit is contained in:
parent
ec862942cd
commit
2ef028527f
5 changed files with 118 additions and 1 deletions
46
tests/Unit/Models/PlaylistTest.php
Normal file
46
tests/Unit/Models/PlaylistTest.php
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
<?php
|
||||
|
||||
use App\Models\Device;
|
||||
use App\Models\Playlist;
|
||||
use App\Models\PlaylistItem;
|
||||
|
||||
test('playlist has required attributes', function () {
|
||||
$playlist = Playlist::factory()->create([
|
||||
'name' => 'Test Playlist',
|
||||
'is_active' => true,
|
||||
'weekdays' => [1, 2, 3],
|
||||
'active_from' => '09:00',
|
||||
'active_until' => '17:00',
|
||||
]);
|
||||
|
||||
expect($playlist)
|
||||
->name->toBe('Test Playlist')
|
||||
->is_active->toBeTrue()
|
||||
->weekdays->toBe([1, 2, 3])
|
||||
->active_from->format('H:i')->toBe('09:00')
|
||||
->active_until->format('H:i')->toBe('17:00');
|
||||
});
|
||||
|
||||
test('playlist belongs to device', function () {
|
||||
$device = Device::factory()->create();
|
||||
$playlist = Playlist::factory()->create(['device_id' => $device->id]);
|
||||
|
||||
expect($playlist->device)
|
||||
->toBeInstanceOf(Device::class)
|
||||
->id->toBe($device->id);
|
||||
});
|
||||
|
||||
test('playlist has many items', function () {
|
||||
$playlist = Playlist::factory()->create();
|
||||
$items = PlaylistItem::factory()->count(3)->create(['playlist_id' => $playlist->id]);
|
||||
|
||||
expect($playlist->items)
|
||||
->toHaveCount(3)
|
||||
->each->toBeInstanceOf(PlaylistItem::class);
|
||||
});
|
||||
|
||||
test('getNextPlaylistItem returns null when playlist is inactive', function () {
|
||||
$playlist = Playlist::factory()->create(['is_active' => false]);
|
||||
|
||||
expect($playlist->getNextPlaylistItem())->toBeNull();
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue