-
Notifications
You must be signed in to change notification settings - Fork 408
feat(clerk-js,types): Supports default role on OrganizationProfile invitations
#4210
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
LauraBeatris
merged 8 commits into
main
from
laura/orgs-211-set-default-role-on-organizationprofile
Sep 24, 2024
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
7cb4a3c
Add `default_role` property to `OrganizationSettingsResource`
LauraBeatris 3362126
Determine default role for organization
LauraBeatris 7bf375d
Fix types and resource instance
LauraBeatris ef7ba8d
Add changeset
LauraBeatris ed4ba2f
Provide initial value to `useFormControl`
LauraBeatris d9254d2
Add test TODO
LauraBeatris 93fd37c
Implement tests
LauraBeatris 8212581
Fixes initial value re-render when options get fetched
LauraBeatris File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,6 @@ | ||
| --- | ||
| "@clerk/clerk-js": patch | ||
| "@clerk/types": patch | ||
| --- | ||
|
|
||
| Supports default role on `OrganizationProfile` invitations. When inviting a member, the default role will be automatically selected, otherwise it falls back to the only available role. |
This file contains hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| import type { OrganizationInvitationResource } from '@clerk/types'; | ||
| import { describe } from '@jest/globals'; | ||
| import { waitFor } from '@testing-library/dom'; | ||
| import React from 'react'; | ||
|
|
||
| import { ClerkAPIResponseError } from '../../../../core/resources'; | ||
| import { render } from '../../../../testUtils'; | ||
|
|
@@ -41,7 +42,156 @@ describe('InviteMembersPage', () => { | |
| getByText('Enter or paste one or more email addresses, separated by spaces or commas.'); | ||
| }); | ||
|
|
||
| describe('Submitting', () => { | ||
| describe('with default role', () => { | ||
| it("initializes with the organization's default role", async () => { | ||
| const defaultRole = 'mydefaultrole'; | ||
|
|
||
| const { wrapper, fixtures } = await createFixtures(f => { | ||
| f.withOrganizations(); | ||
| f.withOrganizationDomains(undefined, defaultRole); | ||
| f.withUser({ | ||
| email_addresses: ['test@clerk.com'], | ||
| organization_memberships: [{ name: 'Org1', role: 'admin' }], | ||
| }); | ||
| }); | ||
|
|
||
| fixtures.clerk.organization?.getRoles.mockResolvedValue({ | ||
| total_count: 2, | ||
| data: [ | ||
| { | ||
| pathRoot: '', | ||
| reload: jest.fn(), | ||
| id: 'member', | ||
| key: 'member', | ||
| name: 'member', | ||
| description: '', | ||
| permissions: [], | ||
| createdAt: new Date(), | ||
| updatedAt: new Date(), | ||
| }, | ||
| { | ||
| pathRoot: '', | ||
| reload: jest.fn(), | ||
| id: 'admin', | ||
| key: 'admin', | ||
| name: 'Admin', | ||
| description: '', | ||
| permissions: [], | ||
| createdAt: new Date(), | ||
| updatedAt: new Date(), | ||
| }, | ||
| { | ||
| pathRoot: '', | ||
| reload: jest.fn(), | ||
| id: defaultRole, | ||
| key: defaultRole, | ||
| name: defaultRole, | ||
| description: '', | ||
| permissions: [], | ||
| createdAt: new Date(), | ||
| updatedAt: new Date(), | ||
| }, | ||
| ], | ||
| }); | ||
|
|
||
| fixtures.clerk.organization?.inviteMembers.mockResolvedValueOnce([{}] as OrganizationInvitationResource[]); | ||
| const { getByRole, userEvent, getByTestId } = render( | ||
| <Action.Root> | ||
| <InviteMembersScreen /> | ||
| </Action.Root>, | ||
| { wrapper }, | ||
| ); | ||
| await userEvent.type(getByTestId('tag-input'), 'test+1@clerk.com,'); | ||
| await userEvent.click(getByRole('button', { name: /mydefaultrole/i })); | ||
| }); | ||
|
|
||
| it("initializes if there's only one role available", async () => { | ||
| const { wrapper, fixtures } = await createFixtures(f => { | ||
| f.withOrganizations(); | ||
| f.withUser({ | ||
| email_addresses: ['test@clerk.com'], | ||
| organization_memberships: [{ name: 'Org1', role: 'admin' }], | ||
| }); | ||
| }); | ||
|
|
||
| fixtures.clerk.organization?.getRoles.mockResolvedValue({ | ||
| total_count: 1, | ||
| data: [ | ||
| { | ||
| pathRoot: '', | ||
| reload: jest.fn(), | ||
| id: 'member', | ||
| key: 'member', | ||
| name: 'member', | ||
| description: '', | ||
| permissions: [], | ||
| createdAt: new Date(), | ||
| updatedAt: new Date(), | ||
| }, | ||
| ], | ||
| }); | ||
|
|
||
| fixtures.clerk.organization?.inviteMembers.mockResolvedValueOnce([{}] as OrganizationInvitationResource[]); | ||
| const { getByRole, userEvent, getByTestId } = render( | ||
| <Action.Root> | ||
| <InviteMembersScreen /> | ||
| </Action.Root>, | ||
| { wrapper }, | ||
| ); | ||
| await userEvent.type(getByTestId('tag-input'), 'test+1@clerk.com,'); | ||
| await waitFor(() => expect(getByRole('button', { name: /member/i })).toBeInTheDocument()); | ||
| }); | ||
|
|
||
| it("does not initialize if there's neither a default role nor a unique role", async () => { | ||
| const { wrapper, fixtures } = await createFixtures(f => { | ||
| f.withOrganizations(); | ||
| f.withUser({ | ||
| email_addresses: ['test@clerk.com'], | ||
| organization_memberships: [{ name: 'Org1', role: 'admin' }], | ||
| }); | ||
| }); | ||
|
|
||
| fixtures.clerk.organization?.getRoles.mockResolvedValue({ | ||
| total_count: 1, | ||
| data: [ | ||
| { | ||
| pathRoot: '', | ||
| reload: jest.fn(), | ||
| id: 'member', | ||
| key: 'member', | ||
| name: 'member', | ||
| description: '', | ||
| permissions: [], | ||
| createdAt: new Date(), | ||
| updatedAt: new Date(), | ||
| }, | ||
| { | ||
| pathRoot: '', | ||
| reload: jest.fn(), | ||
| id: 'admin', | ||
| key: 'admin', | ||
| name: 'admin', | ||
| description: '', | ||
| permissions: [], | ||
| createdAt: new Date(), | ||
| updatedAt: new Date(), | ||
| }, | ||
| ], | ||
| }); | ||
|
|
||
| fixtures.clerk.organization?.inviteMembers.mockResolvedValueOnce([{}] as OrganizationInvitationResource[]); | ||
| const { getByRole, userEvent, getByTestId } = render( | ||
| <Action.Root> | ||
| <InviteMembersScreen /> | ||
| </Action.Root>, | ||
| { wrapper }, | ||
| ); | ||
| await userEvent.type(getByTestId('tag-input'), 'test+1@clerk.com,'); | ||
| await waitFor(() => expect(getByRole('button', { name: /select role/i })).toBeInTheDocument()); | ||
| }); | ||
| }); | ||
|
|
||
| describe('when submitting', () => { | ||
| it('keeps the Send button disabled until a role is selected and one or more email has been entered', async () => { | ||
| const { wrapper, fixtures } = await createFixtures(f => { | ||
| f.withOrganizations(); | ||
|
|
@@ -65,6 +215,17 @@ describe('InviteMembersPage', () => { | |
| createdAt: new Date(), | ||
| updatedAt: new Date(), | ||
| }, | ||
| { | ||
| pathRoot: '', | ||
| reload: jest.fn(), | ||
| id: 'admin', | ||
| key: 'admin', | ||
| name: 'Admin', | ||
| description: '', | ||
| permissions: [], | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Those tests were mocking with a single role, therefore initiating the field with that one instead and the assertion for "Select role" started to fail. |
||
| createdAt: new Date(), | ||
| updatedAt: new Date(), | ||
| }, | ||
| ], | ||
| }); | ||
|
|
||
|
|
@@ -108,6 +269,17 @@ describe('InviteMembersPage', () => { | |
| createdAt: new Date(), | ||
| updatedAt: new Date(), | ||
| }, | ||
| { | ||
| pathRoot: '', | ||
| reload: jest.fn(), | ||
| id: 'admin', | ||
| key: 'admin', | ||
| name: 'Admin', | ||
| description: '', | ||
| permissions: [], | ||
| createdAt: new Date(), | ||
| updatedAt: new Date(), | ||
| }, | ||
| ], | ||
| }); | ||
|
|
||
|
|
@@ -154,6 +326,17 @@ describe('InviteMembersPage', () => { | |
| createdAt: new Date(), | ||
| updatedAt: new Date(), | ||
| }, | ||
| { | ||
| pathRoot: '', | ||
| reload: jest.fn(), | ||
| id: 'admin', | ||
| key: 'admin', | ||
| name: 'Admin', | ||
| description: '', | ||
| permissions: [], | ||
| createdAt: new Date(), | ||
| updatedAt: new Date(), | ||
| }, | ||
| ], | ||
| }); | ||
|
|
||
|
|
@@ -259,6 +442,17 @@ describe('InviteMembersPage', () => { | |
| createdAt: new Date(), | ||
| updatedAt: new Date(), | ||
| }, | ||
| { | ||
| pathRoot: '', | ||
| reload: jest.fn(), | ||
| id: 'admin', | ||
| key: 'admin', | ||
| name: 'Admin', | ||
| description: '', | ||
| permissions: [], | ||
| createdAt: new Date(), | ||
| updatedAt: new Date(), | ||
| }, | ||
| ], | ||
| }); | ||
|
|
||
|
|
@@ -318,6 +512,17 @@ describe('InviteMembersPage', () => { | |
| createdAt: new Date(), | ||
| updatedAt: new Date(), | ||
| }, | ||
| { | ||
| pathRoot: '', | ||
| reload: jest.fn(), | ||
| id: 'admin', | ||
| key: 'admin', | ||
| name: 'Admin', | ||
| description: '', | ||
| permissions: [], | ||
| createdAt: new Date(), | ||
| updatedAt: new Date(), | ||
| }, | ||
| ], | ||
| }); | ||
|
|
||
|
|
@@ -373,6 +578,17 @@ describe('InviteMembersPage', () => { | |
| createdAt: new Date(), | ||
| updatedAt: new Date(), | ||
| }, | ||
| { | ||
| pathRoot: '', | ||
| reload: jest.fn(), | ||
| id: 'admin', | ||
| key: 'admin', | ||
| name: 'Admin', | ||
| description: '', | ||
| permissions: [], | ||
| createdAt: new Date(), | ||
| updatedAt: new Date(), | ||
| }, | ||
| ], | ||
| }); | ||
|
|
||
|
|
||
This file contains hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.