Skip to content

Commit 3cc3f2f

Browse files
fixed tests
1 parent 6c24df6 commit 3cc3f2f

File tree

1 file changed

+36
-14
lines changed

1 file changed

+36
-14
lines changed

packages/lib/src/components/GooglePay/GooglePay.test.ts

+36-14
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ describe('GooglePay', () => {
5858
describe('onClick()', () => {
5959
test('should not call "initiatePayment" if the onClick reject() is called', async () => {
6060
const googlepay = new GooglePay(global.core, {
61+
configuration: { merchantId: 'merchant-id', gatewayMerchantId: 'gateway-id' },
6162
onClick(resolve, reject) {
6263
reject();
6364
}
@@ -73,6 +74,7 @@ describe('GooglePay', () => {
7374

7475
test('should call "initiatePayment" if the onClick resolve() is called', async () => {
7576
const googlepay = new GooglePay(global.core, {
77+
configuration: { merchantId: 'merchant-id', gatewayMerchantId: 'gateway-id' },
7678
onClick(resolve) {
7779
resolve();
7880
}
@@ -89,16 +91,27 @@ describe('GooglePay', () => {
8991

9092
describe('isExpress flag', () => {
9193
test('should add subtype: express when isExpress is configured', () => {
92-
const googlepay = new GooglePay(global.core, { isExpress: true });
94+
const googlepay = new GooglePay(global.core, {
95+
configuration: { merchantId: 'merchant-id', gatewayMerchantId: 'gateway-id' },
96+
isExpress: true
97+
});
9398
expect(googlepay.data.paymentMethod).toHaveProperty('subtype', 'express');
9499
});
95100
test('should not add subtype: express when isExpress is omitted', () => {
96-
const googlepay = new GooglePay(global.core);
101+
const googlepay = new GooglePay(global.core, {
102+
configuration: { merchantId: 'merchant-id', gatewayMerchantId: 'gateway-id' }
103+
});
97104
expect(googlepay.data.paymentMethod).not.toHaveProperty('subtype', 'express');
98105
});
99106

100107
test('should throw error when express callbacks are passed but isExpress flag is not set', () => {
101-
expect(() => new GooglePay(global.core, { paymentDataCallbacks: { onPaymentDataChanged: jest.fn() } })).toThrow();
108+
expect(
109+
() =>
110+
new GooglePay(global.core, {
111+
configuration: { merchantId: 'merchant-id', gatewayMerchantId: 'gateway-id' },
112+
paymentDataCallbacks: { onPaymentDataChanged: jest.fn() }
113+
})
114+
).toThrow();
102115
});
103116
});
104117

@@ -112,6 +125,7 @@ describe('GooglePay', () => {
112125
const onPaymentCompletedMock = jest.fn();
113126

114127
const gpay = new GooglePay(global.core, {
128+
configuration: { merchantId: 'merchant-id', gatewayMerchantId: 'gateway-id' },
115129
onSubmit: onSubmitMock,
116130
onPaymentCompleted: onPaymentCompletedMock
117131
});
@@ -176,6 +190,7 @@ describe('GooglePay', () => {
176190
});
177191

178192
new GooglePay(global.core, {
193+
configuration: { merchantId: 'merchant-id', gatewayMerchantId: 'gateway-id' },
179194
onSubmit: onSubmitMock
180195
});
181196

@@ -214,6 +229,7 @@ describe('GooglePay', () => {
214229
const onPaymentFailedMock = jest.fn();
215230

216231
const gpay = new GooglePay(global.core, {
232+
configuration: { merchantId: 'merchant-id', gatewayMerchantId: 'gateway-id' },
217233
i18n: global.i18n,
218234
onSubmit: onSubmitMock,
219235
onPaymentFailed: onPaymentFailedMock
@@ -256,6 +272,7 @@ describe('GooglePay', () => {
256272
const onPaymentFailedMock = jest.fn();
257273

258274
const gpay = new GooglePay(global.core, {
275+
configuration: { merchantId: 'merchant-id', gatewayMerchantId: 'gateway-id' },
259276
i18n: global.i18n,
260277
onSubmit: onSubmitMock,
261278
onPaymentFailed: onPaymentFailedMock
@@ -338,7 +355,10 @@ describe('GooglePay', () => {
338355

339356
test('should provide GooglePay auth event and formatted data', () => {
340357
const onAuthorizedMock = jest.fn();
341-
new GooglePay(global.core, { onAuthorized: onAuthorizedMock });
358+
new GooglePay(global.core, {
359+
configuration: { merchantId: 'merchant-id', gatewayMerchantId: 'gateway-id' },
360+
onAuthorized: onAuthorizedMock
361+
});
342362

343363
// @ts-ignore GooglePayService is mocked
344364
const onPaymentAuthorized = GooglePayService.mock.calls[0][1].onPaymentAuthorized;
@@ -354,6 +374,7 @@ describe('GooglePay', () => {
354374
const onPaymentFailedMock = jest.fn();
355375

356376
new GooglePay(global.core, {
377+
configuration: { merchantId: 'merchant-id', gatewayMerchantId: 'gateway-id' },
357378
i18n: global.i18n,
358379
onAuthorized: onAuthorizedMock,
359380
onPaymentFailed: onPaymentFailedMock
@@ -383,6 +404,7 @@ describe('GooglePay', () => {
383404
const onPaymentCompletedMock = jest.fn();
384405

385406
const gpay = new GooglePay(global.core, {
407+
configuration: { merchantId: 'merchant-id', gatewayMerchantId: 'gateway-id' },
386408
i18n: global.i18n,
387409
onAuthorized: onAuthorizedMock,
388410
onPaymentCompleted: onPaymentCompletedMock
@@ -399,7 +421,10 @@ describe('GooglePay', () => {
399421
});
400422

401423
test('should make the payments call if onAuthorized is not provided', async () => {
402-
const gpay = new GooglePay(global.core, { i18n: global.i18n });
424+
const gpay = new GooglePay(global.core, {
425+
configuration: { merchantId: 'merchant-id', gatewayMerchantId: 'gateway-id' },
426+
i18n: global.i18n
427+
});
403428

404429
const paymentCall = jest.spyOn(gpay as any, 'makePaymentsCall');
405430

@@ -414,7 +439,7 @@ describe('GooglePay', () => {
414439

415440
describe('isAvailable()', () => {
416441
test('should resolve if GooglePay is available', async () => {
417-
const gpay = new GooglePay(global.core);
442+
const gpay = new GooglePay(global.core, { configuration: { merchantId: 'merchant-id', gatewayMerchantId: 'gateway-id' } });
418443
gpay.isReadyToPay = jest.fn(() => {
419444
return Promise.resolve({ result: true });
420445
});
@@ -423,7 +448,7 @@ describe('GooglePay', () => {
423448
});
424449

425450
test('should reject if is not available', async () => {
426-
const gpay = new GooglePay(global.core);
451+
const gpay = new GooglePay(global.core, { configuration: { merchantId: 'merchant-id', gatewayMerchantId: 'gateway-id' } });
427452
gpay.isReadyToPay = jest.fn(() => {
428453
return Promise.resolve({ result: false });
429454
});
@@ -432,7 +457,7 @@ describe('GooglePay', () => {
432457
});
433458

434459
test('should reject if "paymentMethodPresent" is false', async () => {
435-
const gpay = new GooglePay(global.core);
460+
const gpay = new GooglePay(global.core, { configuration: { merchantId: 'merchant-id', gatewayMerchantId: 'gateway-id' } });
436461
gpay.isReadyToPay = jest.fn(() => {
437462
return Promise.resolve({ result: true, paymentMethodPresent: false });
438463
});
@@ -442,19 +467,15 @@ describe('GooglePay', () => {
442467
});
443468

444469
describe('Process CA based configuration data', () => {
445-
test('Retrieves default merchantId', () => {
446-
const gpay = new GooglePay(global.core);
447-
expect(gpay.props.configuration.merchantId).toEqual('');
448-
});
449-
450470
test('Retrieves merchantId from configuration', () => {
451471
const gpay = new GooglePay(global.core, { configuration: { merchantId: 'abcdef', gatewayMerchantId: 'TestMerchant' } });
452472
expect(gpay.props.configuration.merchantId).toEqual('abcdef');
453473
});
454474

455-
test('Retrieves merchantId from configuration', () => {
475+
test('Retrieves merchantOrigin from configuration', () => {
456476
const gpay = new GooglePay(global.core, {
457477
configuration: {
478+
merchantId: 'abcdef',
458479
gatewayMerchantId: 'TestMerchant',
459480
merchantOrigin: 'example.com'
460481
}
@@ -476,6 +497,7 @@ describe('GooglePay', () => {
476497
console.log = jest.fn(() => {});
477498

478499
gpay = new GooglePay(global.core, {
500+
configuration: { merchantId: 'merchant-id', gatewayMerchantId: 'gateway-id' },
479501
type: 'googlepay',
480502
isInstantPayment: true,
481503
modules: {

0 commit comments

Comments
 (0)