feat(carousel): add migration and test for Mutual SMEP carousel images
This commit is contained in:
119
tests/Feature/Migrations/SeedMutualSmepCarouselTest.php
Normal file
119
tests/Feature/Migrations/SeedMutualSmepCarouselTest.php
Normal file
@@ -0,0 +1,119 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Migrations;
|
||||
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Tests\TestCase;
|
||||
|
||||
class SeedMutualSmepCarouselTest extends TestCase
|
||||
{
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
Storage::fake('s3');
|
||||
$this->createSchema();
|
||||
|
||||
DB::table('tenants')->insert([
|
||||
'codigo' => 'mutual_smep',
|
||||
'storefront_website_type_code' => 'shopit',
|
||||
]);
|
||||
DB::table('storefront_website_type_extras')->insert([
|
||||
'storefront_website_type_code' => 'shopit',
|
||||
'codigo' => 'carousel',
|
||||
]);
|
||||
}
|
||||
|
||||
protected function tearDown(): void
|
||||
{
|
||||
foreach (['websites_extras', 'attachments', 'storefront_website_type_extras', 'tenants'] as $table) {
|
||||
Schema::dropIfExists($table);
|
||||
}
|
||||
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
public function test_it_loads_and_rolls_back_the_mutual_smep_carousel(): void
|
||||
{
|
||||
$migration = require database_path(
|
||||
'migrations/2026_09_24_040000_seed_mutual_smep_carousel.php'
|
||||
);
|
||||
|
||||
$migration->up();
|
||||
$migration->up();
|
||||
|
||||
$this->assertDatabaseCount('attachments', 4);
|
||||
$this->assertDatabaseCount('websites_extras', 1);
|
||||
|
||||
$attachments = DB::table('attachments')->orderBy('filename')->get();
|
||||
$this->assertSame([
|
||||
'01-tecnologia.webp',
|
||||
'02-hogar.webp',
|
||||
'03-vida-activa.webp',
|
||||
'04-descanso.webp',
|
||||
], $attachments->pluck('filename')->all());
|
||||
$this->assertSame(
|
||||
$attachments->pluck('id')->all(),
|
||||
json_decode(
|
||||
DB::table('websites_extras')->value('config'),
|
||||
true,
|
||||
flags: JSON_THROW_ON_ERROR,
|
||||
),
|
||||
);
|
||||
|
||||
foreach ($attachments as $attachment) {
|
||||
$this->assertSame('image/webp', $attachment->mime_type);
|
||||
$this->assertStringStartsWith(
|
||||
'tenants/mutual_smep/extras/carousel-v1/',
|
||||
$attachment->path,
|
||||
);
|
||||
Storage::disk('s3')->assertExists($attachment->path);
|
||||
}
|
||||
|
||||
$storedPaths = $attachments->pluck('path')->all();
|
||||
$migration->down();
|
||||
|
||||
$this->assertDatabaseCount('websites_extras', 0);
|
||||
$this->assertDatabaseCount('attachments', 0);
|
||||
|
||||
foreach ($storedPaths as $storedPath) {
|
||||
Storage::disk('s3')->assertMissing($storedPath);
|
||||
}
|
||||
}
|
||||
|
||||
private function createSchema(): void
|
||||
{
|
||||
Schema::create('tenants', function (Blueprint $table): void {
|
||||
$table->string('codigo')->primary();
|
||||
$table->string('storefront_website_type_code');
|
||||
});
|
||||
Schema::create('storefront_website_type_extras', function (Blueprint $table): void {
|
||||
$table->id();
|
||||
$table->string('storefront_website_type_code');
|
||||
$table->string('codigo');
|
||||
});
|
||||
Schema::create('attachments', function (Blueprint $table): void {
|
||||
$table->id();
|
||||
$table->uuid('key')->unique();
|
||||
$table->string('path');
|
||||
$table->string('filename');
|
||||
$table->string('type');
|
||||
$table->string('mime_type');
|
||||
$table->string('extension')->nullable();
|
||||
$table->unsignedBigInteger('size')->default(0);
|
||||
$table->timestamps();
|
||||
});
|
||||
Schema::create('websites_extras', function (Blueprint $table): void {
|
||||
$table->id();
|
||||
$table->string('website_code');
|
||||
$table->unsignedBigInteger('website_type_extra_id');
|
||||
$table->json('config');
|
||||
$table->boolean('is_enabled')->default(true);
|
||||
$table->timestamps();
|
||||
$table->unique(['website_code', 'website_type_extra_id']);
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user