Skip to content

Commit

Permalink
Calculate correct tax for applePay express (#1079)
Browse files Browse the repository at this point in the history
* fix: calculate correct tax for applePay express

* test: update unit tests
  • Loading branch information
shanikantsingh committed May 7, 2024
1 parent 125e268 commit 953500d
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ initializeCheckout()
country: shippingContact.country,
countryCode: shippingContact.countryCode,
stateCode: shippingContact.administrativeArea,
postalCode: shippingContact.postalCode,
})}`,
);
if (shippingMethods.ok) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
/* eslint-disable global-require */
const BasketMgr = require('dw/order/BasketMgr');
const AdyenHelper = require('*/cartridge/adyen/utils/adyenHelper');

let res;
let req;
const next = jest.fn();

const callGetShippingMethods = require('../shippingMethods');
const Logger = require("../../../../../../../../jest/__mocks__/dw/system/Logger");

beforeEach(() => {
jest.clearAllMocks();
Expand All @@ -15,6 +17,7 @@ beforeEach(() => {
city: 'Amsterdam',
countryCode: 'NL',
stateCode: 'AMS',
postalCode: '1001',
shipmentUUID: 'mocked_uuid',
},
locale: { id: 'nl_NL' },
Expand Down Expand Up @@ -52,4 +55,28 @@ describe('Shipping methods', () => {
callGetShippingMethods(req, res, next);
expect(res.json).not.toHaveBeenCalled();
});
it('Should update shipping address for the basket', () => {
const Logger = require('../../../../../../../../jest/__mocks__/dw/system/Logger');
const setCityMock = jest.fn()
const setPostalCodeMock = jest.fn()
const setStateCodeMock = jest.fn()
const setCountryCodeMock = jest.fn()
const currentBasketMock = {
getDefaultShipment: jest.fn(() =>({
createShippingAddress: jest.fn(() => ({
setCity: setCityMock,
setPostalCode: setPostalCodeMock,
setStateCode: setStateCodeMock,
setCountryCode: setCountryCodeMock
}))
})),
};
BasketMgr.getCurrentBasket.mockReturnValueOnce(currentBasketMock);
callGetShippingMethods(req, res, next);
expect(setCityMock).toHaveBeenCalledWith('Amsterdam');
expect(setPostalCodeMock).toHaveBeenCalledWith('1001');
expect(setStateCodeMock).toHaveBeenCalledWith('AMS');
expect(setCountryCodeMock).toHaveBeenCalledWith('NL');
expect(Logger.error.mock.calls.length).toBe(0);
});
});
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const BasketMgr = require('dw/order/BasketMgr');
const Transaction = require('dw/system/Transaction');
const AdyenLogs = require('*/cartridge/adyen/logs/adyenCustomLogs');
const AdyenHelper = require('*/cartridge/adyen/utils/adyenHelper');

Expand All @@ -13,14 +14,25 @@ function callGetShippingMethods(req, res, next) {
city: req.querystring.city,
countryCode: req.querystring.countryCode,
stateCode: req.querystring.stateCode,
postalCode: req.querystring.postalCode,
};
}
const currentBasket = BasketMgr.getCurrentBasket();
const shipment = currentBasket.getDefaultShipment();
Transaction.wrap(() => {
let { shippingAddress } = shipment;
if (!shippingAddress) {
shippingAddress = currentBasket
.getDefaultShipment()
.createShippingAddress();
}
shippingAddress.setCity(address.city);
shippingAddress.setPostalCode(address.postalCode);
shippingAddress.setStateCode(address.stateCode);
shippingAddress.setCountryCode(address.countryCode);
});
const currentShippingMethodsModels =
AdyenHelper.getApplicableShippingMethods(
currentBasket.getDefaultShipment(),
address,
);
AdyenHelper.getApplicableShippingMethods(shipment, address);
res.json({
shippingMethods: currentShippingMethodsModels,
});
Expand Down

0 comments on commit 953500d

Please sign in to comment.