feat(seeder): add WebsiteTypeSeeder and update DatabaseSeeder to include it
This commit is contained in:
@@ -23,6 +23,7 @@ class DatabaseSeeder extends Seeder
|
||||
]);
|
||||
|
||||
$this->call([
|
||||
WebsiteTypeSeeder::class,
|
||||
SocialMediaSeeder::class,
|
||||
TenantSeeder::class,
|
||||
AttributeSeeder::class,
|
||||
|
||||
103
database/seeders/WebsiteTypeSeeder.php
Normal file
103
database/seeders/WebsiteTypeSeeder.php
Normal file
@@ -0,0 +1,103 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use App\Domains\Tenant\Models\WebsiteType;
|
||||
use Illuminate\Database\Seeder;
|
||||
|
||||
class WebsiteTypeSeeder extends Seeder
|
||||
{
|
||||
public function run(): void
|
||||
{
|
||||
$shopIt = WebsiteType::query()->updateOrCreate(
|
||||
['codigo' => 'shopit'],
|
||||
['nombre' => 'ShopIt'],
|
||||
);
|
||||
|
||||
$shopIt->extras()->updateOrCreate(
|
||||
['nombre' => 'carousel'],
|
||||
[
|
||||
'descripcion' => 'Listado de attachments que se muestran en el carousel principal.',
|
||||
'is_required' => false,
|
||||
'config_schema' => [
|
||||
'request_rules' => [
|
||||
'$' => 'required|array|max:10',
|
||||
'$.*' => 'required|image_or_base64|distinct',
|
||||
],
|
||||
'transforms' => [
|
||||
'$.*' => [
|
||||
'handler' => 'attachment',
|
||||
'attachment_type' => 'image',
|
||||
],
|
||||
],
|
||||
'database_rules' => [
|
||||
'$' => 'required|array',
|
||||
'$.*' => 'required|integer|distinct|exists:attachments,id',
|
||||
],
|
||||
],
|
||||
],
|
||||
);
|
||||
|
||||
$onTicket = WebsiteType::query()->updateOrCreate(
|
||||
['codigo' => 'onticket'],
|
||||
['nombre' => 'OnTicket'],
|
||||
);
|
||||
|
||||
$onTicket->extras()->updateOrCreate(
|
||||
['nombre' => 'heroConfig'],
|
||||
[
|
||||
'descripcion' => 'Configuracion del hero principal del evento.',
|
||||
'is_required' => false,
|
||||
'config_schema' => [
|
||||
'request_rules' => [
|
||||
'$' => 'required|array',
|
||||
'title_html' => 'nullable|string',
|
||||
'description_html' => 'nullable|string',
|
||||
'button_text' => 'nullable|string',
|
||||
'button_href' => 'nullable|string',
|
||||
'background_image_id' => 'nullable|image_or_base64',
|
||||
],
|
||||
'transforms' => [
|
||||
'background_image_id' => [
|
||||
'handler' => 'attachment',
|
||||
'attachment_type' => 'image',
|
||||
],
|
||||
],
|
||||
'database_rules' => [
|
||||
'$' => 'required|array',
|
||||
'title_html' => 'nullable|string',
|
||||
'description_html' => 'nullable|string',
|
||||
'button_text' => 'nullable|string',
|
||||
'button_href' => 'nullable|string',
|
||||
'background_image_id' => 'nullable|integer|exists:attachments,id',
|
||||
],
|
||||
],
|
||||
],
|
||||
);
|
||||
|
||||
$onTicket->extras()->updateOrCreate(
|
||||
['nombre' => 'eventConfig'],
|
||||
[
|
||||
'descripcion' => 'Informacion principal del evento.',
|
||||
'is_required' => false,
|
||||
'config_schema' => [
|
||||
'request_rules' => [
|
||||
'$' => 'required|array',
|
||||
'title' => 'nullable|string',
|
||||
'location' => 'nullable|string',
|
||||
'dates' => 'nullable|array',
|
||||
'dates.*' => 'required|date_format:Y-m-d|distinct',
|
||||
],
|
||||
'transforms' => [],
|
||||
'database_rules' => [
|
||||
'$' => 'required|array',
|
||||
'title' => 'nullable|string',
|
||||
'location' => 'nullable|string',
|
||||
'dates' => 'nullable|array',
|
||||
'dates.*' => 'required|date_format:Y-m-d|distinct',
|
||||
],
|
||||
],
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
101
tests/Feature/Seeders/WebsiteTypeSeederTest.php
Normal file
101
tests/Feature/Seeders/WebsiteTypeSeederTest.php
Normal file
@@ -0,0 +1,101 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Seeders;
|
||||
|
||||
use App\Domains\Tenant\Models\WebsiteType;
|
||||
use Database\Seeders\WebsiteTypeSeeder;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Tests\TestCase;
|
||||
|
||||
class WebsiteTypeSeederTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_it_seeds_website_types_and_their_config_schemas_idempotently(): void
|
||||
{
|
||||
$this->seed(WebsiteTypeSeeder::class);
|
||||
$this->seed(WebsiteTypeSeeder::class);
|
||||
|
||||
$this->assertSame(2, WebsiteType::query()->count());
|
||||
|
||||
$shopIt = WebsiteType::query()
|
||||
->where('codigo', 'shopit')
|
||||
->with('extras')
|
||||
->sole();
|
||||
|
||||
$this->assertSame('ShopIt', $shopIt->nombre);
|
||||
$this->assertSame(['carousel'], $shopIt->extras->pluck('nombre')->all());
|
||||
$this->assertSame([
|
||||
'request_rules' => [
|
||||
'$' => 'required|array|max:10',
|
||||
'$.*' => 'required|image_or_base64|distinct',
|
||||
],
|
||||
'transforms' => [
|
||||
'$.*' => [
|
||||
'handler' => 'attachment',
|
||||
'attachment_type' => 'image',
|
||||
],
|
||||
],
|
||||
'database_rules' => [
|
||||
'$' => 'required|array',
|
||||
'$.*' => 'required|integer|distinct|exists:attachments,id',
|
||||
],
|
||||
], $shopIt->extras->sole()->config_schema);
|
||||
|
||||
$onTicket = WebsiteType::query()
|
||||
->where('codigo', 'onticket')
|
||||
->with('extras')
|
||||
->sole();
|
||||
|
||||
$this->assertSame('OnTicket', $onTicket->nombre);
|
||||
$this->assertEqualsCanonicalizing(
|
||||
['heroConfig', 'eventConfig'],
|
||||
$onTicket->extras->pluck('nombre')->all(),
|
||||
);
|
||||
|
||||
$heroSchema = $onTicket->extras->firstWhere('nombre', 'heroConfig')->config_schema;
|
||||
$this->assertSame([
|
||||
'request_rules' => [
|
||||
'$' => 'required|array',
|
||||
'title_html' => 'nullable|string',
|
||||
'description_html' => 'nullable|string',
|
||||
'button_text' => 'nullable|string',
|
||||
'button_href' => 'nullable|string',
|
||||
'background_image_id' => 'nullable|image_or_base64',
|
||||
],
|
||||
'transforms' => [
|
||||
'background_image_id' => [
|
||||
'handler' => 'attachment',
|
||||
'attachment_type' => 'image',
|
||||
],
|
||||
],
|
||||
'database_rules' => [
|
||||
'$' => 'required|array',
|
||||
'title_html' => 'nullable|string',
|
||||
'description_html' => 'nullable|string',
|
||||
'button_text' => 'nullable|string',
|
||||
'button_href' => 'nullable|string',
|
||||
'background_image_id' => 'nullable|integer|exists:attachments,id',
|
||||
],
|
||||
], $heroSchema);
|
||||
|
||||
$eventSchema = $onTicket->extras->firstWhere('nombre', 'eventConfig')->config_schema;
|
||||
$this->assertSame([
|
||||
'request_rules' => [
|
||||
'$' => 'required|array',
|
||||
'title' => 'nullable|string',
|
||||
'location' => 'nullable|string',
|
||||
'dates' => 'nullable|array',
|
||||
'dates.*' => 'required|date_format:Y-m-d|distinct',
|
||||
],
|
||||
'transforms' => [],
|
||||
'database_rules' => [
|
||||
'$' => 'required|array',
|
||||
'title' => 'nullable|string',
|
||||
'location' => 'nullable|string',
|
||||
'dates' => 'nullable|array',
|
||||
'dates.*' => 'required|date_format:Y-m-d|distinct',
|
||||
],
|
||||
], $eventSchema);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user