CognxSafeTrack commited on
Commit Β·
df5c8fa
1
Parent(s): f8274a4
chore: implement Phase 3 initial setup (TypeScript cleanup and health test)
Browse files- apps/api/src/index.ts +1 -1
- apps/api/src/routes/internal.ts +2 -2
- apps/api/src/types/fastify.d.ts +1 -0
- apps/api/test/health.test.ts +45 -0
apps/api/src/index.ts
CHANGED
|
@@ -24,7 +24,7 @@ const server: FastifyInstance = fastify({
|
|
| 24 |
});
|
| 25 |
|
| 26 |
// Attach prisma to server instance for global access in routes
|
| 27 |
-
|
| 28 |
|
| 29 |
// ββ Middleware & Plugins ββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 30 |
server.register(cors, {
|
|
|
|
| 24 |
});
|
| 25 |
|
| 26 |
// Attach prisma to server instance for global access in routes
|
| 27 |
+
server.decorate('prisma', prisma);
|
| 28 |
|
| 29 |
// ββ Middleware & Plugins ββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 30 |
server.register(cors, {
|
apps/api/src/routes/internal.ts
CHANGED
|
@@ -27,13 +27,13 @@ export async function internalRoutes(fastify: FastifyInstance) {
|
|
| 27 |
const serverAdapter = new FastifyAdapter();
|
| 28 |
|
| 29 |
createBullBoard({
|
| 30 |
-
queues: [new BullMQAdapter(whatsappQueue as any)],
|
| 31 |
serverAdapter,
|
| 32 |
});
|
| 33 |
|
| 34 |
// Re-enabled BullBoard for production monitoring
|
| 35 |
serverAdapter.setBasePath('/v1/internal/queues');
|
| 36 |
-
fastify.register(serverAdapter.registerPlugin()
|
| 37 |
prefix: '/v1/internal/queues',
|
| 38 |
basePath: '/v1/internal/queues',
|
| 39 |
config: { requireAuth: true }
|
|
|
|
| 27 |
const serverAdapter = new FastifyAdapter();
|
| 28 |
|
| 29 |
createBullBoard({
|
| 30 |
+
queues: [new BullMQAdapter(whatsappQueue as any)], // Queue types are notoriously difficult to match with BullMQAdapter
|
| 31 |
serverAdapter,
|
| 32 |
});
|
| 33 |
|
| 34 |
// Re-enabled BullBoard for production monitoring
|
| 35 |
serverAdapter.setBasePath('/v1/internal/queues');
|
| 36 |
+
fastify.register(serverAdapter.registerPlugin(), {
|
| 37 |
prefix: '/v1/internal/queues',
|
| 38 |
basePath: '/v1/internal/queues',
|
| 39 |
config: { requireAuth: true }
|
apps/api/src/types/fastify.d.ts
CHANGED
|
@@ -10,6 +10,7 @@ declare module 'fastify' {
|
|
| 10 |
interface FastifyRequest {
|
| 11 |
jwtVerify(): Promise<void>;
|
| 12 |
rawBody?: Buffer;
|
|
|
|
| 13 |
user: {
|
| 14 |
id: string;
|
| 15 |
organizationId: string;
|
|
|
|
| 10 |
interface FastifyRequest {
|
| 11 |
jwtVerify(): Promise<void>;
|
| 12 |
rawBody?: Buffer;
|
| 13 |
+
organizationId?: string; // For internal forwarding context
|
| 14 |
user: {
|
| 15 |
id: string;
|
| 16 |
organizationId: string;
|
apps/api/test/health.test.ts
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { describe, it, expect, beforeAll, afterAll } from 'vitest';
|
| 2 |
+
import fastify, { FastifyInstance } from 'fastify';
|
| 3 |
+
import { whatsappRoutes } from '../src/routes/whatsapp';
|
| 4 |
+
import { authRoutes } from '../src/routes/auth';
|
| 5 |
+
|
| 6 |
+
describe('API Health & Basic Routing', () => {
|
| 7 |
+
let server: FastifyInstance;
|
| 8 |
+
|
| 9 |
+
beforeAll(async () => {
|
| 10 |
+
server = fastify({ logger: false });
|
| 11 |
+
// Register minimal routes for health check
|
| 12 |
+
await server.register(authRoutes, { prefix: '/v1/auth' });
|
| 13 |
+
await server.register(whatsappRoutes, { prefix: '/v1/whatsapp' });
|
| 14 |
+
await server.ready();
|
| 15 |
+
});
|
| 16 |
+
|
| 17 |
+
afterAll(async () => {
|
| 18 |
+
await server.close();
|
| 19 |
+
});
|
| 20 |
+
|
| 21 |
+
it('should respond with 200 on WhatsApp webhook GET (Verification)', async () => {
|
| 22 |
+
const response = await server.inject({
|
| 23 |
+
method: 'GET',
|
| 24 |
+
url: '/v1/whatsapp/webhook',
|
| 25 |
+
query: {
|
| 26 |
+
'hub.mode': 'subscribe',
|
| 27 |
+
'hub.verify_token': process.env.WHATSAPP_VERIFY_TOKEN || 'test-token',
|
| 28 |
+
'hub.challenge': '1234'
|
| 29 |
+
}
|
| 30 |
+
});
|
| 31 |
+
|
| 32 |
+
expect(response.statusCode).toBe(200);
|
| 33 |
+
expect(response.payload).toBe('1234');
|
| 34 |
+
});
|
| 35 |
+
|
| 36 |
+
it('should have a working Auth registration endpoint structure', async () => {
|
| 37 |
+
const response = await server.inject({
|
| 38 |
+
method: 'POST',
|
| 39 |
+
url: '/v1/auth/register',
|
| 40 |
+
payload: {} // Empty payload should trigger validation error, not 404
|
| 41 |
+
});
|
| 42 |
+
|
| 43 |
+
expect(response.statusCode).not.toBe(404);
|
| 44 |
+
});
|
| 45 |
+
});
|