-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Consistently populating Adyen_paymentMethod (#1088)
- Loading branch information
Showing
10 changed files
with
87 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const Encoding = jest.fn(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const MessageDigest = jest.fn(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const createService = jest.fn(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const Bytes = jest.fn(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const getCurrency = jest.fn(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const createUUID = jest.fn(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
src/cartridges/int_adyen_SFRA/cartridge/adyen/utils/__tests__/adyenHelper.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* eslint-disable global-require */ | ||
const savePaymentDetails = require('../adyenHelper').savePaymentDetails; | ||
describe('savePaymentDetails', () => { | ||
let paymentInstrument; | ||
let order; | ||
let result; | ||
|
||
beforeEach(() => { | ||
paymentInstrument = { | ||
paymentTransaction: { | ||
custom: {} | ||
}, | ||
getCreditCardToken: jest.fn(), | ||
setCreditCardToken: jest.fn() | ||
}; | ||
order = { | ||
custom: {} | ||
}; | ||
result = {}; | ||
}); | ||
|
||
it('should set the transactionID and Adyen_pspReference', () => { | ||
result.pspReference = 'testReference'; | ||
savePaymentDetails(paymentInstrument, order, result); | ||
expect(paymentInstrument.paymentTransaction.transactionID).toBe('testReference'); | ||
expect(paymentInstrument.paymentTransaction.custom.Adyen_pspReference).toBe('testReference'); | ||
}); | ||
|
||
it('should set Adyen_paymentMethod from additionalData', () => { | ||
result.additionalData = { paymentMethod: 'visa' }; | ||
savePaymentDetails(paymentInstrument, order, result); | ||
expect(paymentInstrument.paymentTransaction.custom.Adyen_paymentMethod).toBe('visa'); | ||
expect(order.custom.Adyen_paymentMethod).toBe('visa'); | ||
}); | ||
|
||
it('should set Adyen_paymentMethod from paymentMethod', () => { | ||
result.paymentMethod = { type: 'mc' }; | ||
savePaymentDetails(paymentInstrument, order, result); | ||
expect(paymentInstrument.paymentTransaction.custom.Adyen_paymentMethod).toBe(JSON.stringify('mc')); | ||
expect(order.custom.Adyen_paymentMethod).toBe(JSON.stringify('mc')); | ||
}); | ||
|
||
it('should set the credit card token if not already exists', () => { | ||
result.additionalData = { 'recurring.recurringDetailReference': 'token123' }; | ||
paymentInstrument.getCreditCardToken.mockReturnValue(null); | ||
savePaymentDetails(paymentInstrument, order, result); | ||
expect(paymentInstrument.setCreditCardToken).toHaveBeenCalledWith('token123'); | ||
}); | ||
|
||
it('should not set the credit card token if already exists', () => { | ||
result.additionalData = { 'recurring.recurringDetailReference': 'token123' }; | ||
paymentInstrument.getCreditCardToken.mockReturnValue('existingToken'); | ||
savePaymentDetails(paymentInstrument, order, result); | ||
expect(paymentInstrument.setCreditCardToken).not.toHaveBeenCalled(); | ||
}); | ||
|
||
it('should set the authCode and Adyen_value', () => { | ||
result.resultCode = 'Authorised'; | ||
savePaymentDetails(paymentInstrument, order, result); | ||
expect(paymentInstrument.paymentTransaction.custom.authCode).toBe('Authorised'); | ||
expect(order.custom.Adyen_value).toBe('0'); | ||
}); | ||
|
||
it('should set Adyen_donationToken if present', () => { | ||
result.donationToken = 'donation-token-123'; | ||
savePaymentDetails(paymentInstrument, order, result); | ||
expect(paymentInstrument.paymentTransaction.custom.Adyen_donationToken).toBe('donation-token-123'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters