Replaced the `createSimpleProduct` helper with a usage of the factory

This commit is contained in:
Christopher Allford 2020-07-02 10:50:56 -07:00
parent f11a47693b
commit 3e69dd3a64
6 changed files with 4525 additions and 18 deletions

4473
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -34,6 +34,7 @@
"@typescript-eslint/eslint-plugin": "3.1.0", "@typescript-eslint/eslint-plugin": "3.1.0",
"@typescript-eslint/parser": "3.1.0", "@typescript-eslint/parser": "3.1.0",
"@woocommerce/e2e-environment": "file:tests/e2e/env", "@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-plugin-import-jsx-pragma": "1.1.3",
"@wordpress/babel-preset-default": "3.0.2", "@wordpress/babel-preset-default": "3.0.2",
"@wordpress/e2e-test-utils": "4.6.0", "@wordpress/e2e-test-utils": "4.6.0",

View File

@ -5,3 +5,6 @@ echo "Initializing WooCommerce E2E"
wp plugin install woocommerce --activate wp plugin install woocommerce --activate
wp theme install twentynineteen --activate wp theme install twentynineteen --activate
wp user create customer customer@woocommercecoree2etestsuite.com --user_pass=password --role=customer --path=/var/www/html 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

View File

@ -14,4 +14,4 @@ export * from './models';
* UTILITIES * UTILITIES
* These exports relate to common utilities that can be used to utilize the package. * These exports relate to common utilities that can be used to utilize the package.
*/ */
export { initializeAPIAdapters } from './utils'; export { initializeUsingOAuth, initializeUsingBasicAuth } from './utils';

View File

@ -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} consumerKey The OAuth consumer key for the API service.
* @param {string} consumerSecret The OAuth consumer secret for the API service. * @param {string} consumerSecret The OAuth consumer secret for the API service.
*/ */
export function initializeAPIAdapters( export function initializeUsingOAuth(
registry: ModelRegistry, registry: ModelRegistry,
apiURL: string, apiURL: string,
consumerKey: string, consumerKey: string,
@ -26,3 +26,30 @@ export function initializeAPIAdapters(
adapter.setAPIService( apiService ); 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 );
}
}

View File

@ -7,6 +7,12 @@
*/ */
import { StoreOwnerFlow } from './flows'; import { StoreOwnerFlow } from './flows';
import { clickTab, uiUnblocked, verifyCheckboxIsUnset } from './index'; import { clickTab, uiUnblocked, verifyCheckboxIsUnset } from './index';
import {
AdapterTypes,
initializeUsingBasicAuth,
ModelRegistry,
registerSimpleProduct, SimpleProduct
} from '@woocommerce/e2e-factories';
const config = require( 'config' ); const config = require( 'config' );
const simpleProductName = config.get( 'products.simple.name' ); const simpleProductName = config.get( 'products.simple.name' );
@ -347,22 +353,19 @@ const completeOldSetupWizard = async () => {
* Create simple product. * Create simple product.
*/ */
const createSimpleProduct = async () => { const createSimpleProduct = async () => {
// Go to "add product" page const registry = new ModelRegistry()
await StoreOwnerFlow.openNewProduct(); registerSimpleProduct( registry );
initializeUsingBasicAuth( registry,
// Make sure we're on the add order page config.get( 'url' ) + '/wp-json',
await expect( page.title() ).resolves.toMatch( 'Add new product' ); config.get( 'users.admin.username' ),
config.get( 'users.admin.password' )
// Set product data );
await expect( page ).toFill( '#title', simpleProductName ); registry.changeAllFactoryAdapters( AdapterTypes.API );
await clickTab( 'General' ); const product = await registry.getFactory( SimpleProduct ).create( {
await expect( page ).toFill( '#_regular_price', '9.99' ); Name: config.get( 'products.simple.name' ),
RegularPrice: '9.99'
await verifyAndPublish(); } );
return product.ID;
const simplePostId = await page.$( '#post_ID' );
let simplePostIdValue = ( await ( await simplePostId.getProperty( 'value' ) ).jsonValue() );
return simplePostIdValue;
} ; } ;
/** /**