Merge branch 'refactor/inventory_stock' of https://gitea.quo.ar/tbianchini/shopit-back into refactor/inventory_stock

This commit is contained in:
2026-09-29 08:23:09 -03:00
parent c5aeb19735
commit 96378a6c2e
596 changed files with 239 additions and 7622 deletions

View File

@@ -1,119 +0,0 @@
<?php
namespace Tests\Feature\Seeders;
use Database\Seeders\MutualSmepAttributeSeeder;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
use Tests\TestCase;
class MutualSmepAttributeSeederTest extends TestCase
{
protected function setUp(): void
{
parent::setUp();
Schema::create('tenants', function (Blueprint $table): void {
$table->string('codigo')->primary();
});
Schema::create('attribute', function (Blueprint $table): void {
$table->id();
$table->string('tenant_codigo');
$table->string('codigo');
$table->string('nombre');
$table->boolean('is_required')->default(false);
$table->json('metadata_schema')->nullable();
$table->string('type');
$table->timestamps();
$table->unique(['tenant_codigo', 'codigo']);
});
Schema::create('attribute_options', function (Blueprint $table): void {
$table->id();
$table->foreignId('attribute_id')->constrained('attribute')->cascadeOnDelete();
$table->string('value');
$table->string('label');
$table->unsignedInteger('sort_order')->default(0);
$table->json('metadata')->nullable();
$table->timestamps();
});
}
protected function tearDown(): void
{
Schema::dropIfExists('attribute_options');
Schema::dropIfExists('attribute');
Schema::dropIfExists('tenants');
parent::tearDown();
}
public function test_it_creates_the_attributes_and_options_idempotently(): void
{
$this->createTenant('mutual_smep');
$this->seed(MutualSmepAttributeSeeder::class);
$this->seed(MutualSmepAttributeSeeder::class);
$this->assertSame(5, DB::table('attribute')->where('tenant_codigo', 'mutual_smep')->count());
$this->assertSame(25, DB::table('attribute_options')->count());
$this->assertDatabaseHas('attribute', [
'tenant_codigo' => 'mutual_smep',
'codigo' => 'medida_cama',
'nombre' => 'Medida',
'type' => 'select',
'is_required' => false,
]);
$this->assertDatabaseHas('attribute_options', [
'value' => '512 GB',
'label' => '512 GB',
]);
}
public function test_down_only_removes_mutual_smep_attributes(): void
{
$this->createTenant('mutual_smep');
$this->createTenant('other');
DB::table('attribute')->insert([
'tenant_codigo' => 'other',
'codigo' => 'color',
'nombre' => 'Color',
'type' => 'select',
'created_at' => now(),
'updated_at' => now(),
]);
$seeder = app(MutualSmepAttributeSeeder::class);
$seeder->run();
$seeder->down();
$this->assertDatabaseMissing('attribute', ['tenant_codigo' => 'mutual_smep']);
$this->assertDatabaseHas('attribute', [
'tenant_codigo' => 'other',
'codigo' => 'color',
]);
}
public function test_the_data_migration_runs_and_rolls_back_the_attributes(): void
{
$this->createTenant('mutual_smep');
$migration = require database_path(
'migrations/2026_09_24_020000_seed_mutual_smep_attributes.php'
);
$migration->up();
$this->assertSame(5, DB::table('attribute')->where('tenant_codigo', 'mutual_smep')->count());
$this->assertSame(25, DB::table('attribute_options')->count());
$migration->down();
$this->assertDatabaseMissing('attribute', ['tenant_codigo' => 'mutual_smep']);
$this->assertSame(0, DB::table('attribute_options')->count());
}
private function createTenant(string $code): void
{
DB::table('tenants')->insert(['codigo' => $code]);
}
}

View File

@@ -1,119 +0,0 @@
<?php
namespace Tests\Feature\Seeders;
use App\Domains\Commerce\Catalog\Models\Category;
use Database\Seeders\MutualSmepCategorySeeder;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
use Tests\TestCase;
class MutualSmepCategorySeederTest extends TestCase
{
protected function setUp(): void
{
parent::setUp();
Schema::create('tenants', function (Blueprint $table): void {
$table->string('codigo')->primary();
});
Schema::create('categorias', function (Blueprint $table): void {
$table->id();
$table->string('tenant_code')->nullable();
$table->unsignedBigInteger('categoria_id')->nullable();
$table->string('nombre');
$table->boolean('is_enabled')->default(true);
$table->timestamps();
});
}
protected function tearDown(): void
{
Schema::dropIfExists('categorias');
Schema::dropIfExists('tenants');
parent::tearDown();
}
public function test_it_creates_the_mutual_smep_category_hierarchy_idempotently(): void
{
$this->createTenant('mutual_smep');
$this->seed(MutualSmepCategorySeeder::class);
$this->seed(MutualSmepCategorySeeder::class);
$parents = Category::query()
->where('tenant_code', 'mutual_smep')
->whereNull('categoria_id')
->with('subCategories')
->get()
->keyBy('nombre');
$this->assertCount(6, $parents);
$this->assertCount(37, Category::query()->where('tenant_code', 'mutual_smep')->get());
$this->assertEqualsCanonicalizing([
'Colchones',
'Bases y Sommiers',
'Acolchados y Edredones',
'Frazadas y Mantas',
'Infantil y Cuna',
], $parents->get('Dormitorio y Blanco')->subCategories->pluck('nombre')->all());
$this->assertEqualsCanonicalizing([
'Celulares',
'Notebooks',
'Smart TV',
'Audio',
'Accesorios de Computación',
'Soportes para TV',
], $parents->get('Tecnología')->subCategories->pluck('nombre')->all());
}
public function test_down_removes_only_the_seeded_mutual_smep_hierarchy(): void
{
$this->createTenant('mutual_smep');
$this->createTenant('other');
Category::query()->create([
'tenant_code' => 'other',
'nombre' => 'Tecnología',
]);
$seeder = app(MutualSmepCategorySeeder::class);
$seeder->run();
$seeder->down();
$this->assertDatabaseMissing('categorias', [
'tenant_code' => 'mutual_smep',
]);
$this->assertDatabaseHas('categorias', [
'tenant_code' => 'other',
'nombre' => 'Tecnología',
]);
}
public function test_the_data_migration_runs_and_rolls_back_the_seeder(): void
{
$this->createTenant('mutual_smep');
$migration = require database_path(
'migrations/2026_09_24_010000_seed_mutual_smep_categories.php'
);
$migration->up();
$this->assertCount(37, Category::query()->where('tenant_code', 'mutual_smep')->get());
$migration->down();
$this->assertDatabaseMissing('categorias', [
'tenant_code' => 'mutual_smep',
]);
}
private function createTenant(string $code): void
{
DB::table('tenants')->insert([
'codigo' => $code,
]);
}
}