Skip to content

Feature for handle options in Rosie #3197

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions lib/helper/ApiDataFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -257,13 +257,16 @@ class ApiDataFactory extends Helper {
* // create user with defined email
* // and receive it when inside async function
* const user = await I.have('user', { email: 'user@user.com'});
* // create a user with options that will not be included in the final request
* I.have('user', { }, { age: 33, height: 55 })
* ```
*
* @param {*} factory factory to use
* @param {*} params predefined parameters
* @param {*} options options for programmatically generate the attributes
*/
have(factory, params) {
const item = this._createItem(factory, params);
have(factory, params, options) {
const item = this._createItem(factory, params, options);
this.debug(`Creating ${factory} ${JSON.stringify(item)}`);
return this._requestCreate(factory, item);
}
Expand All @@ -277,21 +280,25 @@ class ApiDataFactory extends Helper {
*
* // create 3 posts by one author
* I.haveMultiple('post', 3, { author: 'davert' });
*
* // create 3 posts by one author with options
* I.haveMultiple('post', 3, { author: 'davert' }, { publish_date: '01.01.1997' });
* ```
*
* @param {*} factory
* @param {*} times
* @param {*} params
* @param {*} options
*/
haveMultiple(factory, times, params) {
haveMultiple(factory, times, params, options) {
const promises = [];
for (let i = 0; i < times; i++) {
promises.push(this.have(factory, params));
promises.push(this.have(factory, params, options));
}
return Promise.all(promises);
}

_createItem(model, data) {
_createItem(model, data, options) {
if (!this.factories[model]) {
throw new Error(`Factory ${model} is not defined in config`);
}
Expand All @@ -303,7 +310,7 @@ class ApiDataFactory extends Helper {
modulePath = path.join(global.codecept_dir, modulePath);
}
const builder = require(modulePath);
return builder.build(data);
return builder.build(data, options);
} catch (err) {
throw new Error(`Couldn't load factory file from ${modulePath}, check that

Expand Down