-
Notifications
You must be signed in to change notification settings - Fork 135
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(UIElement): added tests for sending error event to the analytics
- Loading branch information
1 parent
24daf37
commit f83dd0f
Showing
7 changed files
with
160 additions
and
8 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,50 @@ | ||
import { render } from '@testing-library/preact'; | ||
import { mockDeep } from 'jest-mock-extended'; | ||
import { AnalyticsModule } from '../../types/global-types'; | ||
import AdyenCheckoutError from '../../core/Errors/AdyenCheckoutError'; | ||
import { ANALYTICS_ERROR_TYPE, ANALYTICS_EVENT } from '../../core/Analytics/constants'; | ||
import ANCV from './ANCV'; | ||
|
||
const flushPromises = () => new Promise(process.nextTick); | ||
|
||
describe('ANCV', () => { | ||
const resources = global.resources; | ||
const i18n = global.i18n; | ||
|
||
const baseProps = { | ||
amount: { value: 1000, currency: 'EUR' }, | ||
i18n, | ||
loadingContext: 'mock' | ||
}; | ||
|
||
describe('createOrder', () => { | ||
test('should send an error event to the analytics if the createOrder call fails for the session flow', async () => { | ||
const code = 'mockErrorCode'; | ||
const analytics = mockDeep<AnalyticsModule>(); | ||
const mockedSendAnalytics = analytics.sendAnalytics as jest.Mock; | ||
|
||
const ancv = new ANCV(global.core, { | ||
...baseProps, | ||
modules: { | ||
resources, | ||
analytics | ||
}, | ||
onError: () => {}, | ||
// @ts-ignore test only | ||
session: { | ||
createOrder: () => { | ||
return Promise.reject(new AdyenCheckoutError('NETWORK_ERROR', '', { code })); | ||
} | ||
} | ||
}); | ||
render(ancv.render()); | ||
await ancv.createOrder(); | ||
await flushPromises(); | ||
expect(mockedSendAnalytics).toHaveBeenCalledWith( | ||
'ancv', | ||
{ code, errorType: ANALYTICS_ERROR_TYPE.apiError, type: ANALYTICS_EVENT.error }, | ||
undefined | ||
); | ||
}); | ||
}); | ||
}); |
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
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