Repository navigation
fix(sim-links): hand off a departing member's links to the successor #9597
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
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
463be58
fix(sim-links): hand off a departing member's links to the successor
waleedlatif1 13c1cd4
fix(sim-links): repair leftover links on account deletion
waleedlatif1 69741c4
fix(sim-links): lock leftover-link organizations before deletion barr…
waleedlatif1 2db7e0f
fix(sim-links): hold the creator's membership while creating a link
waleedlatif1 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
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
101 changes: 101 additions & 0 deletions
101
apps/sim/lib/sim-links/application/create-membership.integration.ts
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,101 @@ | ||
| import { db } from '@sim/db' | ||
| import { member, organization, simLink, user } from '@sim/db/schema' | ||
| import { readTestDatabaseUrl } from '@sim/db/testing/test-infrastructure' | ||
| import { createSessionPrincipal } from '@sim/testing/factories/principal.factory' | ||
| import { createDeferred } from '@sim/testing/helpers/deferred' | ||
| import { featureFlagsMock, featureFlagsMockFns } from '@sim/testing/mocks/feature-flags.mock' | ||
| import { generateId } from '@sim/utils/id' | ||
| import { eq, inArray } from 'drizzle-orm' | ||
| import { afterAll, expect, it, vi } from 'vitest' | ||
| import { removeUserFromOrganization } from '@/lib/billing/organizations/membership' | ||
| import { createSimLink } from '@/lib/sim-links/application/use-cases' | ||
|
|
||
| vi.mock('@/lib/core/config/feature-flags', () => featureFlagsMock) | ||
|
|
||
| readTestDatabaseUrl() | ||
|
|
||
| const ownerId = generateId() | ||
| const creatorId = generateId() | ||
| const organizationId = generateId() | ||
| const creatorMemberId = generateId() | ||
|
|
||
| afterAll(async () => { | ||
| await db.delete(organization).where(eq(organization.id, organizationId)) | ||
| await db.delete(user).where(inArray(user.id, [ownerId, creatorId])) | ||
| }) | ||
|
|
||
| it('refuses a link whose creator is removed after authorization but before the insert', async () => { | ||
| await db.insert(user).values( | ||
| [ownerId, creatorId].map((id) => ({ | ||
| id, | ||
| name: 'Sim link fixture', | ||
| email: `${id}@example.test`, | ||
| emailVerified: true, | ||
| createdAt: new Date(), | ||
| updatedAt: new Date(), | ||
| })) | ||
| ) | ||
| await db.insert(organization).values({ | ||
| id: organizationId, | ||
| name: 'Sim link organization', | ||
| slug: organizationId, | ||
| createdAt: new Date(), | ||
| }) | ||
| await db.insert(member).values([ | ||
| { id: generateId(), organizationId, userId: ownerId, role: 'owner', createdAt: new Date() }, | ||
| { | ||
| id: creatorMemberId, | ||
| organizationId, | ||
| userId: creatorId, | ||
| role: 'member', | ||
| createdAt: new Date(), | ||
| }, | ||
| ]) | ||
|
|
||
| const authorized = createDeferred<void>() | ||
| const proceed = createDeferred<void>() | ||
| featureFlagsMockFns.mockIsFeatureEnabled.mockImplementation(async (flag) => { | ||
| if (flag !== 'sim-links') return false | ||
| authorized.resolve() | ||
| await proceed.promise | ||
| return true | ||
| }) | ||
|
|
||
| const creation = createSimLink.execute({ | ||
| principal: createSessionPrincipal({ userId: creatorId }), | ||
| input: { | ||
| organizationId, | ||
| name: 'handbook', | ||
| url: 'https://example.test/handbook', | ||
| defaultUrl: null, | ||
| description: null, | ||
| unlisted: true, | ||
| restrictEdit: true, | ||
| }, | ||
| }) | ||
| const settled = creation.then( | ||
| () => null, | ||
| (error: unknown) => error | ||
| ) | ||
| await authorized.promise | ||
| expect( | ||
| ( | ||
| await removeUserFromOrganization({ | ||
| organizationId, | ||
| userId: creatorId, | ||
| memberId: creatorMemberId, | ||
| skipBillingLogic: true, | ||
| onError: 'throw', | ||
| }) | ||
| ).success | ||
| ).toBe(true) | ||
| proceed.resolve() | ||
|
|
||
| expect(await settled).toMatchObject({ message: 'Organization not found' }) | ||
| expect( | ||
| await db | ||
| .select({ id: simLink.id }) | ||
| .from(simLink) | ||
| .where(eq(simLink.organizationId, organizationId)) | ||
| ).toEqual([]) | ||
| }) |
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
Oops, something went wrong.
Oops, something went wrong.
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.