|
1 | 1 | const adyenCheckout = require('../adyenCheckout'); |
2 | 2 | const Logger = require('../../../../../../../../jest/__mocks__/dw/system/Logger'); |
| 3 | +const AdyenConfigs = require('*/cartridge/adyen/utils/adyenConfigs'); |
| 4 | +const AdyenHelper = require('*/cartridge/adyen/utils/adyenHelper'); |
| 5 | +const adyenLevelTwoThreeData = require('*/cartridge/adyen/scripts/payments/adyenLevelTwoThreeData'); |
3 | 6 |
|
4 | 7 | describe('AdyenCheckout', () => { |
5 | 8 | it('should not error when cached gift card amount and actual amount match', () => { |
@@ -95,4 +98,87 @@ describe('AdyenCheckout', () => { |
95 | 98 | const testFn = () => {adyenCheckout.createPaymentRequest(args)}; |
96 | 99 | expect(testFn).toThrow("Cart has been edited after applying a gift card"); |
97 | 100 | }) |
| 101 | + |
| 102 | + describe('L2/3 Data filtering with L23_PAYMENT_METHODS', () => { |
| 103 | + let getLineItemsSpy; |
| 104 | + const l23MockData = { 'enhancedSchemeData.totalTaxAmount': 10 }; |
| 105 | + |
| 106 | + function createArgs() { |
| 107 | + return { |
| 108 | + Order: { |
| 109 | + custom: {}, |
| 110 | + setPaymentStatus: jest.fn(), |
| 111 | + setExportStatus: jest.fn(), |
| 112 | + getOrderNo: jest.fn(), |
| 113 | + getOrderToken: jest.fn(), |
| 114 | + getCustomerEmail: jest.fn(), |
| 115 | + getBillingAddress: jest.fn(), |
| 116 | + getDefaultShipment: jest.fn(), |
| 117 | + paymentInstrument: { |
| 118 | + custom: { |
| 119 | + adyenPaymentData: "{}", |
| 120 | + }, |
| 121 | + paymentTransaction: { |
| 122 | + amount: { |
| 123 | + value: 1000, |
| 124 | + currencyCode: "EUR" |
| 125 | + } |
| 126 | + } |
| 127 | + }, |
| 128 | + }, |
| 129 | + }; |
| 130 | + } |
| 131 | + |
| 132 | + beforeEach(() => { |
| 133 | + getLineItemsSpy = jest.spyOn(adyenLevelTwoThreeData, 'getLineItems') |
| 134 | + .mockReturnValue(l23MockData); |
| 135 | + AdyenConfigs.getAdyenLevel23DataEnabled.mockReturnValue(true); |
| 136 | + }); |
| 137 | + |
| 138 | + afterEach(() => { |
| 139 | + getLineItemsSpy.mockRestore(); |
| 140 | + AdyenConfigs.getAdyenLevel23DataEnabled.mockReturnValue(false); |
| 141 | + AdyenHelper.createAdyenRequestObject.mockReturnValue({ |
| 142 | + paymentMethod: { type: 'scheme' }, |
| 143 | + }); |
| 144 | + }); |
| 145 | + |
| 146 | + it('should add L2/3 data for scheme payment method', () => { |
| 147 | + AdyenHelper.createAdyenRequestObject.mockReturnValue({ |
| 148 | + paymentMethod: { type: 'scheme' }, |
| 149 | + }); |
| 150 | + adyenCheckout.createPaymentRequest(createArgs()); |
| 151 | + expect(getLineItemsSpy).toHaveBeenCalled(); |
| 152 | + }); |
| 153 | + |
| 154 | + it('should add L2/3 data for applepay payment method', () => { |
| 155 | + AdyenHelper.createAdyenRequestObject.mockReturnValue({ |
| 156 | + paymentMethod: { type: 'applepay' }, |
| 157 | + }); |
| 158 | + adyenCheckout.createPaymentRequest(createArgs()); |
| 159 | + expect(getLineItemsSpy).toHaveBeenCalled(); |
| 160 | + }); |
| 161 | + |
| 162 | + it('should add L2/3 data for googlepay payment method', () => { |
| 163 | + AdyenHelper.createAdyenRequestObject.mockReturnValue({ |
| 164 | + paymentMethod: { type: 'googlepay' }, |
| 165 | + }); |
| 166 | + adyenCheckout.createPaymentRequest(createArgs()); |
| 167 | + expect(getLineItemsSpy).toHaveBeenCalled(); |
| 168 | + }); |
| 169 | + |
| 170 | + it('should not add L2/3 data for non-L23 payment method', () => { |
| 171 | + AdyenHelper.createAdyenRequestObject.mockReturnValue({ |
| 172 | + paymentMethod: { type: 'ideal' }, |
| 173 | + }); |
| 174 | + adyenCheckout.createPaymentRequest(createArgs()); |
| 175 | + expect(getLineItemsSpy).not.toHaveBeenCalled(); |
| 176 | + }); |
| 177 | + |
| 178 | + it('should not add L2/3 data when Level23Data is disabled', () => { |
| 179 | + AdyenConfigs.getAdyenLevel23DataEnabled.mockReturnValue(false); |
| 180 | + adyenCheckout.createPaymentRequest(createArgs()); |
| 181 | + expect(getLineItemsSpy).not.toHaveBeenCalled(); |
| 182 | + }); |
| 183 | + }) |
98 | 184 | }) |
0 commit comments