Replaced the `createSimpleProduct` helper with a usage of the factory
This commit is contained in:
parent
f11a47693b
commit
3e69dd3a64
File diff suppressed because it is too large
Load Diff
|
@ -34,6 +34,7 @@
|
|||
"@typescript-eslint/eslint-plugin": "3.1.0",
|
||||
"@typescript-eslint/parser": "3.1.0",
|
||||
"@woocommerce/e2e-environment": "file:tests/e2e/env",
|
||||
"@woocommerce/e2e-factories": "file:tests/e2e/factories",
|
||||
"@wordpress/babel-plugin-import-jsx-pragma": "1.1.3",
|
||||
"@wordpress/babel-preset-default": "3.0.2",
|
||||
"@wordpress/e2e-test-utils": "4.6.0",
|
||||
|
|
|
@ -5,3 +5,6 @@ echo "Initializing WooCommerce E2E"
|
|||
wp plugin install woocommerce --activate
|
||||
wp theme install twentynineteen --activate
|
||||
wp user create customer customer@woocommercecoree2etestsuite.com --user_pass=password --role=customer --path=/var/www/html
|
||||
|
||||
# we cannot create API keys for the API, so we using basic auth, this plugin allows that.
|
||||
wp plugin install https://github.com/WP-API/Basic-Auth/archive/master.zip --activate
|
||||
|
|
|
@ -14,4 +14,4 @@ export * from './models';
|
|||
* UTILITIES
|
||||
* These exports relate to common utilities that can be used to utilize the package.
|
||||
*/
|
||||
export { initializeAPIAdapters } from './utils';
|
||||
export { initializeUsingOAuth, initializeUsingBasicAuth } from './utils';
|
||||
|
|
|
@ -10,7 +10,7 @@ import { AxiosAPIService } from './framework/api/axios/axios-api-service';
|
|||
* @param {string} consumerKey The OAuth consumer key for the API service.
|
||||
* @param {string} consumerSecret The OAuth consumer secret for the API service.
|
||||
*/
|
||||
export function initializeAPIAdapters(
|
||||
export function initializeUsingOAuth(
|
||||
registry: ModelRegistry,
|
||||
apiURL: string,
|
||||
consumerKey: string,
|
||||
|
@ -26,3 +26,30 @@ export function initializeAPIAdapters(
|
|||
adapter.setAPIService( apiService );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize all of the APIAdapters with a client to communicate with the API.
|
||||
*
|
||||
*
|
||||
*
|
||||
* @param {ModelRegistry} registry The model registry that we want to initialize.
|
||||
* @param {string} apiURL The base URL for the API.
|
||||
* @param {string} username The username to use for authentication.
|
||||
* @param {string} password The password to use for authentication.
|
||||
*/
|
||||
export function initializeUsingBasicAuth(
|
||||
registry: ModelRegistry,
|
||||
apiURL: string,
|
||||
username: string,
|
||||
password: string,
|
||||
): void {
|
||||
const adapters = registry.getAdapters( AdapterTypes.API ) as APIAdapter<any>[];
|
||||
if ( ! adapters.length ) {
|
||||
return;
|
||||
}
|
||||
|
||||
const apiService = AxiosAPIService.createUsingBasicAuth( apiURL, username, password );
|
||||
for ( const adapter of adapters ) {
|
||||
adapter.setAPIService( apiService );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,6 +7,12 @@
|
|||
*/
|
||||
import { StoreOwnerFlow } from './flows';
|
||||
import { clickTab, uiUnblocked, verifyCheckboxIsUnset } from './index';
|
||||
import {
|
||||
AdapterTypes,
|
||||
initializeUsingBasicAuth,
|
||||
ModelRegistry,
|
||||
registerSimpleProduct, SimpleProduct
|
||||
} from '@woocommerce/e2e-factories';
|
||||
|
||||
const config = require( 'config' );
|
||||
const simpleProductName = config.get( 'products.simple.name' );
|
||||
|
@ -347,22 +353,19 @@ const completeOldSetupWizard = async () => {
|
|||
* Create simple product.
|
||||
*/
|
||||
const createSimpleProduct = async () => {
|
||||
// Go to "add product" page
|
||||
await StoreOwnerFlow.openNewProduct();
|
||||
|
||||
// Make sure we're on the add order page
|
||||
await expect( page.title() ).resolves.toMatch( 'Add new product' );
|
||||
|
||||
// Set product data
|
||||
await expect( page ).toFill( '#title', simpleProductName );
|
||||
await clickTab( 'General' );
|
||||
await expect( page ).toFill( '#_regular_price', '9.99' );
|
||||
|
||||
await verifyAndPublish();
|
||||
|
||||
const simplePostId = await page.$( '#post_ID' );
|
||||
let simplePostIdValue = ( await ( await simplePostId.getProperty( 'value' ) ).jsonValue() );
|
||||
return simplePostIdValue;
|
||||
const registry = new ModelRegistry()
|
||||
registerSimpleProduct( registry );
|
||||
initializeUsingBasicAuth( registry,
|
||||
config.get( 'url' ) + '/wp-json',
|
||||
config.get( 'users.admin.username' ),
|
||||
config.get( 'users.admin.password' )
|
||||
);
|
||||
registry.changeAllFactoryAdapters( AdapterTypes.API );
|
||||
const product = await registry.getFactory( SimpleProduct ).create( {
|
||||
Name: config.get( 'products.simple.name' ),
|
||||
RegularPrice: '9.99'
|
||||
} );
|
||||
return product.ID;
|
||||
} ;
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue