d25d482dc2
Publish CLI Package / publish-npm (push) Waiting to run
Publish Python SDK / publish-pypi (push) Waiting to run
Publish TypeScript SDK / publish-npm (push) Waiting to run
CI / Migrate Dev DB (push) Has been skipped
CI / Detect Version (push) Has been cancelled
CI / Migrate DB (push) Has been cancelled
CI / Build Dev ECR (./docker/app.Dockerfile, ECR_APP) (push) Has been cancelled
CI / Build Dev ECR (./docker/db.Dockerfile, ECR_MIGRATIONS) (push) Has been cancelled
CI / Build Dev ECR (./docker/pii.Dockerfile, ECR_PII) (push) Has been cancelled
CI / Build Dev ECR (./docker/realtime.Dockerfile, ECR_REALTIME) (push) Has been cancelled
CI / Deploy Trigger.dev (Dev) (push) Has been cancelled
CI / Build AMD64 (./docker/app.Dockerfile, ECR_APP, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Build AMD64 (./docker/db.Dockerfile, ECR_MIGRATIONS, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build AMD64 (./docker/pii.Dockerfile, ECR_PII, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build AMD64 (./docker/realtime.Dockerfile, ECR_REALTIME, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/app.Dockerfile, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/db.Dockerfile, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/pii.Dockerfile, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/realtime.Dockerfile, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Check Docs Changes (push) Has been cancelled
CI / Process Docs (push) Has been cancelled
CI / Create GitHub Release (push) Has been cancelled
CI / Test and Build (push) Has been cancelled
74 lines
2.2 KiB
TypeScript
74 lines
2.2 KiB
TypeScript
/**
|
|
* @vitest-environment node
|
|
*/
|
|
import { dbChainMock } from '@sim/testing'
|
|
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
|
|
|
const {
|
|
mockCreateOrganizationWithOwner,
|
|
mockAttachOwnedWorkspacesToOrganization,
|
|
mockGetOrganizationIdForSubscriptionReference,
|
|
} = vi.hoisted(() => ({
|
|
mockCreateOrganizationWithOwner: vi.fn(),
|
|
mockAttachOwnedWorkspacesToOrganization: vi.fn(),
|
|
mockGetOrganizationIdForSubscriptionReference: vi.fn(),
|
|
}))
|
|
|
|
vi.mock('@sim/db', () => dbChainMock)
|
|
|
|
vi.mock('@/lib/billing/core/billing', () => ({
|
|
getPlanPricing: vi.fn(),
|
|
}))
|
|
|
|
vi.mock('@/lib/billing/core/subscription', () => ({
|
|
getOrganizationIdForSubscriptionReference: mockGetOrganizationIdForSubscriptionReference,
|
|
}))
|
|
|
|
vi.mock('@/lib/billing/core/usage', () => ({
|
|
syncUsageLimitsFromSubscription: vi.fn(),
|
|
}))
|
|
|
|
vi.mock('@/lib/billing/plan-helpers', () => ({
|
|
isOrgPlan: (plan: string) => plan === 'team' || plan === 'enterprise',
|
|
isTeam: (plan: string) => plan === 'team',
|
|
}))
|
|
|
|
vi.mock('@/lib/billing/organizations/create-organization', () => ({
|
|
createOrganizationWithOwner: mockCreateOrganizationWithOwner,
|
|
}))
|
|
|
|
vi.mock('@/lib/workspaces/organization-workspaces', () => ({
|
|
attachOwnedWorkspacesToOrganization: mockAttachOwnedWorkspacesToOrganization,
|
|
}))
|
|
|
|
import { ensureOrganizationForTeamSubscription } from '@/lib/billing/organization'
|
|
|
|
describe('ensureOrganizationForTeamSubscription', () => {
|
|
beforeEach(() => {
|
|
vi.clearAllMocks()
|
|
mockGetOrganizationIdForSubscriptionReference.mockResolvedValue(null)
|
|
})
|
|
|
|
it('treats existing legacy organization ids as organization references', async () => {
|
|
mockGetOrganizationIdForSubscriptionReference.mockResolvedValue('legacy-org-id')
|
|
|
|
const result = await ensureOrganizationForTeamSubscription({
|
|
id: 'sub-1',
|
|
plan: 'team',
|
|
referenceId: 'legacy-org-id',
|
|
status: 'active',
|
|
seats: 5,
|
|
})
|
|
|
|
expect(result).toEqual({
|
|
id: 'sub-1',
|
|
plan: 'team',
|
|
referenceId: 'legacy-org-id',
|
|
status: 'active',
|
|
seats: 5,
|
|
})
|
|
expect(mockCreateOrganizationWithOwner).not.toHaveBeenCalled()
|
|
expect(mockAttachOwnedWorkspacesToOrganization).not.toHaveBeenCalled()
|
|
})
|
|
})
|