mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-16 23:33:29 +00:00
perf(i18n,shell): ship one locale and stop blocking the first paint
The client bundle carries only the active locale — resolved on the server and handed to the provider with no hydration flash, halving the dashboard route to under a megabyte parsed (288 KiB gzip). The auth shell renders the app chrome immediately instead of a spinner while the session resolves in parallel, the widgets request folds into the snapshot it duplicated, and insight pills prefetch their sub-pages — a first visit to a sub-page lands in about ninety milliseconds instead of nearly a second.
This commit is contained in:
1 parent
9445d89b76
commit
3b480b9885
284 files changed
+6058
-5398
No files matched your search
@@ -70,19 +70,19 @@ describe("GET /api/admin/audit-log — extended filters", () => {
|
||||
});
|
||||
|
||||
it("filters by `actor` against userId OR user.username", async () => {
|
||||
await GET(req("actor=marc"));
|
||||
await GET(req("actor=testuser"));
|
||||
const call = vi.mocked(prisma.auditLog.findMany).mock.calls[0][0]!;
|
||||
const where = call.where as Record<string, unknown>;
|
||||
// Expect an OR clause covering userId + user.username (contains)
|
||||
expect(where.OR).toBeDefined();
|
||||
const or = where.OR as Array<Record<string, unknown>>;
|
||||
const matchesUserId = or.some((c) => c.userId === "marc");
|
||||
const matchesUserId = or.some((c) => c.userId === "testuser");
|
||||
const matchesUsername = or.some(
|
||||
(c) =>
|
||||
typeof c.user === "object" &&
|
||||
c.user !== null &&
|
||||
// user: { username: { contains: "marc", mode: "insensitive" } }
|
||||
JSON.stringify(c).toLowerCase().includes("marc"),
|
||||
// user: { username: { contains: "testuser", mode: "insensitive" } }
|
||||
JSON.stringify(c).toLowerCase().includes("testuser"),
|
||||
);
|
||||
expect(matchesUserId).toBe(true);
|
||||
expect(matchesUsername).toBe(true);
|
||||
|
||||
@@ -60,7 +60,7 @@ import { getSession } from "@/lib/auth/session";
|
||||
|
||||
const ADMIN_SESSION = {
|
||||
session: { id: "sess-admin", expiresAt: new Date(Date.now() + 3_600_000) },
|
||||
user: { id: "admin-1", username: "marc", role: "ADMIN" as const },
|
||||
user: { id: "admin-1", username: "testuser", role: "ADMIN" as const },
|
||||
};
|
||||
const USER_SESSION = {
|
||||
session: { id: "sess-user", expiresAt: new Date(Date.now() + 3_600_000) },
|
||||
|
||||
@@ -4,7 +4,7 @@ import { annotate, getEvent } from "@/lib/logging/context";
|
||||
import { apiSuccess } from "@/lib/api-response";
|
||||
import { parseScheduleRecurrence } from "@/lib/medication-schedule";
|
||||
import { dispatchLocalisedNotification } from "@/lib/notifications/dispatch-localised";
|
||||
import { getUserTodayBounds, getDayOfWeekInTz } from "@/lib/timezone";
|
||||
import { getUserTodayBounds, getDayOfWeekInTz } from "@/lib/tz/local-day";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ import { prisma } from "@/lib/db";
|
||||
|
||||
const ADMIN_OK = {
|
||||
session: { id: "sess-1", expiresAt: new Date(Date.now() + 3_600_000) },
|
||||
user: { id: "admin-1", username: "marc", role: "ADMIN" as const },
|
||||
user: { id: "admin-1", username: "testuser", role: "ADMIN" as const },
|
||||
};
|
||||
const USER_OK = {
|
||||
session: { id: "sess-2", expiresAt: new Date(Date.now() + 3_600_000) },
|
||||
|
||||
@@ -71,7 +71,7 @@ describe("PUT /api/admin/users/[id]", () => {
|
||||
new HttpError(401, "Not authenticated"),
|
||||
);
|
||||
await expect(
|
||||
PUT(jsonReq({ username: "marc" }), params("u1")),
|
||||
PUT(jsonReq({ username: "testuser" }), params("u1")),
|
||||
).rejects.toThrow("Not authenticated");
|
||||
});
|
||||
|
||||
@@ -80,7 +80,7 @@ describe("PUT /api/admin/users/[id]", () => {
|
||||
new HttpError(403, "Admin access required"),
|
||||
);
|
||||
await expect(
|
||||
PUT(jsonReq({ username: "marc" }), params("u1")),
|
||||
PUT(jsonReq({ username: "testuser" }), params("u1")),
|
||||
).rejects.toThrow("Admin access required");
|
||||
});
|
||||
|
||||
@@ -97,7 +97,7 @@ describe("PUT /api/admin/users/[id]", () => {
|
||||
|
||||
it("returns 404 when target user does not exist", async () => {
|
||||
vi.mocked(prisma.user.findUnique).mockResolvedValue(null);
|
||||
const res = await PUT(jsonReq({ username: "marc" }), params("u-missing"));
|
||||
const res = await PUT(jsonReq({ username: "testuser" }), params("u-missing"));
|
||||
expect(res.status).toBe(404);
|
||||
expect(vi.mocked(prisma.user.update)).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user