Refresh HiveGrid Cloud reference snapshot
This commit is contained in:
1 parent
5e99e14772
commit
7f88026f79
5955 files changed
+1177325
-188362
No files matched your search
+30
-1
@@ -7,16 +7,19 @@ vi.mock("../db.server", () => {
|
||||
log: {
|
||||
groupBy: vi.fn(),
|
||||
findMany: vi.fn(),
|
||||
create: vi.fn(),
|
||||
},
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
import { db } from "../db.server";
|
||||
import { getLastUserLogsByUserIds } from "./logs.db.server";
|
||||
import { getRlsExecutionContext } from "@hivegrid/db/rls-context.server";
|
||||
import { createLogLogin, getLastUserLogsByUserIds } from "./logs.db.server";
|
||||
|
||||
const groupBy = db.log.groupBy as unknown as ReturnType<typeof vi.fn>;
|
||||
const findMany = db.log.findMany as unknown as ReturnType<typeof vi.fn>;
|
||||
const create = db.log.create as unknown as ReturnType<typeof vi.fn>;
|
||||
|
||||
describe("getLastUserLogsByUserIds", () => {
|
||||
beforeEach(() => {
|
||||
@@ -55,6 +58,12 @@ describe("getLastUserLogsByUserIds", () => {
|
||||
where: { userId: { in: userIds } },
|
||||
_max: { createdAt: true },
|
||||
});
|
||||
expect(findMany).toHaveBeenCalledWith({
|
||||
where: {
|
||||
OR: Object.entries(newest).map(([userId, createdAt]) => ({ userId, createdAt })),
|
||||
},
|
||||
select: { id: true, userId: true, action: true, createdAt: true },
|
||||
});
|
||||
expect(result.get("u1")).toMatchObject({ id: "log-u1", userId: "u1" });
|
||||
expect(result.get("u3")).toMatchObject({ id: "log-u3" });
|
||||
expect(result.size).toBe(3);
|
||||
@@ -70,3 +79,23 @@ describe("getLastUserLogsByUserIds", () => {
|
||||
expect(result.size).toBe(0);
|
||||
});
|
||||
});
|
||||
|
||||
describe("identity-owned authentication logs", () => {
|
||||
it("creates a pre-tenant login log inside the user's RLS context", async () => {
|
||||
create.mockImplementationOnce(async () => {
|
||||
expect(getRlsExecutionContext()).toMatchObject({ userId: "user_1" });
|
||||
return {};
|
||||
});
|
||||
|
||||
await createLogLogin(new Request("https://app.example.test/login"), { id: "user_1" } as never);
|
||||
|
||||
expect(create).toHaveBeenCalledWith({
|
||||
data: {
|
||||
userId: "user_1",
|
||||
url: "",
|
||||
action: "Login",
|
||||
details: "",
|
||||
},
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user