-
Notifications
You must be signed in to change notification settings - Fork 141
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implementing handling an optional expiry date as determined by binLoo…
…kup (#1328) * Implementing handling an optional expiry date as determined by binLookup * Add 'korean_local_card' brand to playground KCP example * Updating securedFields playground file to work with v5 * Refactor how we detect single date field and clear error (if optional or hidden) * Fixed tests in customcard.unsupportedCard.test.js * Removed unused imports from test * Fix so that ClientFunction runs for test (removed ref to DOM element) * Fixed bug where card could not become valid if dateField eas optional but had an error due to an isValidate call * Also clear isValidated errors for optional/hidden separate date fields (custom card scenario) * Add classes for ExpirationDate component in same format as for CVC * Create e2e Page Model for testing Card Component * Added first e2e tests (using Page Model) for optional expiryDate * Another test added * Improved CardPage.getFromWindow fn * Improved routine to remove DOM elements from state.errors * Added assertion timeouts to 3DS2 tests to allow flexibility in how long it takes for challenge window to load * Slowed down 3rd expiryDate test more so that it works better when part of a batch of tests (testcafe bug) * Mock response fny made generic (part of BasePage) for more easy reuse * Added tests for expiryDatePolicy = 'hidden' * Create type for window.mockBinCount so that e2e tests have a way to know/turn off SDK bin mocking (in case it's accidentally been left on) * Added functionality for e2e tests to know/turn off SDK bin mocking (in case it's accidentally been left on) * Added line to 'hidden' test * Moved checkMocking.test so that it is always the first run * Adding clientScripts to fixture last seems to allow onChange event to always fire (was sometimes failing when entire test suite was run) * Adding code to custom card playground & e2e files to handle 'optional' date & cvc policies * Removed id's from playground & e2e custom card examples. Allowed separate date field example to support dual branding * Added CustomCard Page model & tests for optional expiryDate on the "regular" custom card * Aligning class names for the "separate" custom card * Added new utils for Card pages * Added tests for optional expiryDate on the "separate" custom card * Added utils for retrieving iframe input & aria error fields * Convert customcard.unsupportedCard.test.js to use Custom card Page model (& stripped repeated test code) * onChange function for Cards that maps state.errors to remove DOM nodes - moved to Cards.js (it's just not always picked up from the expiryDate.clientScript.js for some reason) * Comments added * Added assertion in e2e test for undefined object * removing unused code * Replaced zeroPad fn with String.padStart * Mock related functionality moved out from BasePage to a mocks util for the Card related pages & tests
- Loading branch information
Showing
55 changed files
with
1,823 additions
and
403 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { ClientFunction, RequestMock } from 'testcafe'; | ||
import { BASE_URL } from '../pages'; | ||
|
||
import path from 'path'; | ||
require('dotenv').config({ path: path.resolve('../../', '.env') }); | ||
|
||
export const binLookupUrl = `https://checkoutshopper-test.adyen.com/checkoutshopper/v2/bin/binLookup?token=${process.env.CLIENT_KEY}`; | ||
|
||
/** | ||
* Functionality for mocking a /binLookup API response via testcafe's fixture.requestHooks() | ||
* | ||
* @param requestURL | ||
* @param mockedResponse | ||
* @returns {RequestMock} | ||
*/ | ||
export const getBinLookupMock = (requestURL, mockedResponse) => { | ||
return RequestMock() | ||
.onRequestTo(request => { | ||
return request.url === requestURL && request.method === 'post'; | ||
}) | ||
.respond( | ||
(req, res) => { | ||
const body = JSON.parse(req.body); | ||
mockedResponse.requestId = body.requestId; | ||
res.setBody(mockedResponse); | ||
}, | ||
200, | ||
{ | ||
'Access-Control-Allow-Origin': BASE_URL | ||
} | ||
); | ||
}; | ||
|
||
// For the tests as a whole - throw an error if SDK binLookup mocking is turned on | ||
export const checkSDKMocking = ClientFunction(() => { | ||
if (window.mockBinCount > 0) { | ||
throw new Error('SDK bin mocking is turned on - this will affect/break the tests - so turn it off in triggerBinLookup.ts'); | ||
} | ||
}); | ||
|
||
// For individual test suites (perhaps being run in isolation) - provide a way to ensure SDK bin mocking is turned off | ||
export const turnOffSDKMocking = ClientFunction(() => { | ||
window.mockBinCount = 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { checkSDKMocking } from './cardMocks'; | ||
import CardComponentPage from '../_models/CardComponent.page'; | ||
|
||
const cardPage = new CardComponentPage(); | ||
|
||
fixture`Test that bin mocking isn't turned on in the SDK`.page(cardPage.pageUrl); | ||
|
||
/** | ||
* Check that bin mocking isn't turned on in the SDK | ||
* - this is used for testing (in triggerBinLookup.ts) but if left on will break or skew the tests | ||
*/ | ||
test('Check for SDK Bin mocking', async () => { | ||
await checkSDKMocking(); | ||
}); |
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,25 @@ | ||
import { BASE_URL } from '../pages'; | ||
import { ClientFunction } from 'testcafe'; | ||
|
||
export default class BasePage { | ||
constructor(url) { | ||
this.pageUrl = `${BASE_URL}/${url}`; | ||
} | ||
|
||
/** | ||
* Client function that accesses properties on the window object | ||
*/ | ||
getFromWindow = ClientFunction(path => { | ||
const splitPath = path.split('.'); | ||
const reducer = (xs, x) => (xs && xs[x] !== undefined ? xs[x] : undefined); | ||
|
||
return splitPath.reduce(reducer, window); | ||
}); | ||
|
||
/** | ||
* Hack to force testcafe to fire expected blur events as (securedFields) switch focus | ||
*/ | ||
setForceClick = ClientFunction(val => { | ||
window.testCafeForceClick = val; | ||
}); | ||
} |
Oops, something went wrong.