d25d482dc2
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
Publish CLI Package / publish-npm (push) Has been cancelled
Publish Python SDK / publish-pypi (push) Has been cancelled
Publish TypeScript SDK / publish-npm (push) Has been cancelled
81 lines
2.4 KiB
TypeScript
81 lines
2.4 KiB
TypeScript
/**
|
|
* @vitest-environment node
|
|
*/
|
|
import { createMockRequest } from '@sim/testing'
|
|
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
|
|
|
const { mockGetSession, mockGetUserEntityPermissions, mockGetWorkspaceOwnerSubscriptionAccess } =
|
|
vi.hoisted(() => ({
|
|
mockGetSession: vi.fn(),
|
|
mockGetUserEntityPermissions: vi.fn(),
|
|
mockGetWorkspaceOwnerSubscriptionAccess: vi.fn(),
|
|
}))
|
|
|
|
vi.mock('@/lib/auth', () => ({
|
|
auth: { api: { getSession: vi.fn() } },
|
|
getSession: mockGetSession,
|
|
}))
|
|
|
|
vi.mock('@/lib/workspaces/permissions/utils', () => ({
|
|
getUserEntityPermissions: mockGetUserEntityPermissions,
|
|
}))
|
|
|
|
vi.mock('@/lib/billing/core/workspace-access', () => ({
|
|
getWorkspaceOwnerSubscriptionAccess: mockGetWorkspaceOwnerSubscriptionAccess,
|
|
}))
|
|
|
|
import { GET } from '@/app/api/workspaces/[id]/owner-billing/route'
|
|
|
|
const WORKSPACE_ID = 'ws-1'
|
|
|
|
const PAID_ACCESS = {
|
|
plan: 'team_25000',
|
|
status: 'active',
|
|
isPaid: true,
|
|
isPro: false,
|
|
isTeam: true,
|
|
isEnterprise: false,
|
|
isOrgScoped: true,
|
|
organizationId: 'org-1',
|
|
}
|
|
|
|
function buildParams() {
|
|
return { params: Promise.resolve({ id: WORKSPACE_ID }) }
|
|
}
|
|
|
|
async function callGet() {
|
|
const request = createMockRequest('GET')
|
|
const response = await GET(request, buildParams())
|
|
return { status: response.status, body: await response.json() }
|
|
}
|
|
|
|
describe('GET /api/workspaces/[id]/owner-billing', () => {
|
|
beforeEach(() => {
|
|
vi.clearAllMocks()
|
|
mockGetSession.mockResolvedValue({ user: { id: 'u-1' } })
|
|
mockGetUserEntityPermissions.mockResolvedValue('read')
|
|
mockGetWorkspaceOwnerSubscriptionAccess.mockResolvedValue(PAID_ACCESS)
|
|
})
|
|
|
|
it('returns 401 when unauthenticated', async () => {
|
|
mockGetSession.mockResolvedValue(null)
|
|
const { status } = await callGet()
|
|
expect(status).toBe(401)
|
|
expect(mockGetWorkspaceOwnerSubscriptionAccess).not.toHaveBeenCalled()
|
|
})
|
|
|
|
it('returns 404 when the caller has no workspace access', async () => {
|
|
mockGetUserEntityPermissions.mockResolvedValue(null)
|
|
const { status } = await callGet()
|
|
expect(status).toBe(404)
|
|
expect(mockGetWorkspaceOwnerSubscriptionAccess).not.toHaveBeenCalled()
|
|
})
|
|
|
|
it('returns the workspace owner subscription access for a member', async () => {
|
|
const { status, body } = await callGet()
|
|
expect(status).toBe(200)
|
|
expect(body).toEqual(PAID_ACCESS)
|
|
expect(mockGetWorkspaceOwnerSubscriptionAccess).toHaveBeenCalledWith(WORKSPACE_ID)
|
|
})
|
|
})
|