Fix order email receiving test (#34972)
* Added JS data file * Moved onboarding logic into utils folder * Used new onboarding methods and data file * Added changelog * Moved utils directory * Added api utils * Added customer details data * Used new api utils and data * Updated path * Added comment and removed log * Removed log * Added changelog
This commit is contained in:
parent
aa438e5741
commit
91e1347aab
|
@ -1,4 +0,0 @@
|
|||
Significance: patch
|
||||
Type: dev
|
||||
|
||||
Moved onboarding methods into utils method for the sake of reusability
|
|
@ -0,0 +1,4 @@
|
|||
Significance: patch
|
||||
Type: dev
|
||||
|
||||
set the store country in the test step
|
|
@ -10,7 +10,8 @@ const storeDetails = {
|
|||
city: 'San Francisco',
|
||||
zip: '94107',
|
||||
email: adminEmail,
|
||||
country: 'United States (US) — California', // corresponding to the text value of the option
|
||||
country: 'United States (US) — California', // corresponding to the text value of the option,
|
||||
countryCode: 'US:CA',
|
||||
},
|
||||
expectedIndustries: 8, // There are 8 checkboxes on the page (in the US), adjust this constant if we change that
|
||||
industries: {
|
||||
|
@ -28,7 +29,8 @@ const storeDetails = {
|
|||
city: 'Valletta',
|
||||
zip: 'VT 1011',
|
||||
email: adminEmail,
|
||||
country: 'Malta', // corresponding to the text value of the option
|
||||
country: 'Malta', // corresponding to the text value of the option,
|
||||
countryCode: 'MT',
|
||||
},
|
||||
expectedIndustries: 7, // There are 7 checkboxes on the page (in Malta), adjust this constant if we change that
|
||||
industries: {
|
||||
|
@ -41,6 +43,31 @@ const storeDetails = {
|
|||
},
|
||||
};
|
||||
|
||||
const customerDetails = {
|
||||
us: {
|
||||
first_name: 'Maggie',
|
||||
last_name: 'Simpson',
|
||||
address: '123 Evergreen Terrace',
|
||||
city: 'Springfield',
|
||||
country: 'US',
|
||||
state: 'OR',
|
||||
zip: '97403',
|
||||
phone: '555 555-5555',
|
||||
email: 'customer@example.com',
|
||||
},
|
||||
malta: {
|
||||
first_name: 'Maggie',
|
||||
last_name: 'Simpson',
|
||||
address: '123 Evergreen Terrace',
|
||||
city: 'Valletta',
|
||||
country: 'MT',
|
||||
zip: 'VT 1011',
|
||||
phone: '555 555-5555',
|
||||
email: 'vt-customer@example.com',
|
||||
},
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
storeDetails,
|
||||
customerDetails,
|
||||
};
|
||||
|
|
|
@ -1,56 +1,24 @@
|
|||
const { test, expect } = require( '@playwright/test' );
|
||||
const wcApi = require( '@woocommerce/woocommerce-rest-api' ).default;
|
||||
const { customerDetails, storeDetails } = require( '../../test-data/data' );
|
||||
const { api } = require( '../../utils' );
|
||||
|
||||
let productId, orderId;
|
||||
const productName = 'Order email product';
|
||||
|
||||
const product = {
|
||||
name: 'Order email product',
|
||||
type: 'simple',
|
||||
price: '42.77',
|
||||
};
|
||||
|
||||
const customerEmail = 'order-email-test@example.com';
|
||||
const storeName = 'WooCommerce Core E2E Test Suite';
|
||||
|
||||
test.describe( 'Shopper Order Email Receiving', () => {
|
||||
test.use( { storageState: process.env.ADMINSTATE } );
|
||||
|
||||
test.beforeAll( async ( { baseURL } ) => {
|
||||
const api = new wcApi( {
|
||||
url: baseURL,
|
||||
consumerKey: process.env.CONSUMER_KEY,
|
||||
consumerSecret: process.env.CONSUMER_SECRET,
|
||||
version: 'wc/v3',
|
||||
} );
|
||||
// ensure store address is US
|
||||
await api.post( 'settings/general/batch', {
|
||||
update: [
|
||||
{
|
||||
id: 'woocommerce_store_address',
|
||||
value: 'addr 1',
|
||||
},
|
||||
{
|
||||
id: 'woocommerce_store_city',
|
||||
value: 'San Francisco',
|
||||
},
|
||||
{
|
||||
id: 'woocommerce_default_country',
|
||||
value: 'US:CA',
|
||||
},
|
||||
{
|
||||
id: 'woocommerce_store_postcode',
|
||||
value: '94107',
|
||||
},
|
||||
],
|
||||
} );
|
||||
// add product
|
||||
await api
|
||||
.post( 'products', {
|
||||
name: productName,
|
||||
type: 'simple',
|
||||
regular_price: '42.77',
|
||||
} )
|
||||
.then( ( response ) => {
|
||||
productId = response.data.id;
|
||||
} );
|
||||
// enable COD payment
|
||||
await api.put( 'payment_gateways/cod', {
|
||||
enabled: true,
|
||||
} );
|
||||
test.beforeAll( async () => {
|
||||
productId = await api.create.product( product );
|
||||
await api.update.enableCashOnDelivery();
|
||||
} );
|
||||
|
||||
test.beforeEach( async ( { page } ) => {
|
||||
|
@ -67,42 +35,38 @@ test.describe( 'Shopper Order Email Receiving', () => {
|
|||
}
|
||||
} );
|
||||
|
||||
test.afterAll( async ( { baseURL } ) => {
|
||||
const api = new wcApi( {
|
||||
url: baseURL,
|
||||
consumerKey: process.env.CONSUMER_KEY,
|
||||
consumerSecret: process.env.CONSUMER_SECRET,
|
||||
version: 'wc/v3',
|
||||
} );
|
||||
await api.delete( `products/${ productId }`, {
|
||||
force: true,
|
||||
} );
|
||||
test.afterAll( async () => {
|
||||
await api.deletePost.product( productId );
|
||||
if ( orderId ) {
|
||||
await api.delete( `orders/${ orderId }`, {
|
||||
force: true,
|
||||
} );
|
||||
await api.deletePost.order( orderId );
|
||||
}
|
||||
await api.put( 'payment_gateways/cod', {
|
||||
enabled: false,
|
||||
} );
|
||||
await api.update.disableCashOnDelivery();
|
||||
} );
|
||||
|
||||
test( 'should receive order email after purchasing an item', async ( {
|
||||
page,
|
||||
} ) => {
|
||||
// ensure that the store's address is in the US
|
||||
await api.update.storeDetails( storeDetails.us.store );
|
||||
|
||||
await page.goto( `/shop/?add-to-cart=${ productId }` );
|
||||
await page.waitForLoadState( 'networkidle' );
|
||||
|
||||
await page.goto( '/checkout/' );
|
||||
|
||||
await page.fill( '#billing_first_name', 'Maggie' );
|
||||
await page.fill( '#billing_last_name', 'Simpson' );
|
||||
await page.fill( '#billing_address_1', '123 Evergreen Terrace' );
|
||||
await page.fill( '#billing_city', 'Springfield' );
|
||||
await page.selectOption( '#billing_country', 'US' );
|
||||
await page.selectOption( '#billing_state', 'OR' );
|
||||
await page.fill( '#billing_postcode', '97403' );
|
||||
await page.fill( '#billing_phone', '555 555-5555' );
|
||||
await page.fill( '#billing_first_name', customerDetails.us.first_name );
|
||||
await page.fill( '#billing_last_name', customerDetails.us.last_name );
|
||||
await page.fill( '#billing_address_1', customerDetails.us.address );
|
||||
await page.fill( '#billing_city', customerDetails.us.city );
|
||||
await page.selectOption(
|
||||
'#billing_country',
|
||||
customerDetails.us.country
|
||||
);
|
||||
|
||||
await page.selectOption( '#billing_state', customerDetails.us.state );
|
||||
|
||||
await page.fill( '#billing_postcode', customerDetails.us.zip );
|
||||
await page.fill( '#billing_phone', customerDetails.us.phone );
|
||||
await page.fill( '#billing_email', customerEmail );
|
||||
|
||||
await page.click( 'text=Place order' );
|
||||
|
|
|
@ -0,0 +1,94 @@
|
|||
const wcApi = require( '@woocommerce/woocommerce-rest-api' ).default;
|
||||
const config = require( '../playwright.config' );
|
||||
|
||||
let api;
|
||||
|
||||
// Ensure that global-setup.js runs before creating api client
|
||||
if ( process.env.CONSUMER_KEY && process.env.CONSUMER_SECRET ) {
|
||||
api = new wcApi( {
|
||||
url: config.use.baseURL,
|
||||
consumerKey: process.env.CONSUMER_KEY,
|
||||
consumerSecret: process.env.CONSUMER_SECRET,
|
||||
version: 'wc/v3',
|
||||
} );
|
||||
}
|
||||
|
||||
const update = {
|
||||
storeDetails: async ( store ) => {
|
||||
// ensure store address is US
|
||||
const res = await api.post( 'settings/general/batch', {
|
||||
update: [
|
||||
{
|
||||
id: 'woocommerce_store_address',
|
||||
value: store.address,
|
||||
},
|
||||
{
|
||||
id: 'woocommerce_store_city',
|
||||
value: store.city,
|
||||
},
|
||||
{
|
||||
id: 'woocommerce_default_country',
|
||||
value: store.countryCode,
|
||||
},
|
||||
{
|
||||
id: 'woocommerce_store_postcode',
|
||||
value: store.zip,
|
||||
},
|
||||
],
|
||||
} );
|
||||
},
|
||||
enableCashOnDelivery: async () => {
|
||||
await api.put( 'payment_gateways/cod', {
|
||||
enabled: true,
|
||||
} );
|
||||
},
|
||||
disableCashOnDelivery: async () => {
|
||||
await api.put( 'payment_gateways/cod', {
|
||||
enabled: false,
|
||||
} );
|
||||
},
|
||||
};
|
||||
|
||||
const get = {
|
||||
defaultCountry: async () => {
|
||||
const response = await api.get(
|
||||
'settings/general/woocommerce_default_country'
|
||||
);
|
||||
|
||||
const code = response.data.default;
|
||||
|
||||
return code;
|
||||
},
|
||||
};
|
||||
|
||||
const create = {
|
||||
product: async ( product ) => {
|
||||
const response = await api.post( 'products', {
|
||||
name: product.name,
|
||||
type: product.type,
|
||||
regular_price: product.price,
|
||||
} );
|
||||
|
||||
return response.data.id;
|
||||
},
|
||||
};
|
||||
|
||||
const deletePost = {
|
||||
product: async ( id ) => {
|
||||
await api.delete( `products/${ id }`, {
|
||||
force: true,
|
||||
} );
|
||||
},
|
||||
order: async ( id ) => {
|
||||
await api.delete( `orders/${ id }`, {
|
||||
force: true,
|
||||
} );
|
||||
},
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
update,
|
||||
get,
|
||||
create,
|
||||
deletePost,
|
||||
};
|
|
@ -1,5 +1,7 @@
|
|||
const onboarding = require( './onboarding' );
|
||||
const api = require( './api' );
|
||||
|
||||
module.exports = {
|
||||
onboarding,
|
||||
api,
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue