godcrm/tests/helpers/testFactory.js
GOD CRM Release f89e074dd1
Some checks failed
CI / Lint / Typecheck / Test / Build (push) Has been cancelled
CI / PostgreSQL Integration Tests (push) Has been cancelled
GOD CRM — public scrubbed snapshot
Governed substrate for autonomous agents: scoped identity (passports),
audited actions, MCP workspace. Infra IPs and secrets redacted for public release.
2026-08-10 04:01:45 +03:00

145 lines
3.6 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
* Test Factory — Генератор уникальных тестовых данных
* Решает проблему UNIQUE constraint fails
*/
/**
* Генерирует уникальный суффикс
*/
export function uniqueId() {
return `${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;
}
/**
* Создаёт тестового пользователя с уникальным email
*/
export function createTestUser(overrides = {}) {
const id = uniqueId();
return {
email: `test-${id}@test.godcrm.local`,
password: 'TestPass123!',
name: `Test User ${id}`,
...overrides
};
}
/**
* Создаёт тестовое пространство
*/
export function createTestSpace(userId, overrides = {}) {
const id = uniqueId();
return {
name: `Test Space ${id}`,
type: 'personal',
user_id: userId,
...overrides
};
}
/**
* Создаёт тестовый проект
*/
export function createTestProject(spaceId, overrides = {}) {
const id = uniqueId();
return {
name: `Test Project ${id}`,
space_id: spaceId,
theme_color: '#3B82F6',
theme_gradient: 'from-blue-500 to-blue-600',
...overrides
};
}
/**
* Создаёт тестовую таблицу
*/
export function createTestTable(projectId, overrides = {}) {
const id = uniqueId();
return {
name: `Test Table ${id}`,
project_id: projectId,
description: 'Auto-generated test table',
...overrides
};
}
/**
* Создаёт тестовую колонку
*/
export function createTestColumn(tableId, overrides = {}) {
const id = uniqueId();
return {
table_id: tableId,
name: `column_${id}`,
display_name: `Column ${id}`,
column_type: 'text',
order_index: 0,
required: false,
...overrides
};
}
/**
* Создаёт набор стандартных колонок для таблицы
*/
export function createStandardColumns(tableId) {
return [
createTestColumn(tableId, { name: 'name', display_name: 'Name', column_type: 'text', required: true, order_index: 0 }),
createTestColumn(tableId, { name: 'email', display_name: 'Email', column_type: 'email', order_index: 1 }),
createTestColumn(tableId, { name: 'phone', display_name: 'Phone', column_type: 'phone', order_index: 2 }),
createTestColumn(tableId, { name: 'status', display_name: 'Status', column_type: 'select', order_index: 3, config: JSON.stringify({ options: [{ value: 'active', label: 'Active' }, { value: 'inactive', label: 'Inactive' }] }) }),
createTestColumn(tableId, { name: 'amount', display_name: 'Amount', column_type: 'number', order_index: 4 })
];
}
/**
* Создаёт тестовую строку
*/
export function createTestRow(tableId, data = {}, overrides = {}) {
return {
table_id: tableId,
data: JSON.stringify(data),
...overrides
};
}
/**
* Создаёт тестовый dashboard
*/
export function createTestDashboard(projectId, overrides = {}) {
const id = uniqueId();
return {
name: `Test Dashboard ${id}`,
project_id: projectId,
...overrides
};
}
/**
* Создаёт тестовый виджет
*/
export function createTestWidget(dashboardId, overrides = {}) {
const id = uniqueId();
return {
dashboard_id: dashboardId,
title: `Test Widget ${id}`,
widget_type: 'preset',
preset_name: 'table_view',
config: JSON.stringify({}),
position: JSON.stringify({ x: 0, y: 0, w: 6, h: 4 }),
...overrides
};
}
export default {
createTestUser,
createTestSpace,
createTestProject,
createTestTable,
createTestColumn,
createStandardColumns,
createTestRow,
createTestDashboard,
createTestWidget,
uniqueId
};