Files
ar.badieiandCursor 370ac15471 Ship Novya PWA with backend for deployable production use.
Fix production TypeScript builds and add DEPLOY.md so the app can be hosted from this repo.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-03 21:01:52 +03:30

94 lines
2.7 KiB
TypeScript

import assert from 'node:assert/strict';
import { after, before, describe, it } from 'node:test';
import { createApp } from '../src/app.js';
import * as prismaModule from '../src/lib/prisma.js';
describe('application', () => {
it('initializes createApp without throwing', () => {
const app = createApp();
assert.ok(app);
assert.equal(typeof app.fetch, 'function');
});
it('GET /health returns success', async () => {
const app = createApp();
const response = await app.fetch(new Request('http://localhost/health'));
assert.equal(response.status, 200);
const body = (await response.json()) as {
success: boolean;
data: { status: string; service: string };
meta: { requestId: string };
};
assert.equal(body.success, true);
assert.equal(body.data.status, 'ok');
assert.equal(body.data.service, 'Novya API');
assert.ok(body.meta.requestId);
});
it('GET /ready succeeds when database is available', async (t) => {
const app = createApp();
const response = await app.fetch(new Request('http://localhost/ready'));
if (response.status === 503) {
t.skip('MySQL is not running');
return;
}
assert.equal(response.status, 200);
const body = (await response.json()) as {
success: boolean;
data: { status: string; checks: { database: string } };
};
assert.equal(body.success, true);
assert.equal(body.data.status, 'ready');
assert.equal(body.data.checks.database, 'ok');
});
it('GET /ready fails safely when database is unavailable', async () => {
const app = createApp({
checkDatabaseHealth: async () => false,
});
const response = await app.fetch(new Request('http://localhost/ready'));
assert.equal(response.status, 503);
const body = (await response.json()) as {
success: boolean;
error: { code: string; message: string };
meta: { requestId: string };
};
assert.equal(body.success, false);
assert.equal(body.error.code, 'DATABASE_UNAVAILABLE');
assert.equal(body.error.message, 'Database is not available');
assert.ok(body.meta.requestId);
assert.doesNotMatch(JSON.stringify(body), /mysql:\/\//i);
assert.doesNotMatch(JSON.stringify(body), /DATABASE_URL/i);
});
});
describe('prisma connectivity', () => {
before(async () => {
try {
await prismaModule.connectPrisma();
} catch {
// handled per test
}
});
after(async () => {
await prismaModule.disconnectPrisma();
});
it('can connect when MySQL is available', async (t) => {
const healthy = await prismaModule.checkDatabaseHealth();
if (!healthy) {
t.skip('MySQL is not running');
return;
}
assert.equal(healthy, true);
});
});