-
Notifications
You must be signed in to change notification settings - Fork 279
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(clerk-js): Disable role toggle in <OrganizationMembers />, if las…
…t admin (#1721)
- Loading branch information
1 parent
75be1d6
commit 23c0739
Showing
3 changed files
with
103 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@clerk/clerk-js': patch | ||
--- | ||
|
||
Disable role selection for the last admin in OrganizationProfile |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -111,6 +111,15 @@ describe('OrganizationMembers', () => { | |
lastName: 'Last2', | ||
createdAt: new Date('2022-01-01'), | ||
}), | ||
createFakeMember({ | ||
id: '3', | ||
orgId: '1', | ||
role: 'admin', | ||
identifier: 'test_user3', | ||
firstName: 'First3', | ||
lastName: 'Last3', | ||
createdAt: new Date('2022-01-01'), | ||
}), | ||
]; | ||
const { wrapper, fixtures } = await createFixtures(f => { | ||
f.withOrganizations(); | ||
|
@@ -120,17 +129,74 @@ describe('OrganizationMembers', () => { | |
}); | ||
}); | ||
|
||
fixtures.clerk.organization?.getMemberships.mockReturnValue(Promise.resolve(membersList)); | ||
const { queryByText } = render(<OrganizationMembers />, { wrapper }); | ||
expect(fixtures.clerk.organization?.getMemberships).toHaveBeenCalled(); | ||
expect(fixtures.clerk.organization?.getPendingInvitations).not.toHaveBeenCalled(); | ||
expect(fixtures.clerk.organization?.getMembershipRequests).not.toHaveBeenCalled(); | ||
expect(queryByText('test_user1')).toBeDefined(); | ||
expect(queryByText('First1 Last1')).toBeDefined(); | ||
expect(queryByText('Admin')).toBeDefined(); | ||
expect(queryByText('test_user2')).toBeDefined(); | ||
expect(queryByText('First2 Last2')).toBeDefined(); | ||
expect(queryByText('Member')).toBeDefined(); | ||
fixtures.clerk.organization?.getMemberships.mockReturnValueOnce( | ||
Promise.resolve({ | ||
data: [], | ||
total_count: 2, | ||
}), | ||
); | ||
|
||
fixtures.clerk.organization?.getMemberships.mockReturnValueOnce(Promise.resolve(membersList)); | ||
|
||
const { queryByText, queryAllByRole } = render(<OrganizationMembers />, { wrapper }); | ||
|
||
await waitFor(() => { | ||
expect(fixtures.clerk.organization?.getMemberships).toHaveBeenCalled(); | ||
expect(fixtures.clerk.organization?.getPendingInvitations).not.toHaveBeenCalled(); | ||
expect(fixtures.clerk.organization?.getMembershipRequests).not.toHaveBeenCalled(); | ||
expect(queryByText('test_user1')).toBeInTheDocument(); | ||
expect(queryByText('First1 Last1')).toBeInTheDocument(); | ||
const buttons = queryAllByRole('button', { name: 'Admin' }); | ||
buttons.forEach(button => expect(button).not.toBeDisabled()); | ||
expect(queryByText('test_user2')).toBeInTheDocument(); | ||
expect(queryByText('First2 Last2')).toBeInTheDocument(); | ||
expect(queryByText('Member')).toBeInTheDocument(); | ||
}); | ||
}); | ||
|
||
it('Last admin cannot change to member', async () => { | ||
const membersList: OrganizationMembershipResource[] = [ | ||
createFakeMember({ | ||
id: '1', | ||
orgId: '1', | ||
role: 'admin', | ||
identifier: 'test_user1', | ||
firstName: 'First1', | ||
lastName: 'Last1', | ||
createdAt: new Date('2022-01-01'), | ||
}), | ||
createFakeMember({ | ||
id: '2', | ||
orgId: '1', | ||
role: 'basic_member', | ||
identifier: 'test_user2', | ||
firstName: 'First2', | ||
lastName: 'Last2', | ||
createdAt: new Date('2022-01-01'), | ||
}), | ||
]; | ||
const { wrapper, fixtures } = await createFixtures(f => { | ||
f.withOrganizations(); | ||
f.withUser({ | ||
email_addresses: ['[email protected]'], | ||
organization_memberships: [{ name: 'Org1', id: '1', role: 'admin' }], | ||
}); | ||
}); | ||
|
||
fixtures.clerk.organization?.getMemberships.mockReturnValueOnce( | ||
Promise.resolve({ | ||
data: [], | ||
total_count: 0, | ||
}), | ||
); | ||
|
||
fixtures.clerk.organization?.getMemberships.mockReturnValueOnce(Promise.resolve(membersList)); | ||
|
||
const { queryByRole } = render(<OrganizationMembers />, { wrapper }); | ||
|
||
await waitFor(() => { | ||
expect(queryByRole('button', { name: 'Admin' })).toBeDisabled(); | ||
}); | ||
}); | ||
|
||
it('displays counter in requests tab', async () => { | ||
|