@woocommerce/e2e-utils: updated fishery to 1.2
Now that my PR adding support for async creation has been merged we can remove the AsyncFactory class we were using as a temporary workaround.
This commit is contained in:
parent
6134d0ffc8
commit
3ea6f8d5c5
|
@ -15,7 +15,7 @@
|
|||
"@wordpress/e2e-test-utils": "^4.6.0",
|
||||
"config": "3.3.3",
|
||||
"faker": "^5.1.0",
|
||||
"fishery": "^1.0.1"
|
||||
"fishery": "^1.2.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@woocommerce/api": "^0.1.0"
|
||||
|
|
|
@ -1,41 +0,0 @@
|
|||
import { Factory } from 'fishery';
|
||||
|
||||
/**
|
||||
* A temporary class until Fishery includes better async support.
|
||||
*/
|
||||
export class AsyncFactory extends Factory {
|
||||
constructor( generator, creator ) {
|
||||
super( generator );
|
||||
this.creator = creator;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an object using your factory
|
||||
*
|
||||
* @param {*} params The parameters that should populate the object.
|
||||
* @param {*} options The options to be used in the builder.
|
||||
* @return {Promise} Resolves to the created model.
|
||||
*/
|
||||
create( params = {}, options = {} ) {
|
||||
const model = this.build( params, options );
|
||||
return this.creator( model );
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an array of objects using your factory
|
||||
*
|
||||
* @param {number} number The number of models to create.
|
||||
* @param {*} params The parameters that should populate the object.
|
||||
* @param {*} options The options to be used in the builder.
|
||||
* @return {Promise} Resolves to the created models.
|
||||
*/
|
||||
createList( number, params = {}, options = {} ) {
|
||||
const models = this.buildList( number, params, options );
|
||||
const promises = [];
|
||||
for ( const model of models ) {
|
||||
promises.push( this.creator( model ) );
|
||||
}
|
||||
|
||||
return Promise.all( promises );
|
||||
}
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
import { SimpleProduct } from '@woocommerce/api';
|
||||
import { AsyncFactory } from './async-factory';
|
||||
import faker from 'faker/locale/en';
|
||||
import { Factory } from 'fishery';
|
||||
|
||||
/**
|
||||
* Creates a new factory for creating models.
|
||||
|
@ -11,13 +11,14 @@ import faker from 'faker/locale/en';
|
|||
export function simpleProductFactory( httpClient ) {
|
||||
const repository = SimpleProduct.restRepository( httpClient );
|
||||
|
||||
return new AsyncFactory(
|
||||
( { params } ) => {
|
||||
return {
|
||||
name: params.name ?? faker.commerce.productName(),
|
||||
regularPrice: params.regularPrice ?? faker.commerce.price(),
|
||||
};
|
||||
},
|
||||
( params ) => repository.create( params ),
|
||||
);
|
||||
return Factory.define( ( { params, onCreate } ) => {
|
||||
onCreate( ( model ) => {
|
||||
return repository.create( model );
|
||||
} );
|
||||
|
||||
return {
|
||||
name: params.name ?? faker.commerce.productName(),
|
||||
regularPrice: params.regularPrice ?? faker.commerce.price(),
|
||||
};
|
||||
} );
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue