- Add Next.js app structure with base configs, linting, and formatting - Implement LiveKit Meet page, types, and utility functions - Add Docker, Compose, and deployment scripts for backend and token server - Provide E2E and smoke test scaffolding with Puppeteer and Playwright helpers - Include CSS modules and global styles for UI - Add postMessage and studio integration utilities - Update package.json with dependencies and scripts for development and testing
73 lines
2.8 KiB
JavaScript
73 lines
2.8 KiB
JavaScript
// scripts/test_prisma_session.js
|
|
// Quick script to test Prisma connection and upsert/read a Session record.
|
|
// Usage:
|
|
// node scripts/test_prisma_session.js
|
|
// It will load DATABASE_URL from environment; if not present it will try to load packages/backend-api/.env via dotenv.
|
|
|
|
(async () => {
|
|
try {
|
|
// Load dotenv from the backend-api package if DATABASE_URL not already set
|
|
if (!process.env.DATABASE_URL) {
|
|
try {
|
|
const path = require('path');
|
|
const dotenv = require('dotenv');
|
|
const envFile = path.resolve(__dirname, '..', '.env');
|
|
// load but do not override existing env
|
|
dotenv.config({ path: envFile });
|
|
} catch (e) {
|
|
// ignore if dotenv not available
|
|
}
|
|
}
|
|
|
|
if (!process.env.DATABASE_URL) {
|
|
console.error('ERROR: DATABASE_URL env var is not set. Aborting.');
|
|
console.error('You can set it manually or create packages/backend-api/.env with DATABASE_URL.');
|
|
process.exit(2);
|
|
}
|
|
|
|
// Normalize: remove surrounding single/double quotes if present
|
|
let dbUrl = process.env.DATABASE_URL;
|
|
if ((dbUrl.startsWith("'") && dbUrl.endsWith("'")) || (dbUrl.startsWith('"') && dbUrl.endsWith('"'))) {
|
|
dbUrl = dbUrl.slice(1, -1);
|
|
}
|
|
process.env.DATABASE_URL = dbUrl;
|
|
|
|
console.log('Prisma test: using DATABASE_URL=', dbUrl.replace(/:[^:@]+@/, ':***@'));
|
|
|
|
const { PrismaClient } = require('@prisma/client');
|
|
const prisma = new PrismaClient();
|
|
await prisma.$connect();
|
|
console.log('[Prisma] connected');
|
|
|
|
const id = 'e2e_test_' + Math.random().toString(36).slice(2, 9);
|
|
const expiresAt = new Date(Date.now() + 5 * 60 * 1000); // 5m
|
|
|
|
console.log('Upserting session id=', id);
|
|
const created = await prisma.session.upsert({
|
|
where: { id },
|
|
update: { token: 'test-token-' + id, url: 'wss://test-local', room: 'testroom', username: 'tester', expiresAt },
|
|
create: { id, token: 'test-token-' + id, url: 'wss://test-local', room: 'testroom', username: 'tester', expiresAt },
|
|
});
|
|
|
|
console.log('Upsert result:', { id: created.id, room: created.room, username: created.username, expiresAt: created.expiresAt });
|
|
|
|
const found = await prisma.session.findUnique({ where: { id } });
|
|
if (!found) {
|
|
console.error('Failed to read session after upsert');
|
|
process.exit(1);
|
|
}
|
|
console.log('Read session ok:', { id: found.id, room: found.room, username: found.username, expiresAt: found.expiresAt });
|
|
|
|
// cleanup
|
|
await prisma.session.delete({ where: { id } }).catch(() => {});
|
|
console.log('Cleanup done');
|
|
|
|
await prisma.$disconnect();
|
|
console.log('Prisma test complete');
|
|
process.exit(0);
|
|
} catch (err) {
|
|
console.error('Prisma test failed', err && err.message ? err.message : err);
|
|
process.exit(1);
|
|
}
|
|
})();
|