fix(checkout): defer catalog refresh for expired reservations
This commit is contained in:
@@ -58,6 +58,27 @@ describe('CheckoutService', () => {
|
|||||||
expect(notifyAvailabilityChanged).toHaveBeenCalledOnce();
|
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 () => {
|
it('preserves checkout timing fields when completing a purchase', async () => {
|
||||||
const purchasePromise = service.completePurchase('desfile', 55);
|
const purchasePromise = service.completePurchase('desfile', 55);
|
||||||
const request = httpMock.expectOne(`${environment.url}tenants/desfile/compras/55/complete`);
|
const request = httpMock.expectOne(`${environment.url}tenants/desfile/compras/55/complete`);
|
||||||
|
|||||||
@@ -149,7 +149,10 @@ export class CheckoutService extends BaseApiService {
|
|||||||
|
|
||||||
return purchase;
|
return purchase;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.catalogAvailabilityService.notifyAvailabilityChanged();
|
const responseBody = (error as { error?: unknown } | null)?.error;
|
||||||
|
if (!isExpiredStockReservationResponse(responseBody)) {
|
||||||
|
this.catalogAvailabilityService.notifyAvailabilityChanged();
|
||||||
|
}
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user