diff --git a/apps/backend/src/__tests__/app.test.ts b/apps/backend/src/__tests__/app.test.ts new file mode 100644 index 0000000..648d98a --- /dev/null +++ b/apps/backend/src/__tests__/app.test.ts @@ -0,0 +1,20 @@ +process.env.NODE_ENV = 'test'; + +import { describe, it, expect } from 'vitest'; +import { buildApp } from '../app'; + +describe('GET /health', () => { + it('should return status ok', async () => { + const app = await buildApp(); + + const res = await app.inject({ + method: 'GET', + url: '/health', + }); + + expect(res.statusCode).toBe(200); + expect(JSON.parse(res.body)).toEqual({ status: 'ok' }); + + await app.close(); + }); +}); \ No newline at end of file diff --git a/apps/backend/src/app.ts b/apps/backend/src/app.ts index dc023a2..e412e6a 100644 --- a/apps/backend/src/app.ts +++ b/apps/backend/src/app.ts @@ -54,9 +54,12 @@ export async function buildApp() { }); // ─── Database & Cache Plugins ─── - await app.register(prismaPlugin); + if (process.env.NODE_ENV !== 'test') { + await app.register(prismaPlugin); //change +} + if (process.env.NODE_ENV !== 'test') { await app.register(redisPlugin); - +} // ─── Auth Decorator ─── app.decorate('authenticate', async function (request: any, reply: any) { try { @@ -76,11 +79,12 @@ export async function buildApp() { await app.register(analyticsRoutes, { prefix: '/api/analytics' }); // ─── Health Check ─── - app.get('/health', async () => ({ - status: 'ok', - timestamp: new Date().toISOString(), - service: 'devcard-api', - })); +type HealthResponse = { + status: 'ok'; +}; +app.get('/health', async (): Promise => { + return { status: 'ok' }; +}); return app; }