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
85 lines
2.5 KiB
TypeScript
85 lines
2.5 KiB
TypeScript
/**
|
|
* @vitest-environment node
|
|
*/
|
|
import { NextRequest } from 'next/server'
|
|
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
|
|
|
const { mockGetSession, mockCheckWorkspaceAccess, mockIsPlatformAdmin, mockGetBlockVisibility } =
|
|
vi.hoisted(() => ({
|
|
mockGetSession: vi.fn(),
|
|
mockCheckWorkspaceAccess: vi.fn(),
|
|
mockIsPlatformAdmin: vi.fn(),
|
|
mockGetBlockVisibility: vi.fn(),
|
|
}))
|
|
|
|
vi.mock('@/lib/auth', () => ({
|
|
auth: { api: { getSession: vi.fn() } },
|
|
getSession: mockGetSession,
|
|
}))
|
|
|
|
vi.mock('@/lib/workspaces/permissions/utils', () => ({
|
|
checkWorkspaceAccess: mockCheckWorkspaceAccess,
|
|
}))
|
|
|
|
vi.mock('@/lib/permissions/super-user', () => ({
|
|
isPlatformAdmin: mockIsPlatformAdmin,
|
|
}))
|
|
|
|
vi.mock('@/lib/core/config/block-visibility', () => ({
|
|
getBlockVisibility: mockGetBlockVisibility,
|
|
}))
|
|
|
|
import { GET } from '@/app/api/blocks/visibility/route'
|
|
|
|
const WORKSPACE_ID = '11111111-2222-4333-8444-555555555555'
|
|
|
|
function request(workspaceId = WORKSPACE_ID) {
|
|
return new NextRequest(`http://localhost/api/blocks/visibility?workspaceId=${workspaceId}`)
|
|
}
|
|
|
|
describe('GET /api/blocks/visibility', () => {
|
|
beforeEach(() => {
|
|
vi.clearAllMocks()
|
|
mockGetSession.mockResolvedValue({ user: { id: 'user-1' } })
|
|
mockCheckWorkspaceAccess.mockResolvedValue({
|
|
hasAccess: true,
|
|
workspace: { organizationId: 'org-1' },
|
|
})
|
|
mockIsPlatformAdmin.mockResolvedValue(false)
|
|
mockGetBlockVisibility.mockResolvedValue({
|
|
revealed: new Set(['gmail_v2']),
|
|
disabled: new Set(['slack']),
|
|
previewTagged: new Set(['gmail_v2']),
|
|
})
|
|
})
|
|
|
|
it('returns 401 without a session', async () => {
|
|
mockGetSession.mockResolvedValue(null)
|
|
const response = await GET(request())
|
|
expect(response.status).toBe(401)
|
|
})
|
|
|
|
it('returns 403 without workspace access', async () => {
|
|
mockCheckWorkspaceAccess.mockResolvedValue({ hasAccess: false, workspace: null })
|
|
const response = await GET(request())
|
|
expect(response.status).toBe(403)
|
|
expect(mockGetBlockVisibility).not.toHaveBeenCalled()
|
|
})
|
|
|
|
it('evaluates visibility for the session user, workspace org, and pre-resolved admin', async () => {
|
|
mockIsPlatformAdmin.mockResolvedValue(true)
|
|
const response = await GET(request())
|
|
expect(response.status).toBe(200)
|
|
expect(await response.json()).toEqual({
|
|
revealed: ['gmail_v2'],
|
|
disabled: ['slack'],
|
|
previewTagged: ['gmail_v2'],
|
|
})
|
|
expect(mockGetBlockVisibility).toHaveBeenCalledWith({
|
|
userId: 'user-1',
|
|
orgId: 'org-1',
|
|
isAdmin: true,
|
|
})
|
|
})
|
|
})
|