Skip to content

refactor: deduplicate unit test support functions (#323) - #328

Open
smigiska wants to merge 1 commit into
mainfrom
refactor/deduplicate-test-support-functions
Open

refactor: deduplicate unit test support functions (#323)#328
smigiska wants to merge 1 commit into
mainfrom
refactor/deduplicate-test-support-functions

Conversation

@smigiska

@smigiska smigiska commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Extracted repeated helper functions (uniqueEmail, makeToken, ensureSolvroAdminRoleId, assignSolvroAdmin) from drafts_acl.spec.ts, permissions.spec.ts, permissions_cleanup.spec.ts, and users_management.spec.ts into a shared auth_helpers.ts module, imported wherever needed.
Also added createUserWithToken / createAdminWithToken helpers to reduce repeated "create user + get token" boilerplate across the same test files.
CLOSES: #323

@smigiska
smigiska requested a review from a team as a code owner July 16, 2026 20:46
@github-actions

Copy link
Copy Markdown
Contributor

Looks like you did not link an issue to this PR. If this PR completes a task, consider linking it.

@smigiska
smigiska force-pushed the refactor/deduplicate-test-support-functions branch from 9913c65 to edde204 Compare July 16, 2026 20:55

@mini-bomba mini-bomba left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

🔥, but i've got a few suggestions

): Promise<{ user: User; token: string }> {
const user = await User.create({
email: uniqueEmail(prefix),
password: "Passw0rd!",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

minor suggestion: maybe generate a random password and return it along with the user object & token?

Comment on lines +34 to +38
const { user: u1, token: t1 } = await createUserWithToken(
uniqueEmail,
"u1",
"User 1",
);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

passing in a function that generates email addresses seems weird
imo we can drop the idea of using separate fake domains per test file - the emails contain a random string anyway, they shouldn't collide.

"User 8",
);

await user.refresh();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

why is this refresh here? it should probably be a part of the utility function if the function returns a bad user object without this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

refactor: deduplicate unit test support functions

2 participants