Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pickup in store for ApplePay #18643

Merged
merged 23 commits into from
Mar 21, 2024
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,21 @@
import { TestBed } from '@angular/core/testing';
import { DeliveryMode } from '@spartacus/cart/base/root';
import { Product, WindowRef } from '@spartacus/core';
import { OpfCartHandlerService } from '@spartacus/opf/base/core';
import {
OpfCartHandlerService,
OpfPickupInStoreHandlerService,
} from '@spartacus/opf/base/core';
import {
ApplePayObservableConfig,
ApplePayShippingType,
ApplePayTransactionInput,
OpfPaymentFacade,
OpfQuickBuyDeliveryInfo,
OpfQuickBuyDeliveryType,
} from '@spartacus/opf/base/root';
import { Subject, of, throwError } from 'rxjs';
import { Observable, Subject, of, throwError } from 'rxjs';
import { map } from 'rxjs/operators';
import { OpfQuickBuyService } from '../opf-quick-buy.service';
import { ApplePaySessionFactory } from './apple-pay-session/apple-pay-session.factory';
import { ApplePayService } from './apple-pay.service';
import { ApplePayObservableFactory } from './observable/apple-pay-observable.factory';
Expand Down Expand Up @@ -110,7 +118,15 @@ describe('ApplePayService', () => {
let applePayObservableFactoryMock: jasmine.SpyObj<ApplePayObservableFactory>;
let applePaySessionFactoryMock: jasmine.SpyObj<ApplePaySessionFactory>;
let applePayObservableTestController: Subject<ApplePayJS.ApplePayPaymentAuthorizationResult>;
let opfQuickBuyServiceMock: jasmine.SpyObj<OpfQuickBuyService>;
let opfPickupInStoreHandlerServiceMock: jasmine.SpyObj<OpfPickupInStoreHandlerService>;
beforeEach(() => {
opfQuickBuyServiceMock = jasmine.createSpyObj('OpfQuickBuyService', [
'getQuickBuyLocationContext',
'getQuickBuyProviderConfig',
'getQuickBuyDeliveryType',
]);

applePaySessionFactoryMock = jasmine.createSpyObj(
'ApplePaySessionFactory',
['startApplePaySession']
Expand Down Expand Up @@ -142,6 +158,10 @@ describe('ApplePayService', () => {
'removeProductFromOriginalCart',
'loadCartAfterSingleProductTransaction',
]);
opfPickupInStoreHandlerServiceMock = jasmine.createSpyObj(
'OpfPickupInStoreHandlerService',
['getSingleProductDeliveryInfo']
);
TestBed.configureTestingModule({
providers: [
ApplePayService,
Expand All @@ -156,6 +176,11 @@ describe('ApplePayService', () => {
provide: ApplePaySessionFactory,
useValue: applePaySessionFactoryMock,
},
{ provide: OpfQuickBuyService, useValue: opfQuickBuyServiceMock },
{
provide: OpfPickupInStoreHandlerService,
useValue: opfPickupInStoreHandlerServiceMock,
},
],
});
service = TestBed.inject(ApplePayService);
Expand All @@ -179,6 +204,9 @@ describe('ApplePayService', () => {
config = actualConfig;
return applePayObservableTestController;
});
opfQuickBuyServiceMock.getQuickBuyDeliveryType.and.returnValue(
of(OpfQuickBuyDeliveryType.SHIPPING)
);
});

it('should handle validateMerchant change', () => {
Expand Down Expand Up @@ -567,11 +595,79 @@ describe('ApplePayService', () => {
.start({ product: mockProduct, quantity: 1, countryCode: 'us' })
.subscribe({ error: () => {} });
});

it('should handle setApplePayRequestConfig with Pickup delivery type on Cart page', (done) => {
const transactionInputMock: ApplePayTransactionInput = {
product: undefined,
cart: mockCart,
quantity: 0,
countryCode: 'us',
};

const deliverInfoMock: OpfQuickBuyDeliveryInfo = {
type: OpfQuickBuyDeliveryType.PICKUP,
pickupDetails: { name: 'Nakano' },
};
opfQuickBuyServiceMock.getQuickBuyDeliveryType.and.returnValue(
of(OpfQuickBuyDeliveryType.PICKUP)
);

opfPickupInStoreHandlerServiceMock.getSingleProductDeliveryInfo.and.returnValue(
of(deliverInfoMock)
);

const setApplePayRequestConfig = service['setApplePayRequestConfig'](
transactionInputMock
) as Observable<ApplePayJS.ApplePayPaymentRequest>;
setApplePayRequestConfig.subscribe((config) => {
expect(config.requiredShippingContactFields).toEqual([]);
expect(config.shippingType).toEqual(ApplePayShippingType.STORE_PICKUP);
expect(
opfPickupInStoreHandlerServiceMock.getSingleProductDeliveryInfo
).not.toHaveBeenCalled();
done();
});
});

it('should handle setApplePayRequestConfig with Pickup delivery type on Product page', (done) => {
const transactionInputMock: ApplePayTransactionInput = {
product: mockProduct,
cart: undefined,
quantity: 1,
countryCode: 'us',
};

const deliverInfoMock: OpfQuickBuyDeliveryInfo = {
type: OpfQuickBuyDeliveryType.PICKUP,
pickupDetails: { name: 'Nakano' },
};
opfQuickBuyServiceMock.getQuickBuyDeliveryType.and.returnValue(
of(OpfQuickBuyDeliveryType.PICKUP)
);

opfPickupInStoreHandlerServiceMock.getSingleProductDeliveryInfo.and.returnValue(
of(deliverInfoMock)
);

const setApplePayRequestConfig = service['setApplePayRequestConfig'](
transactionInputMock
) as Observable<ApplePayJS.ApplePayPaymentRequest>;
setApplePayRequestConfig.subscribe((config) => {
expect(config.requiredShippingContactFields).toEqual([]);
expect(config.shippingType).toEqual(ApplePayShippingType.STORE_PICKUP);
expect(
opfPickupInStoreHandlerServiceMock.getSingleProductDeliveryInfo
).toHaveBeenCalled();
done();
});
});
});

it('should handle errors during Apple Pay session start', () => {
service = TestBed.inject(ApplePayService);

opfQuickBuyServiceMock.getQuickBuyDeliveryType.and.returnValue(
of(OpfQuickBuyDeliveryType.SHIPPING)
);
cartHandlerServiceMock.loadOriginalCart.and.returnValue(of(true));
cartHandlerServiceMock.removeProductFromOriginalCart.and.returnValue(
of(true)
Expand Down
Loading
Loading