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',
|
city: 'San Francisco',
|
||||||
zip: '94107',
|
zip: '94107',
|
||||||
email: adminEmail,
|
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
|
expectedIndustries: 8, // There are 8 checkboxes on the page (in the US), adjust this constant if we change that
|
||||||
industries: {
|
industries: {
|
||||||
|
@ -28,7 +29,8 @@ const storeDetails = {
|
||||||
city: 'Valletta',
|
city: 'Valletta',
|
||||||
zip: 'VT 1011',
|
zip: 'VT 1011',
|
||||||
email: adminEmail,
|
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
|
expectedIndustries: 7, // There are 7 checkboxes on the page (in Malta), adjust this constant if we change that
|
||||||
industries: {
|
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 = {
|
module.exports = {
|
||||||
storeDetails,
|
storeDetails,
|
||||||
|
customerDetails,
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,56 +1,24 @@
|
||||||
const { test, expect } = require( '@playwright/test' );
|
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;
|
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 customerEmail = 'order-email-test@example.com';
|
||||||
const storeName = 'WooCommerce Core E2E Test Suite';
|
const storeName = 'WooCommerce Core E2E Test Suite';
|
||||||
|
|
||||||
test.describe( 'Shopper Order Email Receiving', () => {
|
test.describe( 'Shopper Order Email Receiving', () => {
|
||||||
test.use( { storageState: process.env.ADMINSTATE } );
|
test.use( { storageState: process.env.ADMINSTATE } );
|
||||||
|
|
||||||
test.beforeAll( async ( { baseURL } ) => {
|
test.beforeAll( async () => {
|
||||||
const api = new wcApi( {
|
productId = await api.create.product( product );
|
||||||
url: baseURL,
|
await api.update.enableCashOnDelivery();
|
||||||
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.beforeEach( async ( { page } ) => {
|
test.beforeEach( async ( { page } ) => {
|
||||||
|
@ -67,42 +35,38 @@ test.describe( 'Shopper Order Email Receiving', () => {
|
||||||
}
|
}
|
||||||
} );
|
} );
|
||||||
|
|
||||||
test.afterAll( async ( { baseURL } ) => {
|
test.afterAll( async () => {
|
||||||
const api = new wcApi( {
|
await api.deletePost.product( productId );
|
||||||
url: baseURL,
|
|
||||||
consumerKey: process.env.CONSUMER_KEY,
|
|
||||||
consumerSecret: process.env.CONSUMER_SECRET,
|
|
||||||
version: 'wc/v3',
|
|
||||||
} );
|
|
||||||
await api.delete( `products/${ productId }`, {
|
|
||||||
force: true,
|
|
||||||
} );
|
|
||||||
if ( orderId ) {
|
if ( orderId ) {
|
||||||
await api.delete( `orders/${ orderId }`, {
|
await api.deletePost.order( orderId );
|
||||||
force: true,
|
|
||||||
} );
|
|
||||||
}
|
}
|
||||||
await api.put( 'payment_gateways/cod', {
|
await api.update.disableCashOnDelivery();
|
||||||
enabled: false,
|
|
||||||
} );
|
|
||||||
} );
|
} );
|
||||||
|
|
||||||
test( 'should receive order email after purchasing an item', async ( {
|
test( 'should receive order email after purchasing an item', async ( {
|
||||||
page,
|
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.goto( `/shop/?add-to-cart=${ productId }` );
|
||||||
await page.waitForLoadState( 'networkidle' );
|
await page.waitForLoadState( 'networkidle' );
|
||||||
|
|
||||||
await page.goto( '/checkout/' );
|
await page.goto( '/checkout/' );
|
||||||
|
|
||||||
await page.fill( '#billing_first_name', 'Maggie' );
|
await page.fill( '#billing_first_name', customerDetails.us.first_name );
|
||||||
await page.fill( '#billing_last_name', 'Simpson' );
|
await page.fill( '#billing_last_name', customerDetails.us.last_name );
|
||||||
await page.fill( '#billing_address_1', '123 Evergreen Terrace' );
|
await page.fill( '#billing_address_1', customerDetails.us.address );
|
||||||
await page.fill( '#billing_city', 'Springfield' );
|
await page.fill( '#billing_city', customerDetails.us.city );
|
||||||
await page.selectOption( '#billing_country', 'US' );
|
await page.selectOption(
|
||||||
await page.selectOption( '#billing_state', 'OR' );
|
'#billing_country',
|
||||||
await page.fill( '#billing_postcode', '97403' );
|
customerDetails.us.country
|
||||||
await page.fill( '#billing_phone', '555 555-5555' );
|
);
|
||||||
|
|
||||||
|
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.fill( '#billing_email', customerEmail );
|
||||||
|
|
||||||
await page.click( 'text=Place order' );
|
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 onboarding = require( './onboarding' );
|
||||||
|
const api = require( './api' );
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
onboarding,
|
onboarding,
|
||||||
|
api,
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue