Skip to content

Commit

Permalink
chore: added unit tests for checking the endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
zenit2001 committed Nov 29, 2024
1 parent 307da30 commit 872f046
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 4 deletions.
1 change: 1 addition & 0 deletions jest/__mocks__/dw/system/Site.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const getCurrent = jest.fn();
3 changes: 2 additions & 1 deletion jest/sfccCartridgeMocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ jest.mock(
jest.mock(
'*/cartridge/adyen/utils/adyenConfigs',
() => ({
getAdyenEnvironment: jest.fn(() => 'TEST'),
getAdyenEnvironment: jest.fn(),
getAdyenInstallmentsEnabled: jest.fn(() => true),
getCreditCardInstallments: jest.fn(() => true),
getAdyenTokenisationEnabled: jest.fn(() => true),
Expand All @@ -344,6 +344,7 @@ jest.mock(
getAdyen3DS2Enabled: jest.fn(() => false),
getAdyenLevel23DataEnabled: jest.fn(() => false),
getAdyenSalePaymentMethods: jest.fn(() => []),
getAdyenPosRegion: jest.fn(),
}),
{ virtual: true },
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable global-require */
const Money = require('../../../../../../../jest/__mocks__/dw/value/Money');
const { getApplicableShippingMethods } = require('../adyenHelper');
const { getApplicableShippingMethods, getTerminalApiEnvironment } = require('../adyenHelper');
const savePaymentDetails = require('../adyenHelper').savePaymentDetails;
describe('savePaymentDetails', () => {
let paymentInstrument;
Expand Down Expand Up @@ -116,3 +116,31 @@ describe('getApplicableShippingMethods', () => {
expect(shippingMethods).toBeNull();
})
})

describe('getTerminalApiEnvironment', () => {
beforeEach(() => {
jest.clearAllMocks();
});
it('should return TEST endpoint for TEST environment', () => {
const adyenConfigs = require('*/cartridge/adyen/utils/adyenConfigs');
adyenConfigs.getAdyenEnvironment.mockReturnValue('TEST');
const result = getTerminalApiEnvironment();
expect(result).toBe('test');
});

it('should return LIVE US endpoint for LIVE environment', () => {
const adyenConfigs = require('*/cartridge/adyen/utils/adyenConfigs');
adyenConfigs.getAdyenEnvironment.mockReturnValue('LIVE');
adyenConfigs.getAdyenPosRegion.mockReturnValue('US');
const result = getTerminalApiEnvironment();
expect(result).toBe('live-us');
});

it('should return default LIVE endpoint for LIVE environment', () => {
const adyenConfigs = require('*/cartridge/adyen/utils/adyenConfigs');
adyenConfigs.getAdyenEnvironment.mockReturnValue('LIVE');
adyenConfigs.getAdyenPosRegion.mockReturnValue('EU');
const result = getTerminalApiEnvironment();
expect(result).toBe('live');
});
})
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const dwsystem = require('dw/system');
const Site = require('dw/system/Site');

const adyenCurrentSite = dwsystem.Site.getCurrent();
const adyenCurrentSite = Site.getCurrent();

function getCustomPreference(field) {
let customPreference = null;
Expand Down

0 comments on commit 872f046

Please sign in to comment.