Reorganize repo structure and standards references
This commit is contained in:
1 parent
3cb93a81be
commit
be2054274d
5885 files changed
+2588
-195
No files matched your search
@@ -0,0 +1,142 @@
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
|
||||
import {
|
||||
findLegacyAuthUserById,
|
||||
findLegacyLoginUserByEmail,
|
||||
findLegacyUserWithoutPasswordById,
|
||||
recordLegacyLogin,
|
||||
type LegacyAuthUserReaderClient,
|
||||
type LegacyLoginLogWriterClient,
|
||||
type LegacyLoginUserReaderClient,
|
||||
type LegacyUserWithoutPasswordReaderClient,
|
||||
} from "./users.server.js";
|
||||
|
||||
describe("findLegacyAuthUserById", () => {
|
||||
it("fetches only the legacy auth user fields by id", async () => {
|
||||
const findUnique = vi.fn().mockResolvedValue({
|
||||
id: "user_123",
|
||||
email: "user@example.com",
|
||||
passwordHash: "should-not-leak",
|
||||
});
|
||||
const client = {
|
||||
user: { findUnique },
|
||||
} as unknown as LegacyAuthUserReaderClient;
|
||||
|
||||
await expect(findLegacyAuthUserById("user_123", client)).resolves.toEqual({
|
||||
id: "user_123",
|
||||
email: "user@example.com",
|
||||
});
|
||||
expect(findUnique).toHaveBeenCalledWith({
|
||||
where: { id: "user_123" },
|
||||
select: { id: true, email: true },
|
||||
});
|
||||
});
|
||||
|
||||
it("returns null when the user does not exist", async () => {
|
||||
const client: LegacyAuthUserReaderClient = {
|
||||
user: {
|
||||
findUnique: vi.fn().mockResolvedValue(null),
|
||||
},
|
||||
};
|
||||
|
||||
await expect(findLegacyAuthUserById("missing", client)).resolves.toBeNull();
|
||||
});
|
||||
|
||||
it("fetches only the legacy login user fields by email", async () => {
|
||||
const findUnique = vi.fn().mockResolvedValue({
|
||||
id: "user_123",
|
||||
email: "user@example.com",
|
||||
passwordHash: "hash",
|
||||
firstName: "should-not-leak",
|
||||
});
|
||||
const client = {
|
||||
user: { findUnique },
|
||||
} as unknown as LegacyLoginUserReaderClient;
|
||||
|
||||
await expect(findLegacyLoginUserByEmail("user@example.com", client)).resolves.toEqual({
|
||||
id: "user_123",
|
||||
email: "user@example.com",
|
||||
passwordHash: "hash",
|
||||
});
|
||||
expect(findUnique).toHaveBeenCalledWith({
|
||||
where: { email: "user@example.com" },
|
||||
select: { id: true, email: true, passwordHash: true },
|
||||
});
|
||||
});
|
||||
|
||||
it("returns null when the login user does not exist", async () => {
|
||||
const client: LegacyLoginUserReaderClient = {
|
||||
user: {
|
||||
findUnique: vi.fn().mockResolvedValue(null),
|
||||
},
|
||||
};
|
||||
|
||||
await expect(findLegacyLoginUserByEmail("missing@example.com", client)).resolves.toBeNull();
|
||||
});
|
||||
|
||||
it("fetches the legacy user fields required by API bearer auth", async () => {
|
||||
const user = {
|
||||
id: "user_123",
|
||||
email: "user@example.com",
|
||||
firstName: "Ada",
|
||||
lastName: "Lovelace",
|
||||
avatar: null,
|
||||
phone: null,
|
||||
admin: null,
|
||||
defaultTenantId: null,
|
||||
createdAt: new Date("2026-05-01T00:00:00.000Z"),
|
||||
locale: "de",
|
||||
};
|
||||
const findUnique = vi.fn().mockResolvedValue(user);
|
||||
const client = {
|
||||
user: { findUnique },
|
||||
} as unknown as LegacyUserWithoutPasswordReaderClient;
|
||||
|
||||
await expect(findLegacyUserWithoutPasswordById("user_123", client)).resolves.toBe(user);
|
||||
expect(findUnique).toHaveBeenCalledWith({
|
||||
where: { id: "user_123" },
|
||||
select: {
|
||||
id: true,
|
||||
email: true,
|
||||
firstName: true,
|
||||
lastName: true,
|
||||
avatar: true,
|
||||
phone: true,
|
||||
admin: true,
|
||||
defaultTenantId: true,
|
||||
createdAt: true,
|
||||
locale: true,
|
||||
lightOrDarkMode: true,
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it("returns null when no legacy user id is provided", async () => {
|
||||
const client: LegacyUserWithoutPasswordReaderClient = {
|
||||
user: {
|
||||
findUnique: vi.fn(),
|
||||
},
|
||||
};
|
||||
|
||||
await expect(findLegacyUserWithoutPasswordById(undefined, client)).resolves.toBeNull();
|
||||
expect(client.user.findUnique).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("records legacy login logs", async () => {
|
||||
const create = vi.fn().mockResolvedValue({});
|
||||
const client: LegacyLoginLogWriterClient = {
|
||||
log: { create },
|
||||
};
|
||||
|
||||
await recordLegacyLogin("user_123", client);
|
||||
|
||||
expect(create).toHaveBeenCalledWith({
|
||||
data: {
|
||||
userId: "user_123",
|
||||
url: "",
|
||||
action: "Login",
|
||||
details: "",
|
||||
},
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user