centralize email parsing logic

This commit is contained in:
Tom Moor
2024-07-07 10:54:19 -04:00
parent c484d1defe
commit bdcde1aa53
8 changed files with 52 additions and 9 deletions

View File

@@ -0,0 +1,24 @@
import { parseEmail } from "./email";
describe("parseEmail", () => {
it("should correctly parse email", () => {
expect(parseEmail("tom@example.com")).toEqual({
local: "tom",
domain: "example.com",
});
expect(parseEmail("tom.m@example.com")).toEqual({
local: "tom.m",
domain: "example.com",
});
expect(parseEmail("tom@subdomain.domain.com")).toEqual({
local: "tom",
domain: "subdomain.domain.com",
});
});
it("should throw error for invalid email", () => {
expect(() => parseEmail("")).toThrow();
expect(() => parseEmail("invalid")).toThrow();
expect(() => parseEmail("invalid@")).toThrow();
});
});