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
42
tests/Unit/Models/PluginTest.php
Normal file
42
tests/Unit/Models/PluginTest.php
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
<?php
|
||||
|
||||
use App\Models\Plugin;
|
||||
|
||||
uses(\Illuminate\Foundation\Testing\RefreshDatabase::class);
|
||||
|
||||
test('plugin has required attributes', function () {
|
||||
$plugin = Plugin::factory()->create([
|
||||
'name' => 'Test Plugin',
|
||||
'data_payload' => ['key' => 'value'],
|
||||
]);
|
||||
|
||||
expect($plugin)
|
||||
->name->toBe('Test Plugin')
|
||||
->data_payload->toBe(['key' => 'value'])
|
||||
->uuid->toBeString()
|
||||
->uuid->toMatch('/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/');
|
||||
});
|
||||
|
||||
test('plugin automatically generates uuid on creation', function () {
|
||||
$plugin = Plugin::factory()->create();
|
||||
|
||||
expect($plugin->uuid)
|
||||
->toBeString()
|
||||
->toMatch('/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/');
|
||||
});
|
||||
|
||||
test('plugin can have custom uuid', function () {
|
||||
$uuid = \Illuminate\Support\Str::uuid();
|
||||
$plugin = Plugin::factory()->create(['uuid' => $uuid]);
|
||||
|
||||
expect($plugin->uuid)->toBe($uuid);
|
||||
});
|
||||
|
||||
test('plugin data_payload is cast to array', function () {
|
||||
$data = ['key' => 'value'];
|
||||
$plugin = Plugin::factory()->create(['data_payload' => $data]);
|
||||
|
||||
expect($plugin->data_payload)
|
||||
->toBeArray()
|
||||
->toBe($data);
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue