Skip to content
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

alt test using each #5096

Closed
wants to merge 9 commits into from
Closed

Conversation

gastonfournier
Copy link
Contributor

We have different ways of changing access to a project, this pr covers tests with different functions

@vercel
Copy link

vercel bot commented Oct 19, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
unleash-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 19, 2023 11:45am
unleash-monorepo-frontend ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 19, 2023 11:45am

Comment on lines 1055 to 1075
await expect(async () => {
await projectService.changeRole(
project.id,
memberRole.id,
user.id,
'test',
test.each([
{
name: 'changeRole',
fn: async (projectId: string, roleId: number, userId: number) =>
projectService.changeRole(projectId, roleId, userId, 'test'),
},
{
name: 'setRolesForUser',
fn: async (projectId: string, roleId: number, userId: number) =>
projectService.setRolesForUser(
projectId,
userId,
[roleId],
'test',
),
},
])(
'should not update role for user on project when she is the owner ($name)',
async ({ name, fn }) => {
const project = {
id: `update-users-not-allowed-${name}`,
name: 'New project',
description: 'Blah',
mode: 'open' as const,
defaultStickiness: 'clientId',
};
await projectService.createProject(project, user);

const memberRole = await stores.roleStore.getRoleByName(
RoleName.MEMBER,
);
}).rejects.toThrowError(
new Error('A project must have at least one owner'),
);

await expect(async () => {
await projectService.setRolesForUser(
project.id,
user.id,
[memberRole.id],
'test',
expect(() =>
fn(project.id, memberRole.id, user.id),
).rejects.toThrowError(
new Error('A project must have at least one owner'),
);
}).rejects.toThrowError(
new Error('A project must have at least one owner'),
);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Instead of making 2 assertions, this splits into 2 tests using test.each

@gastonfournier gastonfournier force-pushed the ensure-projects-have-owners branch from d9de330 to b5b4fb9 Compare October 19, 2023 11:47
Base automatically changed from ensure-projects-have-owners to main October 19, 2023 12:15
@gastonfournier gastonfournier deleted the ensure-projects-have-owners-alt branch April 3, 2024 13:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant