Rallly is an open-source scheduling and collaboration tool designed to make organizing events and meetings easier.
TypeScript i18nextnext-authnextjspostgresqlprismareact-emailt3-stacktailwindcsstrpcturborepotypescriptzod
import { afterEach, describe, expect, it, vi } from "vitest";
import { isEmailBlocked } from "./utils";
describe("isEmailBlocked", () => {
afterEach(() => {
vi.unstubAllEnvs();
});
it("allows all emails when ALLOWED_EMAILS is not set", () => {
vi.stubEnv("ALLOWED_EMAILS", "");
expect(isEmailBlocked("[email protected]")).toBe(false);
});
it("allows an email matching a wildcard pattern", () => {
vi.stubEnv("ALLOWED_EMAILS", "*@company.com");
expect(isEmailBlocked("[email protected]")).toBe(false);
});
it("blocks an email that matches no pattern", () => {
vi.stubEnv("ALLOWED_EMAILS", "*@company.com");
expect(isEmailBlocked("[email protected]")).toBe(true);
});
it("matches case-insensitively", () => {
vi.stubEnv("ALLOWED_EMAILS", "*@company.com");
expect(isEmailBlocked("[email protected]")).toBe(false);
});
it("ignores whitespace around comma-separated patterns", () => {
vi.stubEnv("ALLOWED_EMAILS", "*@company.com, *@example.com");
expect(isEmailBlocked("[email protected]")).toBe(false);
});
it("ignores empty entries from trailing commas", () => {
vi.stubEnv("ALLOWED_EMAILS", "*@company.com,");
expect(isEmailBlocked("[email protected]")).toBe(true);
});
it("allows an exact email entry regardless of case", () => {
vi.stubEnv("ALLOWED_EMAILS", "[email protected]");
expect(isEmailBlocked("[email protected]")).toBe(false);
});
it("does not treat pattern dots as regex wildcards", () => {
vi.stubEnv("ALLOWED_EMAILS", "*@company.com");
expect(isEmailBlocked("user@companyxcom")).toBe(true);
});
});