[e2e tests] Check email for completed order (#44186)

* Add completed order email test

Add test structure to verify completed order email arrival and content

* Verify Email JSON Content

Parse email content in JSON format

* Record email content in JSON

Record email content in JSON

* Update emails completed order checks

Added checks to verify the content of completed order's emails

* Add changefile(s) from automation for the following project(s): woocommerce

* Update email content const & remove duplicated test

Updated with a new const to record email content const and removed duplicated assertion.

---------

Co-authored-by: github-actions <github-actions@github.com>
This commit is contained in:
Álvaro Thomas 2024-02-02 16:13:16 +01:00 committed by GitHub
parent aa349b31a7
commit 5fd4176ad0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 65 additions and 2 deletions

View File

@ -0,0 +1,4 @@
Significance: patch
Type: dev
This aims to add more checks to confirm that a completed order email is received, as well as its content.

View File

@ -11,7 +11,7 @@ test.describe( 'Merchant > Order Action emails received', () => {
};
const storeName = 'WooCommerce Core E2E Test Suite';
let orderId, newOrderId, cancelledOrderId;
let orderId, newOrderId, cancelledOrderId, completedOrderId;
test.beforeAll( async ( { baseURL } ) => {
const api = new wcApi( {
@ -62,7 +62,7 @@ test.describe( 'Merchant > Order Action emails received', () => {
} );
await api.post( `orders/batch`, {
delete: [ orderId, newOrderId, cancelledOrderId ],
delete: [ orderId, newOrderId, completedOrderId, cancelledOrderId ],
} );
} );
@ -97,6 +97,65 @@ test.describe( 'Merchant > Order Action emails received', () => {
).toContainText( `[${ storeName }]: New order #${ newOrderId }` );
} );
test( 'can receive completed email', async ( { page, baseURL } ) => {
// Completed order emails are sent automatically when an order's payment is completed.
// Verify that the email is sent, and that the content is the expected one
const emailContent = '#wp-mail-logging-modal-content-body-content';
const emailContentJson = '#wp-mail-logging-modal-format-json';
const api = new wcApi( {
url: baseURL,
consumerKey: process.env.CONSUMER_KEY,
consumerSecret: process.env.CONSUMER_SECRET,
version: 'wc/v3',
} );
await api
.post( 'orders', {
status: 'completed',
billing: customerBilling,
} )
.then( ( response ) => {
completedOrderId = response.data.id;
} );
// Search to narrow it down to just the messages we want
await page.goto(
`wp-admin/tools.php?page=wpml_plugin_log&s=${ encodeURIComponent(
customerBilling.email
) }`
);
await page.selectOption( 'select[name="search[place]"]', 'subject' );
await page.fill( 'input[name="search[term]"]', 'complete' );
await page.click( 'input#search-submit' );
// Verify that the email has been sent
await expect(
page.getByText( `Your ${ storeName } order is now complete` )
).toBeVisible();
// Enter email log and select to view the content in JSON
await page.click( 'button[title^="View log"]' );
await page.locator( emailContentJson ).click();
// Verify that the message includes an order processing confirmation
await expect(
page.locator( emailContent )
).toContainText( 'We have finished processing your order.' );
// Verify that the email address is the correct one
await expect(
page.locator( emailContent )
).toContainText( customerBilling.email );
// Verify that the email contains the order ID
await expect(
page.locator( emailContent )
).toContainText( `[Order #${ completedOrderId.toString() }]` );
// Verify that the email contains a "Thanks" note
await expect(
page.locator( emailContent )
).toContainText( 'Thanks for shopping with us' );
} );
test( 'can receive cancelled order email', async ( { page, baseURL } ) => {
const api = new wcApi( {
url: baseURL,