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
+31
-1
@@ -2,10 +2,13 @@ import { describe, expect, it, vi } from "vitest";
|
||||
|
||||
import {
|
||||
findLegacyUserWithoutPasswordById,
|
||||
upgradeLegacyUserPasswordHash,
|
||||
updateLegacyUserDefaultTenantId,
|
||||
type LegacyUserDefaultTenantWriterClient,
|
||||
type LegacyUserPasswordHashWriterClient,
|
||||
type LegacyUserWithoutPasswordReaderClient,
|
||||
} from "./users.server.js";
|
||||
import { getRlsExecutionContext } from "./rls-context.server.js";
|
||||
|
||||
describe("findLegacyUserWithoutPasswordById error handling", () => {
|
||||
it("returns null instead of propagating a read failure", async () => {
|
||||
@@ -22,7 +25,10 @@ describe("findLegacyUserWithoutPasswordById error handling", () => {
|
||||
|
||||
describe("updateLegacyUserDefaultTenantId", () => {
|
||||
it("updates the default tenant for a valid user id", async () => {
|
||||
const update = vi.fn().mockResolvedValue({ id: "user_1", defaultTenantId: "tenant_2" });
|
||||
const update = vi.fn().mockImplementation(async () => {
|
||||
expect(getRlsExecutionContext()?.userId).toBe("user_1");
|
||||
return { id: "user_1", defaultTenantId: "tenant_2" };
|
||||
});
|
||||
const client = { user: { update } } as unknown as LegacyUserDefaultTenantWriterClient;
|
||||
|
||||
const result = await updateLegacyUserDefaultTenantId({ defaultTenantId: "tenant_2" }, "user_1", client);
|
||||
@@ -42,3 +48,27 @@ describe("updateLegacyUserDefaultTenantId", () => {
|
||||
expect(update).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe("upgradeLegacyUserPasswordHash", () => {
|
||||
it("performs the compare-and-swap update in the user's RLS context", async () => {
|
||||
const updateMany = vi.fn().mockImplementation(async () => {
|
||||
expect(getRlsExecutionContext()?.userId).toBe("user_1");
|
||||
return { count: 1 };
|
||||
});
|
||||
const client = { user: { updateMany } } as unknown as LegacyUserPasswordHashWriterClient;
|
||||
|
||||
await expect(upgradeLegacyUserPasswordHash("user_1", "old_hash", "new_hash", client)).resolves.toBe(true);
|
||||
expect(updateMany).toHaveBeenCalledWith({
|
||||
where: { id: "user_1", passwordHash: "old_hash" },
|
||||
data: { passwordHash: "new_hash" },
|
||||
});
|
||||
});
|
||||
|
||||
it("returns false when the password hash changed concurrently", async () => {
|
||||
const client = {
|
||||
user: { updateMany: vi.fn().mockResolvedValue({ count: 0 }) },
|
||||
} as unknown as LegacyUserPasswordHashWriterClient;
|
||||
|
||||
await expect(upgradeLegacyUserPasswordHash("user_1", "stale_hash", "new_hash", client)).resolves.toBe(false);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user