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

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions src/app/api/hello/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// FILE: src/app/api/hello/route.ts
import { NextRequest, NextResponse } from 'next/server';

/**
* GET /api/hello
* Returns a hello world message with the current timestamp
*/
export async function GET(_req: NextRequest) {
return NextResponse.json({
message: 'Hello World',
timestamp: Date.now(),
});
}
26 changes: 26 additions & 0 deletions src/tests/api/hello.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// FILE: src/tests/api/hello.test.ts
import { describe, it, expect } from 'vitest';
import { GET } from '@/app/api/hello/route';
import { NextRequest } from 'next/server';

function createMockNextRequest(method: string = 'GET', url: string = 'http://localhost/api/hello') {
// Partial implementation sufficient for GET handler
return new NextRequest(url, { method });
}

describe('GET /api/hello', () => {
it('should return Hello World message and timestamp', async () => {
const req = createMockNextRequest();
const res = await GET(req);
expect(res.status).toBe(200);
const json = await res.json();
expect(json).toEqual(
expect.objectContaining({
message: 'Hello World',
timestamp: expect.any(Number),
})
);
// Additional check: timestamp is within the last 5 seconds (to guard against stale/fake responses)
expect(Math.abs(json.timestamp - Date.now())).toBeLessThan(5000);
});
});