Skip to content

Commit

Permalink
test payment with cash flow
Browse files Browse the repository at this point in the history
  • Loading branch information
vladimir-8 committed Aug 28, 2024
1 parent 9d415fb commit a08a43d
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 52 deletions.
115 changes: 63 additions & 52 deletions e2e/foodtech/checkout/customer__role_user__logged_in/success.spec.js
Original file line number Diff line number Diff line change
@@ -1,45 +1,60 @@
import {
addProduct, authenticateWithCredentials,
connectToDemo,
addProduct,
authenticateWithCredentials,
connectToLocalInstance,
connectToSandbox,
disablePasswordAutofill,
} from '../../../utils'
symfonyConsole,
} from '../../../utils';
import { describe } from 'jest-circus';

describe('Checkout; customer in role: user; existing account; logged in', () => {
describe('Successful Checkout; customer in role: user; existing account; logged in', () => {
beforeEach(async () => {
disablePasswordAutofill();

await device.reloadReactNative();
await connectToDemo();
await authenticateWithCredentials('user_15', 'user_15');

//FIXME: run against local instance on iOS too (requires a local coopcycle-web instance setup)
if (device.getPlatform() === 'android') {
symfonyConsole(
'coopcycle:fixtures:load -f cypress/fixtures/checkout.yml',
);
await connectToLocalInstance();
} else {
await connectToSandbox();
}

await authenticateWithCredentials('bob', '12345678');
});

it(`should complete checkout (NOT COMPLETE FLOW!!! see FIXME)`, async () => {
it(`should complete checkout`, async () => {
await expect(element(by.id('checkoutAskAddress'))).toBeVisible();

// Enter address
await waitFor(element(by.id('askAddressAutocomplete')))
.toExist()
.withTimeout(5000);
await element(by.id('askAddressAutocomplete')).typeText(
'23 av claude vellefaux',
'91 rue de rivoli paris',
);
await element(by.id('placeId:ChIJPSRadeBt5kcR4B2HzbBfZQE')).tap();
await element(by.id('placeId:ChIJQ4sJbyFu5kcRbp6Sp6NLnog')).tap();

// List of restaurants
await expect(element(by.id('checkoutSearch'))).toBeVisible();
await expect(element(by.id('restaurantList'))).toBeVisible();

// Choose a restaurant
try {
await expect(element(by.label('La cabane du sud'))).toBeVisible();
await expect(
element(by.label('Restaurant with cash on delivery')),
).toBeVisible();
} catch (e) {
await waitFor(element(by.label('La cabane du sud')))
await waitFor(element(by.label('Restaurant with cash on delivery')))
.toBeVisible()
.whileElement(by.id('restaurantList'))
.scroll(120, 'down');
}
await element(by.label('La cabane du sud')).tap();
await element(by.label('Restaurant with cash on delivery')).tap();

// Restaurant page
await waitFor(element(by.id('restaurantData')))
Expand All @@ -48,21 +63,10 @@ describe('Checkout; customer in role: user; existing account; logged in', () =>
await waitFor(element(by.id('menuItem:0:0')))
.toExist()
.withTimeout(5000);
await waitFor(element(by.id('menuItem:0:1')))
.toExist()
.withTimeout(5000);
await waitFor(element(by.id('menuItem:0:2')))
.toExist()
.withTimeout(5000);

// Add item
await addProduct('menuItem:0:0');

// Reusable packaging modal
await expect(element(by.id('reusablePackagingOk'))).toBeVisible();
// Dismiss reusable packaging modal
await element(by.id('reusablePackagingOk')).tap();

// Check if footer is present
await waitFor(element(by.id('cartFooter')))
.toExist()
Expand All @@ -71,7 +75,7 @@ describe('Checkout; customer in role: user; existing account; logged in', () =>

// Add 2 more items
await addProduct('menuItem:0:1');
await addProduct('menuItem:0:2');
await addProduct('menuItem:1:0');

await waitFor(element(by.id('cartSubmit')))
.toBeVisible()
Expand All @@ -81,9 +85,6 @@ describe('Checkout; customer in role: user; existing account; logged in', () =>
// Cart summary page
await expect(element(by.id('cartSummarySubmit'))).toBeVisible();

// Disable reusable packaging (requires a separate account)
await element(by.id('reusablePackagingCheckbox')).tap();

await element(by.id('cartSummarySubmit')).tap();

// More infos page
Expand All @@ -95,7 +96,9 @@ describe('Checkout; customer in role: user; existing account; logged in', () =>
await element(by.id('checkoutTelephone')).typeText('0612345678');
await element(by.id('checkoutTelephone')).typeText('\n');

// FIXME; test complete checkout flow
await element(by.id('moreInfosSubmit')).tap();

// FIXME; test payment via Stripe as well
// Android: there are at least 2 issues with Stripe in the tests:
// 1. sometimes the app fails with java.lang.IllegalStateException: PaymentConfiguration was not initialized. Call PaymentConfiguration.init().
// might be related to: https://github.com/coopcycle/coopcycle-app/issues/1841
Expand All @@ -108,29 +111,37 @@ describe('Checkout; customer in role: user; existing account; logged in', () =>
// ---
// Error: Error Domain=DetoxErrorDomain Code=0 "View “<StripePaymentsUI.STPFormTextField: 0x7fe7a6649800>” is not visible: View does not pass visibility percent threshold (100)"

if (device.getPlatform() !== 'android' && device.getPlatform() !== 'ios') {
await element(by.id('moreInfosSubmit')).tap();

// Payment page
await element(by.id('cardholderName')).typeText('John Doe');

// Tap the credit card input to make sure we can interact with it
await element(by.id('creditCardWrapper')).tap();

await element(by.label('card number')).typeText('4242424242424242');

await element(by.label('expiration date')).typeText('1228');
// Add "\n" to make sure keyboard is hidden
await element(by.label('CVC').and(by.type('UITextField'))).typeText(
'123\n',
);

await element(by.id('creditCardSubmit')).tap();

// Confirmation page
await waitFor(element(by.id('orderTimeline')))
.toBeVisible()
.withTimeout(15000);
}
// if (device.getPlatform() !== 'android' && device.getPlatform() !== 'ios') {
// // Payment page
// await element(by.id('cardholderName')).typeText('John Doe');
//
// // Tap the credit card input to make sure we can interact with it
// await element(by.id('creditCardWrapper')).tap();
//
// await element(by.label('card number')).typeText('4242424242424242');
//
// await element(by.label('expiration date')).typeText('1228');
// // Add "\n" to make sure keyboard is hidden
// await element(by.label('CVC').and(by.type('UITextField'))).typeText(
// '123\n',
// );
//
// await element(by.id('creditCardSubmit')).tap();
// }

// Payment picker page
await expect(
element(by.id('paymentMethod-cash_on_delivery')),
).toBeVisible();
await element(by.id('paymentMethod-cash_on_delivery')).tap();

// Cash on delivery page
await expect(element(by.id('cashOnDeliverySubmit'))).toBeVisible();
await element(by.id('cashOnDeliverySubmit')).tap();

// Confirmation page
await waitFor(element(by.id('orderTimeline')))
.toBeVisible()
.withTimeout(15000);
});
});
18 changes: 18 additions & 0 deletions e2e/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,24 @@ export const connectToDemo = async () => {
} catch (e) {}
};

export const connectToSandbox = async () => {
await expect(element(by.id('chooseCityBtn'))).toBeVisible();
await element(by.id('chooseCityBtn')).tap();

await expect(element(by.id('moreServerOptions'))).toBeVisible();
await element(by.id('moreServerOptions')).tap();

await element(by.id('customServerURL')).typeText(
'sandbox-fr.coopcycle.org\n',
);

try {
// We deliberately add "\n" to hide the keyboard
// The tap below shouldn't be necessary
await element(by.id('submitCustomServer')).tap();
} catch (e) {}
};

const getLocalIpAddress = () => {
const interfaces = os.networkInterfaces();
for (const name of Object.keys(interfaces)) {
Expand Down

0 comments on commit a08a43d

Please sign in to comment.