woocommerce/plugins/woocommerce-blocks/docs/internal-developers/testing/cart-checkout/data-stores.md

189 lines
9.6 KiB
Markdown
Raw Normal View History

2022-08-25 10:44:31 +00:00
# Testing
## Payments
In general, perform smoke tests, ensure you can check out with carts containing:
- Only physical products,
- Only virtual products,
- A mix of physical and virtual products,
- Products on sale,
- Products with different tax rates.
- Check out using coupons, and the amount charged to the payment method is correct.
2022-08-25 10:44:31 +00:00
Ensure the amount charged is correct.
### Subscriptions
- Check out using WooCommerce Subscriptions products, ensure the checkout works and the stripe key is saved to the order.
- Go to the Subscription in the dashboard, process a renewal for it, ensure the payment goes through and is collected in your stripe account. (This check is to ensure the tokens are saved correctly)
2022-08-25 10:44:31 +00:00
### Stripe failures
Check out using the following cards to ensure following scenarios happen: (use any CVV and expiration date in the future)
- `4242 4242 4242 4242` - Checkout succeeds
- `4000 0025 0000 3155` - SCA prompt appears, if you choose to fail, then checkout fails, if you choose to succeed then the checkout succeeds
- `4000 0082 6000 3178` - Choose to succeed, but the payment should still fail because of insufficient funds
- `4000 0000 0000 9979`- Checkout fails with generic card error. (This card is marked stolen).
2022-08-25 10:44:31 +00:00
### Express Payment methods
Basic card has been deprecated, so we can either: use Google/Apple Pay, or [an older version of Chromium](https://commondatastorage.googleapis.com/chromium-browser-snapshots/index.html?prefix=Mac/625897/) you use any version up to 96 but this the only version I had to hand when writing these instructions.
If using the old version of Chromium, ensure your site is using HTTPS, and set up a payment method in Chromium: `Settings -> Payment Methods -> Add` use the Stripe test cards from the section above. We will need to test each scenario mentioned above, but in Express Payments.
If using GPay, then ensure your account is linked in Chrome. You may need to disable 1Password, but I'm not sure if it's necessary.
### Event emitters
Prerequisite: Install [`woocommerce-gateway-stripe`](https://github.com/woocommerce/woocommerce-gateway-stripe) from GitHub, we will need to edit code here. Set it up and get it running in dev mode.
Go to: [https://github.com/woocommerce/woocommerce-gateway-stripe/blob/8ffd22aff3b06eda02a1ae2fd8368b71450b36a9/client/blocks/credit-card/use-payment-processing.js#L66](https://github.com/woocommerce/woocommerce-gateway-stripe/blob/8ffd22aff3b06eda02a1ae2fd8368b71450b36a9/client/blocks/credit-card/use-payment-processing.js#L66)
- Add a `console.log` to the `onSubmit` at the very top of the function.
- In your browser, open dev tools and view the console. Ensure `preserve log` is enabled!
- Check out (both successfully and unsuccessfully) and ensure the console log you added to `onSubmit` is called **both** times.
2022-08-25 10:44:31 +00:00
### Interaction with unusable payment methods
[Docs] Update links from WooCommerce.com to Woo.com for the Woo Blocks documentation (#43055) * Update woocommerce.com URLs in documentation and code files * Add changelog * Fix github repository link in extend-rest-api-add-custom-fields.md Co-authored-by: Albert Juhé Lluveras <contact@albertjuhe.com> * Add github reporter (#42974) * Add github reporter * Add changelog --------- Co-authored-by: Jon Lane <jon.lane@automattic.com> * Fix product task redirect to support grouped and external products (#43051) * Rearrange product redirection logic to better accept grouped and external produc types * Add changelog * Modify feedback modal actions (#43005) * Adapt feedback modal actions * Add changelogs * Modify comments * Fix tests * Fix test * Update class-wc-gateway-bacs.php (#43054) * Update class-wc-gateway-bacs.php Fix typo in textdomain * Add changefile(s) from automation for the following project(s): woocommerce --------- Co-authored-by: github-actions <github-actions@github.com> * [Product Block Editor]: Add `Linked product` tab (#43009) * add linked-products to group IDs * add Linked Products tab * tweak hideConditions condition * changelog * fix typo in doc comment * Introduce a product type selection within the new experience (#41823) * Create a relation between the product type and the product block template * Add 'patterns' to name the kind of products that can be created for a specific template * Resolve template using its id as a template query param * Rename ProductEditPattern to ProductTemplate * Rename get_patterns hook to woocommerce_product_editor_get_product_templates * Return the list of templates to the client * Set layout template events as array * Register the layout template based on the product template or the post type in case of product variations * Registering non supported product types * Create and register the woocommerce/product-details-section-description block * Add the product type to the section description * Create product type selector * Fix menu item style * Highlight selected menu item * Set the selected product template * Set product template title to lowercase in the content description * Rename blocks by blockTemplates under the AbstractBlockTemplate class * Rename to woocommerce_product_editor_product_templates filter * Remove product_template_ prefix from the supported_product_types map * Rename get_formatted to to_JSON and convert the props to client side like * Refactor get_product_templates * Fix icon resolution * Add a confirmation modal for unsupported product templates * Add changelog files * Remove product types using for testing * Fix redirection when changing to a non supported product template * Set the change button state to busy when it is saving the product * Fix php linter errors * Fix rebase conflict * Move ProductTemplate to Automattic\WooCommerce\Admin\Features\ProductBlockEditor namespace * Add the to_json definition to the BlockTemplateInterface * Create default product template by custom product type if it does not have a template associated yet * Fix some comments and product template creation validation * Add support to load the product template icon from an external resource * Fix php linter * Fix the changelog description * [Experimental] Interactivity Dropdown multi-select mode, ratings filter and introduce each directive (#42981) --------- Co-authored-by: David Arenas <david.arenas@automattic.com> * Introduce the transient files engine (#42877) Co-authored-by: Corey McKrill <916023+coreymckrill@users.noreply.github.com> * Change marketplace install API request to POST instead of GET (#43033) * Change marketplace install API to using POST instead of GET * Fix linting error * Add changefile(s) from automation for the following project(s): woocommerce --------- Co-authored-by: github-actions <github-actions@github.com> * Prep trunk for 8.6 cycle (#43021) Prep trunk for 8.6 cycle with version bump to 8.6.0-dev Co-authored-by: WooCommerce Bot <no-reply@woo.com> * Add Playwright tests for All Reviews, Reviews by Product and Reviews by Category blocks (#42903) * Remove Reviews blocks Puppeteer tests * Minor code cleanup * Typos * Create publishAndVisitPost() editor util * Fix subcategories when importing products in Playwright and add reviews * Add Reviews blocks tests in Playwright * More typos * Add changefile(s) from automation for the following project(s): woocommerce-blocks * Create a 'reviews' object in data.ts so we can store reviews data in one single place * Update test so instead of creating a new post in each test, we go to the already-created post * Add source comments to reviews data to match it with the script --------- Co-authored-by: github-actions <github-actions@github.com> * Release: Remove 8.5 change files (#43022) Delete changelog files from 8.5 release Co-authored-by: WooCommerce Bot <no-reply@woo.com> Co-authored-by: Alex López <alex.lopez@automattic.com> * Delete changelog files based on PR 43033 (#43079) Delete changelog files for 43033 Co-authored-by: WooCommerce Bot <no-reply@woo.com> * Delete changelog files based on PR 43051 (#43081) Delete changelog files for 43051 Co-authored-by: WooCommerce Bot <no-reply@woo.com> * Interactive Price Filter: use `context` instead of `state` (#42980) * feat: use context instead of state * fix: temporary move the context to inner element for diffing to work * fix: update context before navigation for optimistic UI * Load google analytics gtag script asynchronously in WooCommerce Blocks (#43040) Co-authored-by: github-actions <github-actions@github.com> * set WOOCOMMERCE_BLOCKS_PHASE to 1 for the production build (#43074) * set WOOCOMMERCE_BLOCKS_PHASE to 1 for the production build * Add changefile(s) from automation for the following project(s): woocommerce --------- Co-authored-by: github-actions <github-actions@github.com> * Revert "Fix schedule sales error" (#43094) Revert "Fix schedule sales error (#42700)" This reverts commit 9b800aa179b25bafebfed0da8c00eec892272cb4. * [Product Block Editor]: add Linked product sections. First approach. (#43013) * add Linked products, Upsell section * changelog * add Cross-lens section * add links to the Upsell sections * changelog * fix lint issues * fix lint issus * fix linting issue :-| * check whether the linked product group is defined * [Product Block Editor]: introduce ShoppingBags component (#43042) * add ShoppingBags component * Add ShoppingBag story * changelog * Fix: Collection data being leaked between Collection Filters blocks (#43044) * fix: CYS - change heading color (#43076) * fix: CYS - change heading color * Add changefile(s) from automation for the following project(s): woocommerce --------- Co-authored-by: github-actions <github-actions@github.com> Co-authored-by: Patricia Hillebrandt <patriciahillebrandt@gmail.com> * Delete changelog files based on PR 43074 (#43118) Delete changelog files for 43074 Co-authored-by: WooCommerce Bot <no-reply@woo.com> * [Product Block Editor]: fix feature flag to hide the Linked products (#43119) * fix flag to hide/show product editor * changelog * Add changelog --------- Co-authored-by: Albert Juhé Lluveras <contact@albertjuhe.com> Co-authored-by: Jonathan Lane <lanej0@users.noreply.github.com> Co-authored-by: Jon Lane <jon.lane@automattic.com> Co-authored-by: louwie17 <lourensschep@gmail.com> Co-authored-by: Fernando Marichal <fernando.marichal@automattic.com> Co-authored-by: Marc Guay <marc.guay@gmail.com> Co-authored-by: github-actions <github-actions@github.com> Co-authored-by: Damián Suárez <rdsuarez@gmail.com> Co-authored-by: Maikel David Pérez Gómez <maikel.perez@automattic.com> Co-authored-by: Sam Seay <samueljseay@gmail.com> Co-authored-by: Néstor Soriano <konamiman@konamiman.com> Co-authored-by: Corey McKrill <916023+coreymckrill@users.noreply.github.com> Co-authored-by: Kyle Nel <22053773+kdevnel@users.noreply.github.com> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: WooCommerce Bot <no-reply@woo.com> Co-authored-by: Alex López <alex.lopez@automattic.com> Co-authored-by: Tung Du <dinhtungdu@gmail.com> Co-authored-by: Thomas Roberts <5656702+opr@users.noreply.github.com> Co-authored-by: Luigi Teschio <gigitux@gmail.com> Co-authored-by: Patricia Hillebrandt <patriciahillebrandt@gmail.com>
2023-12-29 15:28:11 +00:00
- Install and activate [WooCommerce Bookings](https://woo.com/products/woocommerce-bookings/). Add a bookable product, ensure to add a cost to it on the edit product page, then:
- Add a _normal_ (i.e. Beanie, Hoodie etc.) product to the cart and ensure you can check out successfully.
- Then add a bookable product, ensure you can check out successfully.
2022-08-25 10:44:31 +00:00
### Interaction with another payment method added by extension
- Edit the bookable product and set the `Check this box if the booking requires admin approval/confirmation. Payment will not be taken during checkout.` option to true.
- Add this product to the cart and ensure you can check out.
2022-08-25 10:44:31 +00:00
### Payment filtering by extensions
- Enable the Cash on Delivery payment method.
- Install the `@woocommerce/extend-cart-checkout-block` template by using the following command. Run this from your `wp-content/plugins` directory: `npx @wordpress/create-block -t @woocommerce/extend-cart-checkout-block payment-test-plugin`.
- This will install a plugin called `Payment Test Plugin`. Find this and activate it.
- By default, this example template has the following code [https://github.com/woocommerce/woocommerce/blob/trunk/packages/js/extend-cart-checkout-block/src/js/filters.js.mustache#L17](https://github.com/woocommerce/woocommerce/blob/trunk/packages/js/extend-cart-checkout-block/src/js/filters.js.mustache#L17) which will disable COD if the billing city is Denver.
- Go to the front-end and enter Denver in the billing city.
- Ensure COD is removed as an option.
- Change Denver to something else and ensure COD reappears as an option.
2022-08-25 10:44:31 +00:00
## Checkout
### Event emitters - code changes required to test
Again, this requires us to make changes to the Stripe plugin as this is the easiest way to test event emitters. Go to:
1. [https://github.com/woocommerce/woocommerce-gateway-stripe/blob/9a30800f2aab8e280b61a4f7ed97885f5ba81a56/client/blocks/credit-card/use-checkout-subscriptions.js#L55-L64](https://github.com/woocommerce/woocommerce-gateway-stripe/blob/9a30800f2aab8e280b61a4f7ed97885f5ba81a56/client/blocks/credit-card/use-checkout-subscriptions.js#L55-L64)
2. [https://github.com/woocommerce/woocommerce-gateway-stripe/blob/8ffd22aff3b06eda02a1ae2fd8368b71450b36a9/client/blocks/credit-card/use-payment-processing.js#L47](https://github.com/woocommerce/woocommerce-gateway-stripe/blob/8ffd22aff3b06eda02a1ae2fd8368b71450b36a9/client/blocks/credit-card/use-payment-processing.js#L47)
3. [https://github.com/woocommerce/woocommerce-gateway-stripe/blob/8ffd22aff3b06eda02a1ae2fd8368b71450b36a9/client/blocks/credit-card/use-payment-processing.js#L146](https://github.com/woocommerce/woocommerce-gateway-stripe/blob/8ffd22aff3b06eda02a1ae2fd8368b71450b36a9/client/blocks/credit-card/use-payment-processing.js#L146)
In the position linked in point 1, add `eventRegistration` as a new argument to the `usePaymentProcessing` function. It should now look like this:
```js
usePaymentProcessing(
onStripeError,
error,
stripe,
billing,
emitResponse,
sourceId,
setSourceId,
onPaymentSetup,
eventRegistration
2022-08-25 10:44:31 +00:00
);
```
In the location linked on point 2, add `eventRegistration` as the last argument. The function signature should look like this:
```js
export const usePaymentProcessing = (
onStripeError,
error,
stripe,
billing,
emitResponse,
sourceId,
setSourceId,
onPaymentSetup,
2022-08-25 10:44:31 +00:00
eventRegistration
) => {
...
```
In the location linked in point 3, add the following:
#### `onCheckoutValidation`
2022-08-25 10:44:31 +00:00
```js
const unsubscribeValidation = eventRegistration.onCheckoutValidation( ( a ) => {
console.log( 'onCheckoutValidation', a );
} );
2022-08-25 10:44:31 +00:00
```
#### `onCheckoutFail`
2022-08-25 10:44:31 +00:00
```js
const unsubscribeOnCheckoutFail = eventRegistration.onCheckoutFail( ( a ) => {
console.log( 'onCheckoutFail', a );
} );
2022-08-25 10:44:31 +00:00
```
#### `onCheckoutSuccess`
2022-08-25 10:44:31 +00:00
```js
const unsubscribeOnCheckoutSuccess = eventRegistration.onCheckoutSuccess(
( a ) => {
console.log( 'onCheckoutSuccess', a );
}
);
2022-08-25 10:44:31 +00:00
```
#### `onCheckoutBeforeProcessing` (deprecated)
```js
const unsubscribeOnCheckoutBeforeProcessing =
eventRegistration.onCheckoutBeforeProcessing( ( a ) => {
// Expect a deprecated message here.
console.log( 'onCheckoutBeforeProcessing', a );
} );
2022-08-25 10:44:31 +00:00
```
Then, in the returned function, [https://github.com/woocommerce/woocommerce-gateway-stripe/blob/8ffd22aff3b06eda02a1ae2fd8368b71450b36a9/client/blocks/credit-card/use-payment-processing.js#L147-L149](https://github.com/woocommerce/woocommerce-gateway-stripe/blob/8ffd22aff3b06eda02a1ae2fd8368b71450b36a9/client/blocks/credit-card/use-payment-processing.js#L147-L149) below, add:
```js
unsubscribeOnCheckoutValidation();
unsubscribeOnCheckoutSuccess();
unsubscribeOnCheckoutFail();
2022-08-25 10:44:31 +00:00
unsubscribeOnCheckoutBeforeProcessing();
```
After these changes have been made, your file should look like this: [https://gist.github.com/opr/1f71e72ea8bee0a58d33f6f0412af51f](https://gist.github.com/opr/1f71e72ea8bee0a58d33f6f0412af51f)
### Getting to some testing
1. Ensure you can check out correctly.
2. Press the `Place Order` button and ensure all checkout controls are disabled while processing is taking place.
3. After making the code changes above, you need to use the Stripe payment method (entering new card details in this component each time!)
<img width="647" alt="image" src="https://user-images.githubusercontent.com/5656702/175654613-4f94853a-f96c-4cb8-9f07-d759d049db8a.png">
2022-08-25 10:44:31 +00:00
4. In the console section of dev tools, enable the `Preserve log` option.
5. Then do the following:
- Check out using a valid card. You should see a message telling you `onCheckoutBeforeProcessing` is deprecated then when you check out you should see, in the same order, the following logs:
- `onCheckoutValidation` `{}`
- `onCheckoutBeforeProcessing` `{}`
- `onCheckoutSuccess` `{redirectUrl, orderId, customerId, orderNotes, paymentResult }
- Check out using an invalid card, you should only see:
2022-08-25 10:44:31 +00:00
- `onCheckoutValidation` `{}`
- `onCheckoutBeforeProcessing` `{}`
2022-08-25 10:44:31 +00:00
- Reload the checkout page and then go to [https://github.com/woocommerce/woocommerce-blocks/blob/029b379138906872dec3ed920fcb23d24404a3f2/src/StoreApi/Schemas/V1/CheckoutSchema.php#L26-L25](https://github.com/woocommerce/woocommerce-blocks/blob/029b379138906872dec3ed920fcb23d24404a3f2/src/StoreApi/Schemas/V1/CheckoutSchema.php#L26-L25) and introduce a syntax error. Try to check out using a valid card, then an invalid card you should see:
- `onCheckoutValidation` `{}`
- `onCheckoutBeforeProcessing` `{}`
- `onCheckoutFail` `{redirectUrl, orderId, customerId, orderNotes, paymentResult }`
2022-08-25 10:44:31 +00:00
## WordPress.com
It would be useful to test these on WordPress.com as well - run `npm run package-plugin:deploy` from the repo root, then upload the resulting zip file to a WordPress.com site. Set up the store and repeat the testing instructions there.