Skip to content

Commit e8a6a33

Browse files
committed
test(enterprise): pin owner email update scope
1 parent ab44394 commit e8a6a33

1 file changed

Lines changed: 28 additions & 1 deletion

File tree

apps/sim/lib/billing/enterprise-owner-claim.test.ts

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,12 @@
33
*/
44
import { db } from '@sim/db'
55
import { member, outboxEvent, user, workspace } from '@sim/db/schema'
6-
import { dbChainMockFns, queueTableRows, resetDbChainMock } from '@sim/testing'
6+
import {
7+
dbChainMockFns,
8+
flattenMockConditions,
9+
queueTableRows,
10+
resetDbChainMock,
11+
} from '@sim/testing'
712
import { afterAll, beforeEach, describe, expect, it, vi } from 'vitest'
813

914
const mocks = vi.hoisted(() => ({
@@ -313,6 +318,28 @@ describe('Enterprise future-owner claims', () => {
313318
})
314319
).resolves.toEqual({ success: false, kind: 'email-mismatch' })
315320

321+
const updateConditions = flattenMockConditions(dbChainMockFns.where.mock.calls.at(-1)?.[0])
322+
expect(
323+
updateConditions.some(
324+
(condition) =>
325+
condition.type === 'eq' && condition.left === user.id && condition.right === 'owner-1'
326+
)
327+
).toBe(true)
328+
const emailScope = updateConditions.find((condition) => condition.type === 'or')
329+
const emailConditions = Array.isArray(emailScope?.conditions) ? emailScope.conditions : []
330+
expect(
331+
emailConditions.some(
332+
(condition) =>
333+
condition?.type === 'eq' &&
334+
condition.left === user.normalizedEmail &&
335+
condition.right === request.ownerEmail
336+
)
337+
).toBe(true)
338+
expect(
339+
emailConditions.filter(
340+
(condition) => condition?.type === 'eq' && condition.right === request.ownerEmail
341+
)
342+
).toHaveLength(2)
316343
expect(mocks.createOrganization).not.toHaveBeenCalled()
317344
expect(mocks.enqueue).not.toHaveBeenCalled()
318345
})

0 commit comments

Comments
 (0)