Skip to content

Commit

Permalink
adjust timeouts to ensure tests are passing
Browse files Browse the repository at this point in the history
  • Loading branch information
Timur Karimov committed Dec 12, 2023
1 parent 8fc73fa commit f3d79a6
Showing 1 changed file with 22 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,23 @@ describe( 'Enabled UPE with deferred intent creation', () => {
// Take note of the time when we added this card
timeAdded = Date.now();

// Verify that the card was added
await expect( page ).not.toMatch(
'You cannot add a new payment method so soon after the previous one. Please wait for 20 seconds.'
);
await expect( page ).toMatch( 'Payment method successfully added' );
await expect( page ).toMatch(
`${ card.expires.month }/${ card.expires.year }`
);
await waitTwentySecondsSinceLastCardAdded();
} );

it( 'should be able to set payment method as default', async () => {
await shopperWCP.goToPaymentMethods();
await shopperWCP.addNewPaymentMethod( 'basic', card );
// Take note of the time when we added this card
timeAdded = Date.now();

// Verify that the card was added
await expect( page ).not.toMatch(
'You cannot add a new payment method so soon after the previous one. Please wait for 20 seconds.'
Expand All @@ -160,6 +177,10 @@ describe( 'Enabled UPE with deferred intent creation', () => {
} );

afterAll( async () => {
await waitTwentySecondsSinceLastCardAdded();
} );

async function waitTwentySecondsSinceLastCardAdded() {
// Make sure that at least 20s had already elapsed since the last card was added.
// Otherwise, you will get the error message,
// "You cannot add a new payment method so soon after the previous one."
Expand All @@ -171,6 +192,6 @@ describe( 'Enabled UPE with deferred intent creation', () => {
: 0;

await new Promise( ( r ) => setTimeout( r, remainingWaitTime ) );
} );
}
} );
} );

0 comments on commit f3d79a6

Please sign in to comment.