-
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.
- Loading branch information
1 parent
d5f6baf
commit 14d8cf1
Showing
7 changed files
with
81 additions
and
87 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
81 changes: 35 additions & 46 deletions
81
src/cartridges/int_adyen_SFRA/cartridge/adyen/analytics/__tests__/analyticsService.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 |
---|---|---|
@@ -1,66 +1,55 @@ | ||
const AdyenHelper = require('*/cartridge/adyen/utils/adyenHelper'); | ||
const AdyenLogs = require('*/cartridge/adyen/logs/adyenCustomLogs'); | ||
const { createCheckoutAttemptId } = require('../analyticsService'); | ||
|
||
const AdyenHelper = { | ||
getApplicationInfo: jest.fn(), | ||
}; | ||
|
||
const execute = jest.fn(); | ||
const constants = { | ||
SERVICE: { | ||
ADYEN_ANALYTICS: 'ADYEN_ANALYTICS', | ||
}, | ||
}; | ||
|
||
const AdyenLogs = { | ||
error_log: jest.fn(), | ||
}; | ||
|
||
global.AdyenHelper = AdyenHelper; | ||
global.execute = execute; | ||
global.constants = constants; | ||
global.AdyenLogs = AdyenLogs; | ||
|
||
describe('createCheckoutAttemptId', () => { | ||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('should return checkoutAttemptId when the execute function is successful', () => { | ||
const mockCheckoutAttemptId = 'test-checkout-attempt-id'; | ||
const mockApplicationInfo = { name: 'testApp' }; | ||
|
||
AdyenHelper.getApplicationInfo.mockReturnValue(mockApplicationInfo); | ||
execute.mockReturnValue({ checkoutAttemptId: mockCheckoutAttemptId }); | ||
AdyenHelper.getService.mockImplementationOnce(() => ({ | ||
getURL: jest.fn(() => 'mocked_service_url'), | ||
setURL: jest.fn(), | ||
addHeader: jest.fn(), | ||
call: jest.fn(() => ({ | ||
status: '200', | ||
isOk: jest.fn(() => true), | ||
object: { | ||
getText: jest.fn(() => | ||
`{"checkoutAttemptId":"${mockCheckoutAttemptId}"}`), | ||
|
||
}, | ||
})) | ||
})); | ||
|
||
const result = createCheckoutAttemptId(); | ||
|
||
setTimeout(() => { | ||
expect(AdyenHelper.getApplicationInfo).toHaveBeenCalled(); | ||
expect(execute).toHaveBeenCalledWith(constants.SERVICE.ADYEN_ANALYTICS, { | ||
applicationInfo: mockApplicationInfo, | ||
channel: 'Web', | ||
platform: 'Web', | ||
}); | ||
expect(result).toEqual({ data: mockCheckoutAttemptId }); | ||
}, 0) | ||
expect(result).toEqual({ data: mockCheckoutAttemptId }); | ||
}); | ||
|
||
it('should return an error object and log error when execute throws an error', () => { | ||
const mockError = new Error('Execution failed'); | ||
AdyenHelper.getApplicationInfo.mockReturnValue({}); | ||
execute.mockImplementation(() => { | ||
throw mockError; | ||
}); | ||
|
||
AdyenHelper.getService.mockImplementationOnce(() => ({ | ||
getURL: jest.fn(() => 'mocked_service_url'), | ||
setURL: jest.fn(), | ||
addHeader: jest.fn(), | ||
call: jest.fn(() => ({ | ||
status: 'failed', | ||
isOk: jest.fn(() => false), | ||
getError: jest.fn(() => ({ | ||
toString: jest.fn(() => '500') | ||
})), | ||
getStatus: jest.fn(() => 'failed'), | ||
getErrorMessage: jest.fn(() => 'Service error'), | ||
getMsg: jest.fn(() => 'Service error'), | ||
})) | ||
})); | ||
const mockError = new Error('AdyenAnalytics service call error code 500 Error => ResponseStatus: failed | ResponseErrorText: Service error | ResponseText: Service error'); | ||
const result = createCheckoutAttemptId(); | ||
|
||
setTimeout(() => { | ||
expect(AdyenHelper.getApplicationInfo).toHaveBeenCalled(); | ||
expect(AdyenLogs.error_log).toHaveBeenCalledWith( | ||
'createCheckoutAttemptId for /analytics call failed:', | ||
mockError | ||
'createCheckoutAttemptId for /analytics call failed:', mockError | ||
); | ||
expect(result).toEqual({ error: true }); | ||
}, 0) | ||
}); | ||
}); | ||
}); |
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
15 changes: 9 additions & 6 deletions
15
src/cartridges/int_adyen_SFRA/cartridge/adyen/logs/adyenError.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
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
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