-
Notifications
You must be signed in to change notification settings - Fork 320
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(vue,shared): Move
getCurrentOrganizationMembership
helper to …
…shared package (#5168)
- Loading branch information
1 parent
74868fa
commit 92d17d7
Showing
6 changed files
with
57 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,6 @@ | ||
--- | ||
"@clerk/shared": patch | ||
"@clerk/vue": patch | ||
--- | ||
|
||
Previously, the `getCurrentOrganizationMembership()` function was duplicated in both `@clerk/vue` and `@clerk/shared/react`. This change moves the function to `@clerk/shared/organization`. |
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 |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import type { OrganizationMembershipResource } from '@clerk/types'; | ||
|
||
import { getCurrentOrganizationMembership } from '../organization'; | ||
|
||
describe('getCurrentOrganizationMembership', () => { | ||
const mockMemberships: OrganizationMembershipResource[] = [ | ||
{ | ||
id: 'mem_1', | ||
organization: { id: 'org_1' }, | ||
} as OrganizationMembershipResource, | ||
{ | ||
id: 'mem_2', | ||
organization: { id: 'org_2' }, | ||
} as OrganizationMembershipResource, | ||
]; | ||
|
||
it('returns the correct membership for a given organization ID', () => { | ||
const result = getCurrentOrganizationMembership(mockMemberships, 'org_1'); | ||
expect(result).toBe(mockMemberships[0]); | ||
}); | ||
|
||
it('returns undefined when organization ID is not found', () => { | ||
const result = getCurrentOrganizationMembership(mockMemberships, 'org_nonexistent'); | ||
expect(result).toBeUndefined(); | ||
}); | ||
|
||
it('returns undefined when memberships array is empty', () => { | ||
const result = getCurrentOrganizationMembership([], 'org_1'); | ||
expect(result).toBeUndefined(); | ||
}); | ||
}); |
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,16 @@ | ||
import type { OrganizationMembershipResource } from '@clerk/types'; | ||
|
||
/** | ||
* Finds the organization membership for a given organization ID from a list of memberships | ||
* @param organizationMemberships - Array of organization memberships to search through | ||
* @param organizationId - ID of the organization to find the membership for | ||
* @returns The matching organization membership or undefined if not found | ||
*/ | ||
export function getCurrentOrganizationMembership( | ||
organizationMemberships: OrganizationMembershipResource[], | ||
organizationId: string, | ||
) { | ||
return organizationMemberships.find( | ||
organizationMembership => organizationMembership.organization.id === organizationId, | ||
); | ||
} |
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