From 5416c0fd6160a216df0c3258cfb9401f042efb8b Mon Sep 17 00:00:00 2001 From: ncoronel Date: Wed, 29 Jul 2026 14:42:03 -0300 Subject: [PATCH] feat(seeder): add WebsiteTypeSeeder and update DatabaseSeeder to include it --- database/seeders/DatabaseSeeder.php | 1 + database/seeders/WebsiteTypeSeeder.php | 103 ++++++++++++++++++ .../Feature/Seeders/WebsiteTypeSeederTest.php | 101 +++++++++++++++++ 3 files changed, 205 insertions(+) create mode 100644 database/seeders/WebsiteTypeSeeder.php create mode 100644 tests/Feature/Seeders/WebsiteTypeSeederTest.php diff --git a/database/seeders/DatabaseSeeder.php b/database/seeders/DatabaseSeeder.php index 17ab1fa..64d8861 100644 --- a/database/seeders/DatabaseSeeder.php +++ b/database/seeders/DatabaseSeeder.php @@ -23,6 +23,7 @@ class DatabaseSeeder extends Seeder ]); $this->call([ + WebsiteTypeSeeder::class, SocialMediaSeeder::class, TenantSeeder::class, AttributeSeeder::class, diff --git a/database/seeders/WebsiteTypeSeeder.php b/database/seeders/WebsiteTypeSeeder.php new file mode 100644 index 0000000..63e76df --- /dev/null +++ b/database/seeders/WebsiteTypeSeeder.php @@ -0,0 +1,103 @@ +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', + ], + ], + ], + ); + } +} diff --git a/tests/Feature/Seeders/WebsiteTypeSeederTest.php b/tests/Feature/Seeders/WebsiteTypeSeederTest.php new file mode 100644 index 0000000..a33eecc --- /dev/null +++ b/tests/Feature/Seeders/WebsiteTypeSeederTest.php @@ -0,0 +1,101 @@ +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); + } +}