-
Notifications
You must be signed in to change notification settings - Fork 453
fix(types,clerk-js): Allow organization admin to leave, if there are more admins #1498
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| '@clerk/clerk-js': patch | ||
| --- | ||
|
|
||
| In `<OrganizationProfile />` component, allow an admin to leave the current organization if there are more admins present. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| import type { MembershipRole, OrganizationMembershipResource, OrganizationResource } from '@clerk/types'; | ||
| import { jest } from '@jest/globals'; | ||
|
|
||
| type FakeMemberParams = { | ||
| id: string; | ||
| orgId: string; | ||
| role?: MembershipRole; | ||
| identifier?: string; | ||
| firstName?: string; | ||
| lastName?: string; | ||
| profileImageUrl?: string; | ||
| imageUrl?: string; | ||
| createdAt?: Date; | ||
| }; | ||
|
|
||
| export const createFakeMember = (params: FakeMemberParams): OrganizationMembershipResource => { | ||
| return { | ||
| destroy: jest.fn() as any, | ||
| update: jest.fn() as any, | ||
| organization: { id: params.orgId } as any as OrganizationResource, | ||
| id: params.id, | ||
| role: params?.role || 'admin', | ||
| createdAt: params?.createdAt || new Date(), | ||
| updatedAt: new Date(), | ||
| publicMetadata: {}, | ||
| publicUserData: { | ||
| userId: params.id, | ||
| identifier: params?.identifier || 'test_user', | ||
| firstName: params?.firstName || 'test_firstName', | ||
| lastName: params?.lastName || 'test_lastName', | ||
| profileImageUrl: params?.profileImageUrl || '', | ||
| imageUrl: params?.imageUrl || '', | ||
| }, | ||
| } as any; | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| import type { ClerkOptions, ClientJSON, EnvironmentJSON, LoadedClerk } from '@clerk/types'; | ||
| import { jest } from '@jest/globals'; | ||
| import React from 'react'; | ||
| import { SWRConfig } from 'swr'; | ||
|
|
||
| import { default as ClerkCtor } from '../../../core/clerk'; | ||
| import { Client, Environment } from '../../../core/resources'; | ||
|
|
@@ -84,23 +85,25 @@ const unboundCreateFixtures = <N extends UnpackContext<typeof ComponentContext>[ | |
| const MockClerkProvider = (props: any) => { | ||
| const { children } = props; | ||
| return ( | ||
| <CoreClerkContextWrapper clerk={clerkMock}> | ||
| <EnvironmentProvider value={environmentMock}> | ||
| <OptionsProvider value={optionsMock}> | ||
| <RouteContext.Provider value={routerMock}> | ||
| <AppearanceProvider appearanceKey={'signIn'}> | ||
| <FlowMetadataProvider flow={componentName as any}> | ||
| <InternalThemeProvider> | ||
| <ComponentContext.Provider value={{ ...componentContextProps, componentName }}> | ||
| {children} | ||
| </ComponentContext.Provider> | ||
| </InternalThemeProvider> | ||
| </FlowMetadataProvider> | ||
| </AppearanceProvider> | ||
| </RouteContext.Provider> | ||
| </OptionsProvider> | ||
| </EnvironmentProvider> | ||
| </CoreClerkContextWrapper> | ||
| <SWRConfig value={{ provider: () => new Map(), dedupingInterval: 0 }}> | ||
|
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. We were forced to wrap our test fixture with a SWR config, as swr uses a global cache for tests and there is no easy way to clear it before every test. This lead to use the same initial response when mocking a method
Contributor
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. 💯 All tests seem to pass correctly, so it is good news this does not mess with anything else. |
||
| <CoreClerkContextWrapper clerk={clerkMock}> | ||
| <EnvironmentProvider value={environmentMock}> | ||
| <OptionsProvider value={optionsMock}> | ||
| <RouteContext.Provider value={routerMock}> | ||
| <AppearanceProvider appearanceKey={'signIn'}> | ||
| <FlowMetadataProvider flow={componentName as any}> | ||
| <InternalThemeProvider> | ||
| <ComponentContext.Provider value={{ ...componentContextProps, componentName }}> | ||
| {children} | ||
| </ComponentContext.Provider> | ||
| </InternalThemeProvider> | ||
| </FlowMetadataProvider> | ||
| </AppearanceProvider> | ||
| </RouteContext.Provider> | ||
| </OptionsProvider> | ||
| </EnvironmentProvider> | ||
| </CoreClerkContextWrapper> | ||
| </SWRConfig> | ||
| ); | ||
| }; | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -51,7 +51,9 @@ export interface OrganizationResource extends ClerkResource { | |
| setLogo: (params: SetOrganizationLogoParams) => Promise<OrganizationResource>; | ||
| } | ||
|
|
||
| export type GetMembershipsParams = ClerkPaginationParams; | ||
| export type GetMembershipsParams = { | ||
| role?: MembershipRole[]; | ||
|
Contributor
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. Why is this optional?
Contributor
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. You don't have to specify the role, If it is left empty or undefined it will return memberships of any role |
||
| } & ClerkPaginationParams; | ||
|
|
||
| export type GetPendingInvitationsParams = ClerkPaginationParams; | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if this is the right place to place a common test helper for this component
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can see that this helper is specific to this component, so it's a good place I guess.