Skip to content

Commit

Permalink
fix: lints
Browse files Browse the repository at this point in the history
  • Loading branch information
amihajlovski committed Jan 14, 2025
1 parent 3215e0f commit 0dcd166
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ describe('callSelectShippingMethod', () => {
currentBasket = BasketMgr.getCurrentBasket.mockReturnValueOnce(null);
callSelectShippingMethod(req, res, next);
expect(res.json).toHaveBeenCalledWith({
error: true,
redirectUrl: URLUtils.url('Cart-Show').toString(),
});
error: true,
redirectUrl: URLUtils.url('Cart-Show').toString(),
});
expect(next).toHaveBeenCalled();
});

Expand All @@ -51,8 +51,8 @@ describe('callSelectShippingMethod', () => {

expect(res.setStatusCode).toHaveBeenCalledWith(500);
expect(res.json).toHaveBeenCalledWith({
errorMessage: 'mocked_error.cannot.select.shipping.method',
});
errorMessage: 'mocked_error.cannot.select.shipping.method',
});
expect(next).toHaveBeenCalled();
});

Expand Down Expand Up @@ -90,4 +90,4 @@ describe('callSelectShippingMethod', () => {
});
expect(next).toHaveBeenCalled();
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ beforeEach(() => {
req = {
form: {
data: JSON.stringify({address:{
city: 'Amsterdam',
countryCode: 'NL',
stateCode: 'AMS',
postalCode: '1001',
shipmentUUID: 'mocked_uuid',
}})
city: 'Amsterdam',
countryCode: 'NL',
stateCode: 'AMS',
postalCode: '1001',
shipmentUUID: 'mocked_uuid',
}})
},
};

Expand Down Expand Up @@ -79,28 +79,27 @@ describe('Shipping methods', () => {
});
});

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);
});

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
Expand Up @@ -16,7 +16,16 @@ const paypalHelper = require('*/cartridge/adyen/utils/paypalHelper');
*/
// eslint-disable-next-line complexity
function callSelectShippingMethod(req, res, next) {
const currentBasket = BasketMgr.getCurrentBasket();
const {
basketId,
shipmentUUID,
methodID,
currentPaymentData,
paymentMethodType,
} = JSON.parse(req.form.data);
const currentBasket = basketId
? BasketMgr.getTemporaryBasket(basketId)
: BasketMgr.getCurrentBasket();

if (!currentBasket) {
res.json({
Expand All @@ -27,8 +36,6 @@ function callSelectShippingMethod(req, res, next) {
return next();
}
try {
const { shipmentUUID, methodID, currentPaymentData, paymentMethodType } =
JSON.parse(req.body);
let shipment;
if (shipmentUUID) {
shipment = shippingHelper.getShipmentByUUID(currentBasket, shipmentUUID);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,19 @@ function updateShippingAddress(currentBasket, address) {
}
}

function getBasket(basketId) {
return basketId
? BasketMgr.getTemporaryBasket(basketId)
: BasketMgr.getCurrentBasket();
}
/**
* Make a request to Adyen to get shipping methods
*/
function callGetShippingMethods(req, res, next) {
try {
const { address, currentPaymentData, paymentMethodType } = JSON.parse(
req.body,
);
const currentBasket = BasketMgr.getCurrentBasket();
const { address, currentPaymentData, paymentMethodType, basketId } =
JSON.parse(req.form.data);
const currentBasket = getBasket(basketId);
if (!currentBasket) {
res.json({
error: true,
Expand Down

0 comments on commit 0dcd166

Please sign in to comment.