diff --git a/src/app/core/services/checkout.service.spec.ts b/src/app/core/services/checkout.service.spec.ts index ee3adb7..8bfede7 100644 --- a/src/app/core/services/checkout.service.spec.ts +++ b/src/app/core/services/checkout.service.spec.ts @@ -58,6 +58,27 @@ describe('CheckoutService', () => { expect(notifyAvailabilityChanged).toHaveBeenCalledOnce(); }); + it('waits for the expired cart refresh before refreshing catalog availability', async () => { + const catalogAvailabilityService = TestBed.inject(CatalogAvailabilityService); + const notifyAvailabilityChanged = vi.spyOn( + catalogAvailabilityService, + 'notifyAvailabilityChanged', + ); + const purchasePromise = service.startCheckout('desfile', { cart_id: 12 }); + const request = httpMock.expectOne(`${environment.url}tenants/desfile/compras/start-checkout`); + + request.flush( + { + code: 'stock_reservation.expired', + message: 'La reserva de stock venció.', + }, + { status: 422, statusText: 'Unprocessable Entity' }, + ); + + await expect(purchasePromise).rejects.toBeTruthy(); + expect(notifyAvailabilityChanged).not.toHaveBeenCalled(); + }); + it('preserves checkout timing fields when completing a purchase', async () => { const purchasePromise = service.completePurchase('desfile', 55); const request = httpMock.expectOne(`${environment.url}tenants/desfile/compras/55/complete`); diff --git a/src/app/core/services/checkout.service.ts b/src/app/core/services/checkout.service.ts index 70886d6..459f779 100644 --- a/src/app/core/services/checkout.service.ts +++ b/src/app/core/services/checkout.service.ts @@ -149,7 +149,10 @@ export class CheckoutService extends BaseApiService { return purchase; } catch (error) { - this.catalogAvailabilityService.notifyAvailabilityChanged(); + const responseBody = (error as { error?: unknown } | null)?.error; + if (!isExpiredStockReservationResponse(responseBody)) { + this.catalogAvailabilityService.notifyAvailabilityChanged(); + } throw error; } }