Files
BarevClub/packages/services/test/global-setup.ts
T
zabudko-ruandClaude Opus 5.5 23ffb2bf1d Backoffice stage 2: chats (support + concierge, files)
- ChatThread per client/provider and channel; messages get files, internal notes,
  source (bot/mini app) and delivery errors; reply templates. Migration moves old
  concierge messages into threads.
- Routing: subscribers write to the concierge, others to support; /support and
  /concierge in the client bot; staff can take, transfer, close and move threads.
- Telegram: photos/documents from clients and providers, replies with the channel
  header, files sent from storage, notifications only to the assignee or the
  channel's staff, "Reply" into a specific thread.
- New admin: /chats with list, conversation, notes, files, templates, client panel;
  "Message" button on the client card; dashboard counts threads awaiting reply.
- Client mini app: in-app chat screen sharing the same conversation.
- Old admin keeps working on the same data (notes hidden there).
- Tests for routing, notes, assign/close/move, lists, recipients; separate test DB
  via TEST_DB_NAME; dev:chats-demo script.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-21 01:50:37 +04:00

26 lines
1.2 KiB
TypeScript

import { execSync } from 'node:child_process';
import path from 'node:path';
import { config } from 'dotenv';
import pg from 'pg';
/** Отдельная БД barev_test рядом с основной; схема накатывается миграциями */
export default async function setup() {
config({ path: path.resolve(import.meta.dirname, '../../../.env'), quiet: true });
const base = new URL(process.env.DATABASE_URL!);
const testUrl = new URL(base);
// TEST_DB_NAME — своя тестовая БД (например, для второй рабочей копии)
const name = process.env.TEST_DB_NAME ?? 'barev_test';
testUrl.pathname = `/${name}`;
const admin = new pg.Client({ connectionString: base.toString() });
await admin.connect();
const exists = await admin.query('SELECT 1 FROM pg_database WHERE datname = $1', [name]);
if (!exists.rowCount) await admin.query(`CREATE DATABASE "${name}"`);
await admin.end();
execSync('npx prisma migrate deploy', {
cwd: path.resolve(import.meta.dirname, '../../db'),
env: { ...process.env, DATABASE_URL: testUrl.toString() },
stdio: 'pipe',
});
process.env.TEST_DATABASE_URL = testUrl.toString();
}