feat: implement product and variant CRUD management service with attachment handling
This commit is contained in:
@@ -722,6 +722,52 @@ class ProductControllerTest extends TestCase
|
||||
$this->assertEquals(0, $defaultVariant->definitions()->count());
|
||||
}
|
||||
|
||||
public function test_it_rejects_product_detail_when_requested_variant_has_no_stock(): void
|
||||
{
|
||||
$product = Product::create([
|
||||
'tenant_codigo' => $this->tenant->codigo,
|
||||
'categoria_id' => 1,
|
||||
'brand_id' => $this->brand->id,
|
||||
'slug' => 'test-product-no-stock',
|
||||
'nombre' => 'Test Product No Stock',
|
||||
'precio' => 100.00,
|
||||
]);
|
||||
$productAttributes = $this->syncVariantAttributes($product);
|
||||
|
||||
$outOfStockVariant = $product->createVariant([
|
||||
'stock' => 0,
|
||||
'definitions' => [
|
||||
[
|
||||
'products_attribute_id' => $productAttributes['size']->id,
|
||||
'value' => 'S',
|
||||
],
|
||||
],
|
||||
]);
|
||||
|
||||
$response = $this->getJson("/api/tenants/{$this->tenant->codigo}/productos/{$product->id}?variant_id={$outOfStockVariant->id}");
|
||||
|
||||
$response->assertUnprocessable();
|
||||
$response->assertJsonValidationErrors(['variant_id']);
|
||||
$response->assertJsonPath('errors.variant_id.0', 'La variante seleccionada no tiene stock.');
|
||||
}
|
||||
|
||||
public function test_it_rejects_product_detail_when_requested_variant_id_is_invalid_format(): void
|
||||
{
|
||||
$product = Product::create([
|
||||
'tenant_codigo' => $this->tenant->codigo,
|
||||
'categoria_id' => 1,
|
||||
'brand_id' => $this->brand->id,
|
||||
'slug' => 'test-product-invalid-format',
|
||||
'nombre' => 'Test Product Invalid Format',
|
||||
'precio' => 100.00,
|
||||
]);
|
||||
|
||||
$response = $this->getJson("/api/tenants/{$this->tenant->codigo}/productos/{$product->id}?variant_id=abc");
|
||||
|
||||
$response->assertUnprocessable();
|
||||
$response->assertJsonValidationErrors(['variant_id']);
|
||||
}
|
||||
|
||||
private function createAttachment(string $path): Attachment
|
||||
{
|
||||
return Attachment::create([
|
||||
|
||||
Reference in New Issue
Block a user