Moved the factory package init into a common utility
This commit is contained in:
parent
9b18a95f93
commit
4373c7be1b
|
@ -7,12 +7,8 @@
|
||||||
*/
|
*/
|
||||||
import { StoreOwnerFlow } from './flows';
|
import { StoreOwnerFlow } from './flows';
|
||||||
import { clickTab, uiUnblocked, verifyCheckboxIsUnset } from './index';
|
import { clickTab, uiUnblocked, verifyCheckboxIsUnset } from './index';
|
||||||
import {
|
import modelRegistry from './factories';
|
||||||
AdapterTypes,
|
import { SimpleProduct } from '@woocommerce/e2e-factories';
|
||||||
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' );
|
||||||
|
@ -353,19 +349,11 @@ const completeOldSetupWizard = async () => {
|
||||||
* Create simple product.
|
* Create simple product.
|
||||||
*/
|
*/
|
||||||
const createSimpleProduct = async () => {
|
const createSimpleProduct = async () => {
|
||||||
const registry = new ModelRegistry()
|
const product = await modelRegistry.getFactory( SimpleProduct ).create( {
|
||||||
registerSimpleProduct( registry );
|
name: simpleProductName,
|
||||||
initializeUsingBasicAuth( registry,
|
regularPrice: '9.99'
|
||||||
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;
|
return product.id;
|
||||||
} ;
|
} ;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -0,0 +1,24 @@
|
||||||
|
import {
|
||||||
|
AdapterTypes,
|
||||||
|
initializeUsingBasicAuth,
|
||||||
|
ModelRegistry,
|
||||||
|
registerSimpleProduct
|
||||||
|
} from '@woocommerce/e2e-factories';
|
||||||
|
|
||||||
|
const config = require( 'config' );
|
||||||
|
|
||||||
|
const modelRegistry = new ModelRegistry()
|
||||||
|
|
||||||
|
// Register all of the different factories that we're going to need.
|
||||||
|
registerSimpleProduct( modelRegistry );
|
||||||
|
|
||||||
|
// Make sure to perform the initialization AFTER registering all of the factories, otherwise the adapters might be
|
||||||
|
// missed on subsequent registrations.
|
||||||
|
initializeUsingBasicAuth( modelRegistry,
|
||||||
|
config.get( 'url' ) + '/wp-json',
|
||||||
|
config.get( 'users.admin.username' ),
|
||||||
|
config.get( 'users.admin.password' )
|
||||||
|
);
|
||||||
|
modelRegistry.changeAllFactoryAdapters( AdapterTypes.API );
|
||||||
|
|
||||||
|
export default modelRegistry;
|
Loading…
Reference in New Issue