diff --git a/node_modules/.vite/vitest/da39a3ee5e6b4b0d3255bfef95601890afd80709/results.json b/node_modules/.vite/vitest/da39a3ee5e6b4b0d3255bfef95601890afd80709/results.json index d1c6c39..e3fae1e 100644 --- a/node_modules/.vite/vitest/da39a3ee5e6b4b0d3255bfef95601890afd80709/results.json +++ b/node_modules/.vite/vitest/da39a3ee5e6b4b0d3255bfef95601890afd80709/results.json @@ -1 +1 @@ -{"version":"4.1.5","results":[[":status-badge.test.ts",{"duration":5.837028000000004,"failed":false}]]} \ No newline at end of file +{"version":"3.2.4","results":[[":tests/api/ping.test.ts",{"duration":0,"failed":true}]]} \ No newline at end of file diff --git a/src/app/api/ping/route.ts b/src/app/api/ping/route.ts new file mode 100644 index 0000000..01854d9 --- /dev/null +++ b/src/app/api/ping/route.ts @@ -0,0 +1,20 @@ +// FILE: src/app/api/ping/route.ts +import { NextRequest } from 'next/server'; +import { logger } from '@/lib/logger'; + +/** + * Handles GET requests to /api/ping. + * Responds with { pong: true, ts: Date.now() } in JSON. + * Logs request and response timestamp. + */ +export async function GET(req: NextRequest) { + const now = Date.now(); + logger.info({ event: 'ping_requested', ts: now }); + return new Response( + JSON.stringify({ pong: true, ts: now }), + { + status: 200, + headers: { 'Content-Type': 'application/json' }, + } + ); +} diff --git a/tests/api/ping.test.ts b/tests/api/ping.test.ts new file mode 100644 index 0000000..3611179 --- /dev/null +++ b/tests/api/ping.test.ts @@ -0,0 +1,16 @@ +// FILE: tests/api/ping.test.ts +import { describe, it, expect, vi } from 'vitest'; +import request from 'supertest'; +import app from '../../src/app'; + +describe('GET /api/ping', () => { + it('should return a 200 status and correct response format', async () => { + const response = await request(app).get('/api/ping'); + expect(response.status).toBe(200); + expect(typeof response.body.ts).toBe('number'); + expect(response.body.pong).toBe(true); + // Ensure ts is a recent timestamp + const now = Date.now(); + expect(Math.abs(now - response.body.ts)).toBeLessThan(3000); + }); +});