Skip to content

Introduce some tools for users#7

Merged
Hug0-Drelon merged 10 commits intomasterfrom
users-utils
Mar 4, 2026
Merged

Introduce some tools for users#7
Hug0-Drelon merged 10 commits intomasterfrom
users-utils

Conversation

@Screenfeed
Copy link
Copy Markdown
Contributor

Allows to create a user with translator capabilities:

createTranslator( langSlugs, userName )

Allows to switch to the given user:

switchToUser( user, admin, requestUtils )

@Screenfeed Screenfeed added the enhancement New feature or request label Mar 3, 2026
@Screenfeed Screenfeed self-assigned this Mar 3, 2026
Copy link
Copy Markdown
Member

@Hug0-Drelon Hug0-Drelon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add a small doc in README?


expect( resultCreateUser ).toContain( 'Success: Created user' );

const { groups: user } = resultCreateUser.match(
Copy link
Copy Markdown
Member

@Hug0-Drelon Hug0-Drelon Mar 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use --porcelain to get only the ID and avoid parsing the string with a regex.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not possible.
This means we have to wp user get ${ userId } after that. Problem: this doesn't return the user's password.

Copy link
Copy Markdown
Member

@Hug0-Drelon Hug0-Drelon Mar 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, but why using a strong auto generated password here?
You can use --user_pass=password instead, am I right?

Here is as example:

const userId = execSync(
 `npx wp-env run tests-cli wp user create ${ userName } ${ email } --role=editor --user_pass=password --porcelain`
)

Then no need to call wp user get ${ userId }.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Homer bushes

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 32423f5.

@Screenfeed Screenfeed requested a review from Hug0-Drelon March 3, 2026 16:48
* @return {Promise<User>} The user.
*/
export async function createTranslator( langSlugs, userName ) {
userName =
Copy link
Copy Markdown
Member

@Hug0-Drelon Hug0-Drelon Mar 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wouldn't check types here.
The reason is that we strongly document function in this package, with TS-like checks.
If someone passes dog shit, I expect the code to fail. Here it goes on silently.
Moreover, you coded a default value but didn't document it that way.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The type check was my way to provide a default value. Improved with 61cdb97.

@Screenfeed
Copy link
Copy Markdown
Contributor Author

Could you add a small doc in README?

Done in b62615c.

@Screenfeed Screenfeed requested a review from Hug0-Drelon March 4, 2026 10:34
@Hug0-Drelon Hug0-Drelon merged commit 9497ba9 into master Mar 4, 2026
2 checks passed
@Hug0-Drelon Hug0-Drelon deleted the users-utils branch March 4, 2026 10:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants