-
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.
Feature/sfi 991 handle execute analytics (#1201)
* fix: lint errors * feat: make responses same for all calls * feat: tests for creating attempt id * chore: bump playwright version * chore: additional logs * chore: info log * chore: revert changes * chore: add one more line for e2e tests to pass
- Loading branch information
1 parent
3535f27
commit bbbbe33
Showing
8 changed files
with
129 additions
and
38 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
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
66 changes: 66 additions & 0 deletions
66
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 |
---|---|---|
@@ -0,0 +1,66 @@ | ||
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 }); | ||
|
||
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) | ||
}); | ||
|
||
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; | ||
}); | ||
|
||
const result = createCheckoutAttemptId(); | ||
|
||
setTimeout(() => { | ||
expect(AdyenHelper.getApplicationInfo).toHaveBeenCalled(); | ||
expect(AdyenLogs.error_log).toHaveBeenCalledWith( | ||
'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
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