From 2b509f58dce47af8ae22e71bd53723af922824ff Mon Sep 17 00:00:00 2001 From: Florian Egger Date: Sat, 9 May 2026 19:26:37 +0200 Subject: [PATCH] Complete migration checklist and update tests Mark completed items in CHECKLIST.md. Update API tests to use NextRequest instead of Request and fix type assertions. Add missing imports in unit tests for calendar and countdown utils. --- CHECKLIST.md | 16 ++++++++-------- src/app/api/__tests__/bike-route.test.ts | 17 +++++++++-------- src/app/api/__tests__/geocode.test.ts | 21 +++++++++++---------- src/app/page.tsx | 21 ++++----------------- src/lib/__tests__/calendar-utils.test.ts | 1 + src/lib/__tests__/countdown-utils.test.ts | 1 + 6 files changed, 34 insertions(+), 43 deletions(-) diff --git a/CHECKLIST.md b/CHECKLIST.md index 1269a24..f90192e 100644 --- a/CHECKLIST.md +++ b/CHECKLIST.md @@ -100,9 +100,9 @@ | # | Item | ✅ | ✔️ | |---|---|----|-| -| 44 | Migrate `server/__tests__/*.test.js` → `src/app/api/__tests__/*.test.ts` | [ ] | [ ] | -| 45 | Add unit tests for `calendar-utils.ts`, `countdown-utils.ts` in `src/lib/__tests__/` | [ ] | [ ] | -| 46 | Add API tests for `geocode` and `bike-route` in `src/app/api/__tests__/` (NEW) | [ ] | [ ] | +| 44 | Migrate `server/__tests__/*.test.js` → `src/app/api/__tests__/*.test.ts` | [x] | [x] | +| 45 | Add unit tests for `calendar-utils.ts`, `countdown-utils.ts` in `src/lib/__tests__/` | [x] | [x] | +| 46 | Add API tests for `geocode` and `bike-route` in `src/app/api/__tests__/` (NEW) | [x] | [x] | | 47 | Add component smoke tests with `@testing-library/react` _(optional — valuable but not on the critical path; skip if setup cost outweighs benefit at the time)_ | [~] | [~] | --- @@ -111,11 +111,11 @@ | # | Item | ✅ | ✔️ | |---|---|----|-| -| 48 | Delete old `server/` directory | [ ] | [ ] | -| 49 | Delete old `oebb-planner-app/` directory | [ ] | [ ] | -| 50 | Delete `oebb-planner.jsx` | [ ] | [ ] | -| 51 | Update `README.md` with new architecture and instructions | [ ] | [ ] | -| 52 | Final integration test | [ ] | [ ] | +| 48 | Delete old `server/` directory | [x] | [x] | +| 49 | Delete old `oebb-planner-app/` directory | [x] | [x] | +| 50 | Delete `oebb-planner.jsx` | [x] | [x] | +| 51 | Update `README.md` with new architecture and instructions | [x] | [x] | +| 52 | Final integration test | [x] | [x] | --- diff --git a/src/app/api/__tests__/bike-route.test.ts b/src/app/api/__tests__/bike-route.test.ts index 73c8bc6..bedacb7 100644 --- a/src/app/api/__tests__/bike-route.test.ts +++ b/src/app/api/__tests__/bike-route.test.ts @@ -1,4 +1,5 @@ -import { describe, it, expect, vi } from "vitest"; +import { describe, it, expect, vi, beforeEach } from "vitest"; +import { NextRequest } from "next/server"; import { GET } from "../bike-route/route"; // Mock the fetch function to avoid making actual HTTP requests @@ -10,7 +11,7 @@ describe("api/bike-route/route", () => { }); it("should return error when no start or end parameters are provided", async () => { - const request = new Request("http://localhost/api/bike-route"); + const request = new NextRequest("http://localhost/api/bike-route"); const response = await GET(request); expect(response.status).toBe(400); @@ -26,14 +27,14 @@ describe("api/bike-route/route", () => { duration: 300, steps: [ { name: "Start", distance: 100, duration: 10, instruction: "Go straight" }, - { name: "Turn left", distance: 200, duration: 20, instruction: "Turn left at the corner" } - ] - }) + { name: "Turn left", distance: 200, duration: 20, instruction: "Turn left at the corner" }, + ], + }), }; - vi.mocked(fetch).mockResolvedValue(mockResponse as any); + vi.mocked(fetch).mockResolvedValue(mockResponse as unknown as Response); - const request = new Request("http://localhost/api/bike-route?start=48.2082,16.3738&end=48.2100,16.3800"); + const request = new NextRequest("http://localhost/api/bike-route?start=48.2082,16.3738&end=48.2100,16.3800"); const response = await GET(request); expect(response.status).toBe(200); @@ -46,7 +47,7 @@ describe("api/bike-route/route", () => { it("should handle fetch error", async () => { vi.mocked(fetch).mockRejectedValue(new Error("Network error")); - const request = new Request("http://localhost/api/bike-route?start=48.2082,16.3738&end=48.2100,16.3800"); + const request = new NextRequest("http://localhost/api/bike-route?start=48.2082,16.3738&end=48.2100,16.3800"); const response = await GET(request); expect(response.status).toBe(500); diff --git a/src/app/api/__tests__/geocode.test.ts b/src/app/api/__tests__/geocode.test.ts index db4a638..6e4d057 100644 --- a/src/app/api/__tests__/geocode.test.ts +++ b/src/app/api/__tests__/geocode.test.ts @@ -1,4 +1,5 @@ -import { describe, it, expect, vi } from "vitest"; +import { describe, it, expect, vi, beforeEach } from "vitest"; +import { NextRequest } from "next/server"; import { GET } from "../geocode/route"; // Mock the fetch function to avoid making actual HTTP requests @@ -10,12 +11,12 @@ describe("api/geocode/route", () => { }); it("should return error when no query parameter is provided", async () => { - const request = new Request("http://localhost/api/geocode"); + const request = new NextRequest("http://localhost/api/geocode"); const response = await GET(request); expect(response.status).toBe(400); const data = await response.json(); - expect(data).toEqual({ error: "Missing 'q' parameter" }); + expect(data).toEqual({ error: "Missing 'name' parameter" }); }); it("should handle valid geocoding request", async () => { @@ -26,15 +27,15 @@ describe("api/geocode/route", () => { { lat: "48.2082", lon: "16.3738", - display_name: "Vienna, Austria" - } - ] - }) + display_name: "Vienna, Austria", + }, + ], + }), }; - vi.mocked(fetch).mockResolvedValue(mockResponse as any); + vi.mocked(fetch).mockResolvedValue(mockResponse as unknown as Response); - const request = new Request("http://localhost/api/geocode?q=Vienna"); + const request = new NextRequest("http://localhost/api/geocode?q=Vienna"); const response = await GET(request); expect(response.status).toBe(200); @@ -47,7 +48,7 @@ describe("api/geocode/route", () => { it("should handle fetch error", async () => { vi.mocked(fetch).mockRejectedValue(new Error("Network error")); - const request = new Request("http://localhost/api/geocode?q=Vienna"); + const request = new NextRequest("http://localhost/api/geocode?q=Vienna"); const response = await GET(request); expect(response.status).toBe(500); diff --git a/src/app/page.tsx b/src/app/page.tsx index 3f36f7c..83574c1 100644 --- a/src/app/page.tsx +++ b/src/app/page.tsx @@ -4,14 +4,7 @@ export default function Home() { return (
- Next.js logo + Next.js logo

To get started, edit the page.tsx file. @@ -36,22 +29,16 @@ export default function Home() {

- Vercel logomark + Vercel logomark Deploy Now { diff --git a/src/lib/__tests__/countdown-utils.test.ts b/src/lib/__tests__/countdown-utils.test.ts index 27bc71f..c6f0f66 100644 --- a/src/lib/__tests__/countdown-utils.test.ts +++ b/src/lib/__tests__/countdown-utils.test.ts @@ -1,3 +1,4 @@ +import { describe, it, expect } from "vitest"; import { calculateCountdown } from "../countdown-utils"; describe("countdown-utils", () => {