fix(purchase-status): clear cart on approved purchase
This commit is contained in:
@@ -5,6 +5,7 @@ import {
|
||||
CheckoutService,
|
||||
PurchaseDetailResponse,
|
||||
} from '../../../../core/services/checkout.service';
|
||||
import { CartService } from '../../../../core/services/cart/cart.service';
|
||||
import { Tenant } from '../../../../core/services/tenant.interface';
|
||||
import { TenantService } from '../../../../core/services/tenant.service';
|
||||
import { PurchaseStatusPageComponent } from './purchase-status-page.component';
|
||||
@@ -77,11 +78,13 @@ describe('PurchaseStatusPageComponent', () => {
|
||||
navigate: vi.fn().mockResolvedValue(true),
|
||||
navigateByUrl: vi.fn().mockResolvedValue(true),
|
||||
};
|
||||
const cartService = { clearCart: vi.fn() };
|
||||
|
||||
await TestBed.configureTestingModule({
|
||||
imports: [PurchaseStatusPageComponent],
|
||||
providers: [
|
||||
{ provide: CheckoutService, useValue: checkoutService },
|
||||
{ provide: CartService, useValue: cartService },
|
||||
{ provide: TenantService, useValue: { tenant: () => tenant } },
|
||||
{
|
||||
provide: ActivatedRoute,
|
||||
@@ -107,15 +110,22 @@ describe('PurchaseStatusPageComponent', () => {
|
||||
fixture,
|
||||
element: fixture.nativeElement as HTMLElement,
|
||||
checkoutService,
|
||||
cartService,
|
||||
router,
|
||||
};
|
||||
}
|
||||
|
||||
it('clears the cart when the purchase is approved', async () => {
|
||||
const { cartService } = await render(true);
|
||||
|
||||
expect(cartService.clearCart).toHaveBeenCalledOnce();
|
||||
});
|
||||
|
||||
it('shows the tickets action when this purchase generated tickets', async () => {
|
||||
const { element, checkoutService, router } = await render(true);
|
||||
|
||||
expect(checkoutService.getPurchase).toHaveBeenCalledOnce();
|
||||
expect(element.textContent).toContain('Ver mis tickets');
|
||||
expect(element.textContent).toContain('Mis tickets');
|
||||
expect(element.textContent).not.toContain('WhatsApp');
|
||||
|
||||
element.querySelector<HTMLButtonElement>('app-button button')?.click();
|
||||
@@ -162,11 +172,13 @@ describe('PurchaseStatusPageComponent', () => {
|
||||
return this;
|
||||
},
|
||||
};
|
||||
const cartService = { clearCart: vi.fn() };
|
||||
|
||||
await TestBed.configureTestingModule({
|
||||
imports: [PurchaseStatusPageComponent],
|
||||
providers: [
|
||||
{ provide: CheckoutService, useValue: checkoutService },
|
||||
{ provide: CartService, useValue: cartService },
|
||||
{ provide: TenantService, useValue: { tenant: () => tenant } },
|
||||
{
|
||||
provide: ActivatedRoute,
|
||||
@@ -189,6 +201,7 @@ describe('PurchaseStatusPageComponent', () => {
|
||||
|
||||
expect(checkoutService.getPurchase).toHaveBeenCalledTimes(2);
|
||||
expect(fixture.nativeElement.textContent).toContain('COMPRA REALIZADA!');
|
||||
expect(cartService.clearCart).toHaveBeenCalledOnce();
|
||||
|
||||
await vi.advanceTimersByTimeAsync(10_000);
|
||||
expect(checkoutService.getPurchase).toHaveBeenCalledTimes(2);
|
||||
@@ -212,6 +225,7 @@ describe('PurchaseStatusPageComponent', () => {
|
||||
imports: [PurchaseStatusPageComponent],
|
||||
providers: [
|
||||
{ provide: CheckoutService, useValue: checkoutService },
|
||||
{ provide: CartService, useValue: { clearCart: vi.fn() } },
|
||||
{ provide: TenantService, useValue: { tenant: () => tenant } },
|
||||
{
|
||||
provide: ActivatedRoute,
|
||||
|
||||
@@ -15,6 +15,7 @@ import {
|
||||
CheckoutService,
|
||||
PurchaseStatusResponse,
|
||||
} from '../../../../core/services/checkout.service';
|
||||
import { CartService } from '../../../../core/services/cart/cart.service';
|
||||
import { findMenu } from '../../../../core/services/menu.utils';
|
||||
import { TenantService } from '../../../../core/services/tenant.service';
|
||||
import { ButtonComponent } from '../../../../shared/components/button/button.component';
|
||||
@@ -35,6 +36,7 @@ export class PurchaseStatusPageComponent implements OnInit, OnDestroy {
|
||||
private readonly route = inject(ActivatedRoute);
|
||||
private readonly router = inject(Router);
|
||||
private readonly checkoutService = inject(CheckoutService);
|
||||
private readonly cartService = inject(CartService);
|
||||
private readonly tenantService = inject(TenantService);
|
||||
private readonly isBrowser = isPlatformBrowser(inject(PLATFORM_ID));
|
||||
|
||||
@@ -104,6 +106,10 @@ export class PurchaseStatusPageComponent implements OnInit, OnDestroy {
|
||||
this.status.set(status);
|
||||
this.hasGeneratedTickets.set(purchase.has_generated_tickets === true);
|
||||
|
||||
if (status === 'approved') {
|
||||
this.cartService.clearCart();
|
||||
}
|
||||
|
||||
if (status === 'pending') {
|
||||
this.schedulePolling();
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user