refactor(catalog): Complete catalog refactor to simplify its data model and its querying.
source commits: refactor/catalog
This commit is contained in:
@@ -7,9 +7,10 @@ use App\Domains\Attachable\Models\Attachment;
|
||||
use App\Domains\Auth\Models\User;
|
||||
use App\Domains\Cart\Models\Cart;
|
||||
use App\Domains\Catalog\Enums\InventoryPolicy;
|
||||
use App\Domains\Catalog\Models\CatalogItem;
|
||||
use App\Domains\Catalog\Models\Category;
|
||||
use App\Domains\Catalog\Models\Product;
|
||||
use App\Domains\Catalog\Models\ProductVariant;
|
||||
use App\Domains\Catalog\Models\Inventory;
|
||||
use App\Domains\Catalog\Models\Variant;
|
||||
use App\Domains\Integration\Models\Integration;
|
||||
use App\Domains\Integration\Models\TenantIntegration;
|
||||
use App\Domains\Purchase\Models\Purchase;
|
||||
@@ -177,17 +178,17 @@ class TelepagosWebhookTest extends TestCase
|
||||
|
||||
$this->assertDatabaseHas('compra_items', [
|
||||
'compra_id' => $matchingPurchase->id,
|
||||
'buyable_type' => ProductVariant::class,
|
||||
'buyable_id' => $variant->id,
|
||||
'source_catalog_item_id' => $variant->catalog_item_id,
|
||||
'source_variant_id' => $variant->id,
|
||||
'cantidad' => 1,
|
||||
'total' => 50,
|
||||
]);
|
||||
|
||||
$this->assertDatabaseHas('productos_variantes', [
|
||||
'id' => $variant->id,
|
||||
'stock_real' => 9,
|
||||
'stock_reservado' => 2,
|
||||
'cantidad_vendida' => 1,
|
||||
$this->assertDatabaseHas('inventories', [
|
||||
'id' => $variant->inventory_id,
|
||||
'real_stock' => 9,
|
||||
'reserved_stock' => 2,
|
||||
'sold_units' => 1,
|
||||
]);
|
||||
|
||||
$this->assertDatabaseMissing('compra_items', [
|
||||
@@ -244,12 +245,11 @@ class TelepagosWebhookTest extends TestCase
|
||||
'id' => $purchase->id,
|
||||
'status' => Purchase::STATUS_PAID,
|
||||
]);
|
||||
$this->assertDatabaseHas('productos_variantes', [
|
||||
'id' => $variant->id,
|
||||
'inventory_policy' => InventoryPolicy::Unlimited->value,
|
||||
'stock_real' => 0,
|
||||
'stock_reservado' => 0,
|
||||
'cantidad_vendida' => 3,
|
||||
$this->assertDatabaseHas('inventories', [
|
||||
'id' => $variant->inventory_id,
|
||||
'real_stock' => 0,
|
||||
'reserved_stock' => 0,
|
||||
'sold_units' => 3,
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -266,7 +266,8 @@ class TelepagosWebhookTest extends TestCase
|
||||
'status' => 'active',
|
||||
]);
|
||||
|
||||
$cart->addItem(ProductVariant::class, $variantId, $quantity);
|
||||
$variant = Variant::query()->findOrFail($variantId);
|
||||
$cart->addItem($variant->catalog_item_id, $variant->id, $quantity);
|
||||
|
||||
/** @var CheckoutService $checkoutService */
|
||||
$checkoutService = app(CheckoutService::class);
|
||||
@@ -317,30 +318,27 @@ class TelepagosWebhookTest extends TestCase
|
||||
string $price,
|
||||
string $slugPrefix = 'shirt',
|
||||
InventoryPolicy $inventoryPolicy = InventoryPolicy::Tracked,
|
||||
): ProductVariant {
|
||||
): Variant {
|
||||
$category = Category::query()->create([
|
||||
'tenant_code' => $tenantCode,
|
||||
'nombre' => "{$slugPrefix} category {$tenantCode}",
|
||||
]);
|
||||
|
||||
$product = Product::query()->create([
|
||||
'tenant_codigo' => $tenantCode,
|
||||
'categoria_id' => $category->id,
|
||||
'slug' => "{$slugPrefix}-{$tenantCode}-".Product::query()->count(),
|
||||
$inventory = Inventory::query()->create(['real_stock' => $stock]);
|
||||
$catalogItem = CatalogItem::query()->create([
|
||||
'tenant_code' => $tenantCode,
|
||||
'category_id' => $category->id,
|
||||
'slug' => "{$slugPrefix}-{$tenantCode}-".CatalogItem::query()->count(),
|
||||
'nombre' => ucfirst($slugPrefix)." {$tenantCode}",
|
||||
'descripcion' => 'Test product',
|
||||
'precio' => $price,
|
||||
'inventory_policy' => $inventoryPolicy,
|
||||
]);
|
||||
|
||||
return ProductVariant::query()->create([
|
||||
'producto_id' => $product->id,
|
||||
'inventory_policy' => $inventoryPolicy->value,
|
||||
'slug' => "{$slugPrefix}-variant-".ProductVariant::query()->count(),
|
||||
'nombre' => ucfirst($slugPrefix).' Variant',
|
||||
'stock' => $stock,
|
||||
'descripcion' => 'Test variant',
|
||||
'precio' => $price,
|
||||
])->load('product');
|
||||
return Variant::query()->create([
|
||||
'catalog_item_id' => $catalogItem->id,
|
||||
'inventory_id' => $inventory->id,
|
||||
])->load(['catalogItem', 'inventory']);
|
||||
}
|
||||
|
||||
private function createTenant(string $codigo, string $nombre, string $dominio): Tenant
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Integration;
|
||||
|
||||
use App\Domains\Integration\Models\Integration;
|
||||
use App\Domains\Integration\Models\TenantIntegration;
|
||||
use App\Domains\Integration\Services\TenantIntegrationService;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Mockery;
|
||||
use Tests\TestCase;
|
||||
|
||||
class TenantIntegrationControllerTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_store_returns_success_message_without_integration_data(): void
|
||||
{
|
||||
$integration = Integration::create([
|
||||
'integration_code' => 'test_integration',
|
||||
'name' => 'Test Integration',
|
||||
'integration_data_schema' => [
|
||||
'api_key' => 'required|string',
|
||||
],
|
||||
]);
|
||||
|
||||
$this->mock(TenantIntegrationService::class, function ($mock) use ($integration) {
|
||||
$mock->shouldReceive('updateOrCreateIntegration')
|
||||
->once()
|
||||
->with(
|
||||
'test-tenant',
|
||||
Mockery::on(fn (Integration $argument) => $argument->is($integration)),
|
||||
['api_key' => 'secret']
|
||||
)
|
||||
->andReturn(new TenantIntegration());
|
||||
});
|
||||
|
||||
$this->postJson('/api/test-tenant/integrations/test_integration', [
|
||||
'integration_data' => [
|
||||
'api_key' => 'secret',
|
||||
],
|
||||
])->assertOk()
|
||||
->assertExactJson([
|
||||
'message' => 'integration configured correctly',
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user