forked from baron/baron-sso
코드체크 실패 케이스 해결. 배치잡 야간 배정
This commit is contained in:
@@ -1,5 +1,10 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { cn } from "./utils";
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
import { cn, generateSecurePassword } from "./utils";
|
||||
|
||||
afterEach(() => {
|
||||
vi.restoreAllMocks();
|
||||
vi.unstubAllGlobals();
|
||||
});
|
||||
|
||||
describe("cn utility", () => {
|
||||
it("merges class names correctly", () => {
|
||||
@@ -11,3 +16,23 @@ describe("cn utility", () => {
|
||||
expect(cn("px-2 py-2", "px-4")).toBe("py-2 px-4");
|
||||
});
|
||||
});
|
||||
|
||||
describe("generateSecurePassword", () => {
|
||||
it("uses crypto random values when available", () => {
|
||||
vi.stubGlobal("crypto", {
|
||||
getRandomValues: vi.fn((values: Uint32Array) => {
|
||||
values.set([0, 1, 2, 3]);
|
||||
return values;
|
||||
}),
|
||||
});
|
||||
|
||||
expect(generateSecurePassword(4)).toBe("abcd");
|
||||
});
|
||||
|
||||
it("falls back to Math.random when crypto is unavailable", () => {
|
||||
vi.stubGlobal("crypto", undefined);
|
||||
vi.spyOn(Math, "random").mockReturnValue(0);
|
||||
|
||||
expect(generateSecurePassword(3)).toBe("aaa");
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user