feat: update product and variant resources to improve variant selection handling and response structure
This commit is contained in:
@@ -389,7 +389,7 @@ class ProductControllerTest extends TestCase
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_it_returns_product_detail_with_variants_and_default_variant(): void
|
||||
public function test_it_returns_product_detail_with_variants_and_selected_variant_resource(): void
|
||||
{
|
||||
// 1. Create a product
|
||||
$product = Product::create([
|
||||
@@ -436,26 +436,36 @@ class ProductControllerTest extends TestCase
|
||||
|
||||
$response->assertOk();
|
||||
|
||||
// 4. Assert default_variant structure and data
|
||||
// 4. Assert selected variant resource structure and data
|
||||
$response->assertJsonStructure([
|
||||
'data' => [
|
||||
'id',
|
||||
'nombre',
|
||||
'default_variant' => [
|
||||
'variant_id',
|
||||
'variant' => [
|
||||
'id',
|
||||
'producto_id',
|
||||
'stock',
|
||||
'images',
|
||||
'attributes' => [
|
||||
'talle',
|
||||
'color',
|
||||
'definitions' => [
|
||||
'*' => [
|
||||
'id',
|
||||
'producto_variante_id',
|
||||
'products_attribute_id',
|
||||
'attribute_id',
|
||||
'value',
|
||||
'attribute',
|
||||
'metadata',
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
]);
|
||||
|
||||
$response->assertJsonPath('data.default_variant.variant_id', $variant->id);
|
||||
$response->assertJsonPath('data.default_variant.attributes.talle', 'S');
|
||||
$response->assertJsonPath('data.default_variant.attributes.color', 'Azul');
|
||||
$response->assertJsonCount(1, 'data.default_variant.images');
|
||||
$response->assertJsonPath('data.variant.id', $variant->id);
|
||||
$response->assertJsonPath('data.variant.producto_id', $product->id);
|
||||
$response->assertJsonPath('data.variant.stock', 10);
|
||||
$response->assertJsonCount(1, 'data.variant.images');
|
||||
$response->assertJsonCount(2, 'data.variant.definitions');
|
||||
}
|
||||
|
||||
protected function createTenant(string $codigo, string $nombre, string $dominio): Tenant
|
||||
|
||||
Reference in New Issue
Block a user