mirror of
https://github.com/johndoe6345789/metabuilder.git
synced 2026-04-26 14:54:55 +00:00
- Introduced `PageConfig` entity for page configuration and layout definition. - Introduced `ComponentNode` entity for managing component hierarchy within pages. - Implemented operations for creating, reading, updating, and deleting both entities. - Updated Prisma schema to reflect new entities and relationships. - Enhanced ACL rules for new entities to manage access control. - Added conformance cases to test page and component hierarchy management. - Created a script to check synchronization between DBAL and Prisma schemas.
141 lines
4.1 KiB
TypeScript
141 lines
4.1 KiB
TypeScript
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
|
import { DBALClient } from '../../src/core/client'
|
|
import { DBALError, DBALErrorCode } from '../../src/core/foundation/errors'
|
|
|
|
const mockAdapter = vi.hoisted(() => ({
|
|
create: vi.fn(),
|
|
read: vi.fn(),
|
|
update: vi.fn(),
|
|
delete: vi.fn(),
|
|
list: vi.fn(),
|
|
findFirst: vi.fn(),
|
|
findByField: vi.fn(),
|
|
upsert: vi.fn(),
|
|
updateByField: vi.fn(),
|
|
deleteByField: vi.fn(),
|
|
deleteMany: vi.fn(),
|
|
createMany: vi.fn(),
|
|
updateMany: vi.fn(),
|
|
getCapabilities: vi.fn(),
|
|
close: vi.fn(),
|
|
}))
|
|
|
|
vi.mock('../../src/adapters/prisma', () => ({
|
|
PrismaAdapter: vi.fn(() => mockAdapter),
|
|
}))
|
|
|
|
const baseConfig = {
|
|
mode: 'development' as const,
|
|
adapter: 'prisma' as const,
|
|
database: { url: 'file:memory' },
|
|
tenantId: 'tenant-123',
|
|
}
|
|
|
|
const workflowInput = {
|
|
name: 'daily-sync',
|
|
description: 'Sync at midnight',
|
|
nodes: JSON.stringify([{ id: 'node-1', type: 'noop' }]),
|
|
edges: JSON.stringify([]),
|
|
enabled: true,
|
|
createdBy: 'user-1',
|
|
}
|
|
|
|
const workflowRecord = {
|
|
...workflowInput,
|
|
id: '22222222-2222-2222-2222-222222222222',
|
|
tenantId: baseConfig.tenantId,
|
|
version: 1,
|
|
createdAt: BigInt(1704067200000),
|
|
updatedAt: BigInt(1704153600000),
|
|
}
|
|
|
|
beforeEach(() => {
|
|
Object.values(mockAdapter).forEach(value => {
|
|
if (typeof value === 'function' && 'mockReset' in value) {
|
|
value.mockReset()
|
|
}
|
|
})
|
|
})
|
|
|
|
describe('DBALClient workflows', () => {
|
|
it('creates workflows via adapter', async () => {
|
|
mockAdapter.create.mockResolvedValue(workflowRecord)
|
|
|
|
const client = new DBALClient(baseConfig)
|
|
const result = await client.workflows.create(workflowInput)
|
|
|
|
const payload = mockAdapter.create.mock.calls[0][1]
|
|
expect(mockAdapter.create).toHaveBeenCalledWith('Workflow', expect.any(Object))
|
|
expect(payload).toMatchObject({
|
|
...workflowInput,
|
|
tenantId: baseConfig.tenantId,
|
|
enabled: true,
|
|
version: 1,
|
|
})
|
|
expect(typeof payload.id).toBe('string')
|
|
expect(typeof payload.createdAt).toBe('bigint')
|
|
expect(typeof payload.updatedAt).toBe('bigint')
|
|
expect(result).toEqual(workflowRecord)
|
|
})
|
|
|
|
it('rejects invalid workflow data before adapter call', async () => {
|
|
const client = new DBALClient(baseConfig)
|
|
|
|
await expect(client.workflows.create({
|
|
...workflowInput,
|
|
name: '',
|
|
})).rejects.toMatchObject({ code: DBALErrorCode.VALIDATION_ERROR })
|
|
|
|
expect(mockAdapter.create).not.toHaveBeenCalled()
|
|
})
|
|
|
|
it('maps workflow create conflicts to friendly message', async () => {
|
|
mockAdapter.create.mockRejectedValue(DBALError.conflict('unique violation'))
|
|
|
|
const client = new DBALClient(baseConfig)
|
|
|
|
await expect(client.workflows.create(workflowInput)).rejects.toMatchObject({
|
|
code: DBALErrorCode.CONFLICT,
|
|
message: "Workflow with name 'daily-sync' already exists",
|
|
})
|
|
})
|
|
|
|
it('throws not found when reading missing workflows', async () => {
|
|
mockAdapter.findFirst.mockResolvedValue(null)
|
|
|
|
const client = new DBALClient(baseConfig)
|
|
|
|
await expect(client.workflows.read(workflowRecord.id)).rejects.toMatchObject({
|
|
code: DBALErrorCode.NOT_FOUND,
|
|
})
|
|
})
|
|
|
|
it('updates, deletes, and lists workflows', async () => {
|
|
const updatedRecord = { ...workflowRecord, name: 'updated-name' }
|
|
mockAdapter.findFirst.mockResolvedValue(workflowRecord)
|
|
mockAdapter.update.mockResolvedValue(updatedRecord)
|
|
mockAdapter.delete.mockResolvedValue(true)
|
|
mockAdapter.list.mockResolvedValue({
|
|
data: [workflowRecord],
|
|
total: 1,
|
|
page: 1,
|
|
limit: 20,
|
|
hasMore: false,
|
|
})
|
|
|
|
const client = new DBALClient(baseConfig)
|
|
|
|
const updateResult = await client.workflows.update(workflowRecord.id, { name: 'updated-name' })
|
|
expect(updateResult).toEqual(updatedRecord)
|
|
|
|
const deleteResult = await client.workflows.delete(workflowRecord.id)
|
|
expect(deleteResult).toBe(true)
|
|
|
|
const listResult = await client.workflows.list()
|
|
expect(listResult.data).toEqual([workflowRecord])
|
|
expect(mockAdapter.list).toHaveBeenCalledWith('Workflow', {
|
|
filter: { tenantId: baseConfig.tenantId },
|
|
})
|
|
})
|
|
})
|