Update hivegrid-cloud reference to latest main
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
e98d38e716
commit
7b21524c86
3781 files changed
+373484
-225607
No files matched your search
+46
@@ -155,4 +155,50 @@ describe("recovery-codes.server", () => {
|
||||
expect(consumed.usedAt).toBeInstanceOf(Date);
|
||||
expect(consumed.entries[0].usedAt).toBe(consumed.usedAt);
|
||||
});
|
||||
|
||||
test("rejects non-positive and non-integer count, segment, and segment-length parameters", async () => {
|
||||
const { generateRecoveryCode, generateRecoveryCodes, normalizeRecoveryCode } = await import("./recovery-codes.server");
|
||||
|
||||
// Integer-but-non-positive values reach the `value <= 0` guard branch...
|
||||
expect(() => generateRecoveryCode({ segments: 0 })).toThrow("segments must be a positive integer");
|
||||
expect(() => generateRecoveryCode({ segmentLength: -1 })).toThrow("segmentLength must be a positive integer");
|
||||
expect(() => generateRecoveryCodes({ count: 0 })).toThrow("count must be a positive integer");
|
||||
expect(() => normalizeRecoveryCode("2345-6789-ABCD", { segments: 0 })).toThrow("segments must be a positive integer");
|
||||
expect(() => normalizeRecoveryCode("2345-6789-ABCD", { segmentLength: 0 })).toThrow("segmentLength must be a positive integer");
|
||||
// ...while a fractional value trips the `!Number.isInteger(value)` guard first.
|
||||
expect(() => generateRecoveryCode({ segments: 2.5 })).toThrow("segments must be a positive integer");
|
||||
});
|
||||
|
||||
test("generateRecoveryCode honours explicit shapes and falls back to the default segment layout", async () => {
|
||||
const { generateRecoveryCode } = await import("./recovery-codes.server");
|
||||
|
||||
// No options → both `??` defaults are exercised (3 segments × 4 chars).
|
||||
expect(generateRecoveryCode()).toMatch(codePattern);
|
||||
// Explicit options → the provided values win over the defaults.
|
||||
expect(generateRecoveryCode({ segments: 2, segmentLength: 5 })).toMatch(
|
||||
/^[23456789ABCDEFGHJKLMNPQRSTUVWXYZ]{5}-[23456789ABCDEFGHJKLMNPQRSTUVWXYZ]{5}$/,
|
||||
);
|
||||
});
|
||||
|
||||
test("status helper keeps the most recent usage timestamp and stays null-safe when the first entry lacks a creation date", async () => {
|
||||
const { getRecoveryCodeStatus } = await import("./recovery-codes.server");
|
||||
|
||||
// Two used entries with the later one first forces the reduce to keep the
|
||||
// running `latest` (the `entry > latest` comparison resolves to false), and
|
||||
// an undefined `createdAt` on the first entry exercises the `?? null`
|
||||
// fallback for `generatedAt`.
|
||||
const entries = [
|
||||
{ hash: "aa", usedAt: new Date("2026-05-08T10:00:00.000Z"), createdAt: undefined as unknown as Date },
|
||||
{ hash: "bb", usedAt: new Date("2026-05-08T09:00:00.000Z"), createdAt: new Date("2026-05-08T08:00:00.000Z") },
|
||||
];
|
||||
|
||||
expect(getRecoveryCodeStatus(entries)).toEqual({
|
||||
configured: true,
|
||||
totalCount: 2,
|
||||
remainingCount: 0,
|
||||
usedCount: 2,
|
||||
generatedAt: null,
|
||||
lastUsedAt: new Date("2026-05-08T10:00:00.000Z"),
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user