mirror of
https://github.com/arsvendg/Stirling-PDF.git
synced 2026-07-14 10:34:06 +02:00
# Description of Changes Main fixes: - Fix the display of the username in the bottom left - Now displays as "User" when not logged in on self-hosted (desktop) and "Guest" on SaaS when logged in anonymously - Now updates properly when the user logs in/out in SaaS, desktop and self-hosted - Fix incremental build issues in the desktop app that have been here since the start (I hope at least - I think the issue is that the JLink is built read-only and then on subsequent builds you get OS errors when trying to override the JLink with the new version. There's no real need for it to be read-only that I know of, so we might as well just make it R/W and ship like that)
67 lines
2.0 KiB
TypeScript
67 lines
2.0 KiB
TypeScript
import { describe, it, expect } from "vitest";
|
|
import type { TFunction } from "i18next";
|
|
import type { User } from "@app/auth/springAuthClient";
|
|
import { deriveDisplayName } from "@app/auth/UseSession";
|
|
|
|
// Stub t() that returns the fallback string. The real i18next instance
|
|
// looks up "auth.displayName.user" -> "User" but we don't need that
|
|
// machinery here.
|
|
const t: TFunction = ((_key: string, fallback?: string) =>
|
|
fallback ?? "") as TFunction;
|
|
|
|
function makeUser(overrides: Partial<User> = {}): User {
|
|
return {
|
|
id: "user-1",
|
|
email: "[email protected]",
|
|
username: "alice",
|
|
role: "USER",
|
|
...overrides,
|
|
};
|
|
}
|
|
|
|
describe("proprietary deriveDisplayName", () => {
|
|
it("returns null when there is no user object", () => {
|
|
expect(deriveDisplayName(null, t)).toBeNull();
|
|
expect(deriveDisplayName(undefined, t)).toBeNull();
|
|
});
|
|
|
|
it("returns the username when present", () => {
|
|
expect(deriveDisplayName(makeUser({ username: "alice" }), t)).toBe("alice");
|
|
});
|
|
|
|
it("falls back to email when username is empty", () => {
|
|
expect(
|
|
deriveDisplayName(
|
|
makeUser({ username: "", email: "[email protected]" }),
|
|
t,
|
|
),
|
|
).toBe("[email protected]");
|
|
});
|
|
|
|
it("returns null when both username and email are empty", () => {
|
|
expect(
|
|
deriveDisplayName(makeUser({ username: "", email: "" }), t),
|
|
).toBeNull();
|
|
});
|
|
|
|
it("returns the localised 'User' placeholder for anonymous users", () => {
|
|
expect(
|
|
deriveDisplayName(
|
|
makeUser({ is_anonymous: true, username: "anon-uuid" }),
|
|
t,
|
|
),
|
|
).toBe("User");
|
|
});
|
|
|
|
it("treats anonymous flag as authoritative - even a populated username is overridden", () => {
|
|
// The Spring backend may assign a generated username to anonymous users;
|
|
// we still want the localised placeholder shown to the UI.
|
|
expect(
|
|
deriveDisplayName(
|
|
makeUser({ is_anonymous: true, username: "anonymous-12345" }),
|
|
t,
|
|
),
|
|
).toBe("User");
|
|
});
|
|
});
|