Skip to content

Commit

Permalink
test(clerk-js): Remove legacy roles fallback (#2387)
Browse files Browse the repository at this point in the history
* test(clerk-js): Remove legacy roles fallback

* test(clerk-js): Remove legacy roles fallback
  • Loading branch information
panteliselef authored Dec 18, 2023
1 parent 35f406e commit c64ae68
Show file tree
Hide file tree
Showing 3 changed files with 153 additions and 13 deletions.
2 changes: 2 additions & 0 deletions .changeset/perfect-ants-joke.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
---
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,23 @@ describe('InviteMembersPage', () => {
});
});

fixtures.clerk.organization?.getRoles.mockRejectedValue(null);
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(),
},
],
});

const { getByText, getByRole, userEvent, getByTestId } = render(<InviteMembersPage />, { wrapper });
expect(getByRole('button', { name: 'Send invitations' })).toBeDisabled();

Expand All @@ -58,18 +74,34 @@ describe('InviteMembersPage', () => {
});
});

fixtures.clerk.organization?.getRoles.mockRejectedValue(null);
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(),
},
],
});

fixtures.clerk.organization?.inviteMembers.mockResolvedValueOnce([{}] as OrganizationInvitationResource[]);
const { getByRole, userEvent, getByTestId, getByText } = render(<InviteMembersPage />, { wrapper });
await userEvent.type(getByTestId('tag-input'), 'test+1@clerk.com,');
await userEvent.click(getByRole('button', { name: 'Select an option' }));
await userEvent.click(getByText('Member'));
await userEvent.click(getByText(/^member$/i));
await userEvent.click(getByRole('button', { name: 'Send invitations' }));

await waitFor(() => {
expect(fixtures.clerk.organization?.inviteMembers).toHaveBeenCalledWith({
emailAddresses: ['test+1@clerk.com'],
role: 'basic_member' as MembershipRole,
role: 'member' as MembershipRole,
});
});
});
Expand Down Expand Up @@ -123,21 +155,37 @@ describe('InviteMembersPage', () => {
});
});

fixtures.clerk.organization?.getRoles.mockRejectedValue(null);
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(),
},
],
});

fixtures.clerk.organization?.inviteMembers.mockResolvedValueOnce([{}] as OrganizationInvitationResource[]);
const { getByRole, userEvent, getByTestId, getByText } = render(<InviteMembersPage />, { wrapper });
await userEvent.type(
getByTestId('tag-input'),
'test+1@clerk.com,test+2@clerk.com,test+3@clerk.com,test+4@clerk.com,',
);
await userEvent.click(getByRole('button', { name: 'Select an option' }));
await userEvent.click(getByText('Member'));
await userEvent.click(getByText(/^member$/i));
await userEvent.click(getByRole('button', { name: 'Send invitations' }));

await waitFor(() => {
expect(fixtures.clerk.organization?.inviteMembers).toHaveBeenCalledWith({
emailAddresses: ['test+1@clerk.com', 'test+2@clerk.com', 'test+3@clerk.com', 'test+4@clerk.com'],
role: 'basic_member' as MembershipRole,
role: 'member' as MembershipRole,
});
});
});
Expand All @@ -151,7 +199,23 @@ describe('InviteMembersPage', () => {
});
});

fixtures.clerk.organization?.getRoles.mockRejectedValue(null);
fixtures.clerk.organization?.getRoles.mockResolvedValue({
total_count: 2,
data: [
{
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, getByText, getByTestId } = render(<InviteMembersPage />, { wrapper });
await userEvent.type(getByTestId('tag-input'), 'test+1@clerk.com,');
Expand All @@ -175,7 +239,23 @@ describe('InviteMembersPage', () => {
});
});

fixtures.clerk.organization?.getRoles.mockRejectedValue(null);
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(),
},
],
});

fixtures.clerk.organization?.inviteMembers.mockRejectedValueOnce(
new ClerkAPIResponseError('Error', {
data: [
Expand Down Expand Up @@ -213,7 +293,23 @@ describe('InviteMembersPage', () => {
});
});

fixtures.clerk.organization?.getRoles.mockRejectedValue(null);
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(),
},
],
});

fixtures.clerk.organization?.inviteMembers.mockRejectedValueOnce(
new ClerkAPIResponseError('Error', {
data: [
Expand Down Expand Up @@ -247,7 +343,23 @@ describe('InviteMembersPage', () => {
});
});

fixtures.clerk.organization?.getRoles.mockRejectedValue(null);
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(),
},
],
});

fixtures.clerk.organization?.inviteMembers.mockRejectedValueOnce(
new ClerkAPIResponseError('Error', {
data: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ describe('OrganizationMembers', () => {
createFakeMember({
id: '2',
orgId: '1',
role: 'basic_member',
role: 'member',
identifier: 'test_user2',
firstName: 'First2',
lastName: 'Last2',
Expand Down Expand Up @@ -172,7 +172,33 @@ describe('OrganizationMembers', () => {
}),
);

fixtures.clerk.organization?.getRoles.mockRejectedValue(null);
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(),
},
],
});

const { container, queryByText, queryAllByRole } = render(<OrganizationMembers />, { wrapper });

Expand Down

0 comments on commit c64ae68

Please sign in to comment.