import { describe, it, expect } from 'vitest' import request from 'supertest' import express from 'express' import path from 'path' import { fileURLToPath } from 'url' const __dirname = path.dirname(fileURLToPath(import.meta.url)) const publicDir = path.join(__dirname, '../../../public') function createBuggyApp() { const app = express() app.use(express.static(publicDir, { etag: true })) // Simulate the old buggy behavior - serve file directly instead of redirect app.get("/status", (_req, res) => { res.sendFile(path.join(publicDir, 'status.html')) }) // Clean URLs for other pages for (const page of ["privacy", "terms", "impressum", "usage"]) { app.get(`/${page}`, (_req, res) => res.redirect(301, `/${page}.html`)); } return app } function createFixedApp() { const app = express() app.use(express.static(publicDir, { etag: true })) // The FIX: Remove statusRouter, let redirect loop handle it // Clean URLs for legal pages (redirect /status → /status.html, etc.) for (const page of ["privacy", "terms", "impressum", "status", "usage"]) { app.get(`/${page}`, (_req, res) => res.redirect(301, `/${page}.html`)); } return app } describe('Status Route BUG-020', () => { it('CURRENT BUGGY BEHAVIOR: GET /status returns 200 instead of 301 redirect', async () => { const buggyApp = createBuggyApp() const res = await request(buggyApp).get('/status') expect(res.status).toBe(200) // This is the bug - should be 301 expect(res.headers['content-type']).toContain('text/html') }) it('EXPECTED BEHAVIOR: GET /status should redirect to /status.html with 301', async () => { const fixedApp = createFixedApp() const res = await request(fixedApp).get('/status').expect(301) expect(res.headers['location']).toBe('/status.html') }) it('GET /status.html should always return 200', async () => { const app = createBuggyApp() // This works the same in both cases const res = await request(app).get('/status.html') expect(res.status).toBe(200) expect(res.headers['content-type']).toContain('text/html') }) })