Improve invite handling
All checks were successful
Template Compliance / compliance (push) Successful in 5s
All checks were successful
Template Compliance / compliance (push) Successful in 5s
This commit is contained in:
28
tests/invites.test.ts
Normal file
28
tests/invites.test.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { inviteExpiresAt, isInviteExpired } from "../src/lib/invites";
|
||||
|
||||
const now = Date.UTC(2026, 0, 1);
|
||||
const day = 24 * 60 * 60 * 1000;
|
||||
|
||||
describe("inviteExpiresAt", () => {
|
||||
it("returns null for invalid or non-expiring values", () => {
|
||||
expect(inviteExpiresAt(null, now)).toBeNull();
|
||||
expect(inviteExpiresAt("0", now)).toBeNull();
|
||||
expect(inviteExpiresAt("-3", now)).toBeNull();
|
||||
expect(inviteExpiresAt("not-a-number", now)).toBeNull();
|
||||
});
|
||||
|
||||
it("creates an expiration date for valid day counts", () => {
|
||||
expect(inviteExpiresAt("7", now)?.getTime()).toBe(now + 7 * day);
|
||||
});
|
||||
|
||||
it("caps expiration at one year", () => {
|
||||
expect(inviteExpiresAt("9999", now)?.getTime()).toBe(now + 365 * day);
|
||||
});
|
||||
|
||||
it("detects expired invite timestamps", () => {
|
||||
expect(isInviteExpired(new Date(now - day), now)).toBe(true);
|
||||
expect(isInviteExpired(new Date(now + day), now)).toBe(false);
|
||||
expect(isInviteExpired(null, now)).toBe(false);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user