Skip to content

Commit d6b7a5d

Browse files
committed
test(projects): align transfer mocks with workspace membership
1 parent 9a29636 commit d6b7a5d

3 files changed

Lines changed: 12 additions & 14 deletions

File tree

‎apps/sim/lib/billing/organizations/lock-order.test.ts‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -181,11 +181,13 @@ describe('workspace payer-change transaction lock ordering', () => {
181181
it('locks nonzero workspaces before join billing or aggregate payer changes', async () => {
182182
const ops: Array<{ op: 'lock' | 'payer-transfer' | 'update'; table: unknown }> = []
183183
let memberSelectCount = 0
184-
const rowsForTable = (table: unknown): unknown[] => {
184+
const rowsForTable = (table: unknown, fields?: Record<string, unknown>): unknown[] => {
185185
if (table === workspace) {
186+
if (fields?.id === workspace.projectId) return [{ id: null }]
186187
return [
187188
{
188189
id: 'workspace-1',
190+
projectId: null,
189191
billedAccountUserId: 'user-1',
190192
organizationId: null,
191193
storageUsedBytes: 128,
@@ -203,7 +205,7 @@ describe('workspace payer-change transaction lock ordering', () => {
203205
if (table === userStats) return [{ currentPeriodCost: '5' }]
204206
return []
205207
}
206-
const select = () => {
208+
const select = (fields?: Record<string, unknown>) => {
207209
let table: unknown
208210
const chain = {
209211
from(source: unknown) {
@@ -220,9 +222,9 @@ describe('workspace payer-change transaction lock ordering', () => {
220222
ops.push({ op: 'lock', table })
221223
return chain
222224
},
223-
limit: async () => rowsForTable(table),
225+
limit: async () => rowsForTable(table, fields),
224226
then(resolve: (rows: unknown[]) => unknown, reject: (error: unknown) => unknown) {
225-
return Promise.resolve(rowsForTable(table)).then(resolve, reject)
227+
return Promise.resolve(rowsForTable(table, fields)).then(resolve, reject)
226228
},
227229
}
228230
return chain

‎apps/sim/lib/workspaces/admin-move.test.ts‎

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -191,20 +191,13 @@ const destination = {
191191
}
192192

193193
/**
194-
* The move flow reads the workspace three times in order: the optimistic
195-
* pre-transaction organization read that decides which organizations to lock,
196-
* the locked classification row, and the final summary reload. The workspace
197-
* queue therefore gets one set per read, in that order.
198-
*
199-
* Keep this comment in step with the reads — a stale count silently shifts
200-
* every later queue entry onto the wrong statement, which surfaces as an
201-
* unrelated "could not be reloaded" failure rather than a queueing error.
202-
*
203-
* All invitation/grant/permission selects resolve the queue-less empty default.
194+
* Queues the optimistic scope, locked workspace, optional unassigned Project projection,
195+
* and summary reads. An already completed move skips the Project transfer.
204196
*/
205197
function queueMoveSelects(workspaceRow: Record<string, unknown>) {
206198
queueTableRows(workspace, [workspaceRow])
207199
queueTableRows(workspace, [workspaceRow])
200+
if (workspaceRow.organizationId !== destination.id) queueTableRows(workspace, [{ id: null }])
208201
queueTableRows(workspace, [workspaceRow])
209202
queueTableRows(organization, [destination])
210203
}
@@ -670,6 +663,7 @@ describe('moveWorkspaceToOrganization retries', () => {
670663
queueTableRows(workspace, [organizationWorkspace])
671664
queueTableRows(workspace, [{ ...organizationWorkspace, organizationId: 'org-moved' }])
672665
queueTableRows(workspace, [{ ...organizationWorkspace, organizationId: 'org-moved' }])
666+
queueTableRows(workspace, [{ id: null }])
673667
queueTableRows(workspace, [{ ...organizationWorkspace, organizationId: 'org-moved' }])
674668
queueTableRows(organization, [destination])
675669

‎apps/sim/lib/workspaces/organization-workspaces.test.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ describe('organization workspace helpers', () => {
191191
{ id: 'ws-1', ownerId: 'creator-1', billedAccountUserId: 'old-owner' },
192192
])
193193
queueTableRows(schemaMock.invitation, [{ id: 'invite-pending' }, { id: 'invite-terminal' }])
194+
queueTableRows(schemaMock.workspace, [{ id: null }])
194195
queueTableRows(schemaMock.workspace, [{ id: 'ws-1' }])
195196

196197
const result =
@@ -328,6 +329,7 @@ describe('organization workspace helpers', () => {
328329
{ id: 'ws-2', ownerId: 'creator-2', billedAccountUserId: 'old-owner' },
329330
])
330331
queueTableRows(schemaMock.invitation, [{ id: 'invite-2' }])
332+
queueTableRows(schemaMock.workspace, [{ id: null }])
331333
queueTableRows(schemaMock.workspace, [{ id: 'ws-2' }])
332334

333335
const result = await detachOrganizationWorkspaces('org-1')

0 commit comments

Comments
 (0)