Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions apps/backend/src/__tests__/app.test.ts
Original file line number Diff line number Diff line change
@@ -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();
});
});
18 changes: 11 additions & 7 deletions apps/backend/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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<HealthResponse> => {
return { status: 'ok' };
});
return app;
}