test: authenticated admin E2E tour with smart mock backend (all pages screenshot)
- Rewrote e2e/mock-backend.mjs to return valid auth responses (login + refresh) - Created e2e/authenticated-tour.spec.ts that logs in and screenshots all 7 admin pages - Fixed (dashboard-layout)/layout.tsx: added missing NextIntlClientProvider - All pages render error-free in dark mode with mock data - Screenshots: dashboard, members, distributions, distribution/new, stock, stock/new, reports
This commit is contained in:
@@ -1,10 +1,18 @@
|
||||
/**
|
||||
* Mock backend for screenshot tour.
|
||||
* Returns a valid auth response for any login attempt.
|
||||
* Smart mock backend for authenticated E2E tours.
|
||||
* Handles auth endpoints so NextAuth can create valid sessions.
|
||||
* Run: node e2e/mock-backend.mjs
|
||||
*/
|
||||
import http from "node:http"
|
||||
|
||||
const MOCK_USER = {
|
||||
id: "user-001",
|
||||
email: "admin@gruener-daumen.de",
|
||||
role: "ADMIN",
|
||||
clubId: "club-001",
|
||||
clubName: "Grüner Daumen e.V.",
|
||||
}
|
||||
|
||||
const server = http.createServer((req, res) => {
|
||||
// CORS headers
|
||||
res.setHeader("Access-Control-Allow-Origin", "*")
|
||||
@@ -17,35 +25,57 @@ const server = http.createServer((req, res) => {
|
||||
return
|
||||
}
|
||||
|
||||
const url = req.url?.split("?")[0] // strip query params
|
||||
|
||||
// Login endpoint
|
||||
if (req.url === "/api/v1/auth/login" && req.method === "POST") {
|
||||
if (url === "/api/v1/auth/login" && req.method === "POST") {
|
||||
let body = ""
|
||||
req.on("data", (chunk) => (body += chunk))
|
||||
req.on("end", () => {
|
||||
console.log(` ✓ POST /api/v1/auth/login — 200 OK`)
|
||||
res.writeHead(200, { "Content-Type": "application/json" })
|
||||
res.end(
|
||||
JSON.stringify({
|
||||
accessToken: "mock-jwt-token-for-screenshots",
|
||||
refreshToken: "mock-refresh-token",
|
||||
accessToken: "mock-jwt-token-for-e2e-testing-" + Date.now(),
|
||||
refreshToken: "mock-refresh-token-" + Date.now(),
|
||||
tokenType: "Bearer",
|
||||
expiresIn: 3600,
|
||||
member: {
|
||||
id: "1",
|
||||
email: "admin@cannamanage.de",
|
||||
clubName: "Grüner Daumen e.V.",
|
||||
role: "ADMIN",
|
||||
clubId: "club-1",
|
||||
},
|
||||
member: MOCK_USER,
|
||||
})
|
||||
)
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// Catch-all for other API requests
|
||||
// Refresh endpoint
|
||||
if (url === "/api/v1/auth/refresh" && req.method === "POST") {
|
||||
let body = ""
|
||||
req.on("data", (chunk) => (body += chunk))
|
||||
req.on("end", () => {
|
||||
console.log(` ✓ POST /api/v1/auth/refresh — 200 OK`)
|
||||
res.writeHead(200, { "Content-Type": "application/json" })
|
||||
res.end(
|
||||
JSON.stringify({
|
||||
accessToken: "mock-refreshed-token-" + Date.now(),
|
||||
refreshToken: "mock-refresh-token-new-" + Date.now(),
|
||||
tokenType: "Bearer",
|
||||
expiresIn: 3600,
|
||||
})
|
||||
)
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// Catch-all — return 200 with empty success (frontend uses local mock data)
|
||||
console.log(` → ${req.method} ${req.url} — 200 (catch-all)`)
|
||||
res.writeHead(200, { "Content-Type": "application/json" })
|
||||
res.end(JSON.stringify({ status: "ok" }))
|
||||
res.end(JSON.stringify({ status: "ok", message: "mock backend catch-all" }))
|
||||
})
|
||||
|
||||
server.listen(8080, () => {
|
||||
console.log("🟢 Mock backend running on http://localhost:8080")
|
||||
console.log("🟢 Smart mock backend running on http://localhost:8080")
|
||||
console.log(" Endpoints:")
|
||||
console.log(" • POST /api/v1/auth/login → valid auth response")
|
||||
console.log(" • POST /api/v1/auth/refresh → refreshed token")
|
||||
console.log(" • * → 200 catch-all")
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user