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