|
1 | 1 | import { describe, it, expect } from "@jest/globals"; |
2 | | -import { isDatabaseUrl } from "./validators"; |
| 2 | +import { isDatabaseUrl, isMailboxAddress } from "./validators"; |
3 | 3 |
|
4 | 4 | describe("isDatabaseUrl", () => { |
5 | 5 | const defaultOptions = { |
@@ -249,3 +249,70 @@ describe("isDatabaseUrl", () => { |
249 | 249 | }); |
250 | 250 | }); |
251 | 251 | }); |
| 252 | + |
| 253 | +describe("isMailboxAddress", () => { |
| 254 | + describe("plain email addresses", () => { |
| 255 | + it("should accept a plain email address", () => { |
| 256 | + expect(isMailboxAddress("user@example.com")).toBe(true); |
| 257 | + }); |
| 258 | + |
| 259 | + it("should accept an email with IP domain", () => { |
| 260 | + expect(isMailboxAddress("user@192.168.1.1")).toBe(true); |
| 261 | + }); |
| 262 | + |
| 263 | + it("should reject an invalid email address", () => { |
| 264 | + expect(isMailboxAddress("notanemail")).toBe(false); |
| 265 | + }); |
| 266 | + |
| 267 | + it("should reject an email without domain", () => { |
| 268 | + expect(isMailboxAddress("user@")).toBe(false); |
| 269 | + }); |
| 270 | + }); |
| 271 | + |
| 272 | + describe("mailbox format addresses", () => { |
| 273 | + it("should accept a simple mailbox format", () => { |
| 274 | + expect(isMailboxAddress("Outline <user@example.com>")).toBe(true); |
| 275 | + }); |
| 276 | + |
| 277 | + it("should accept a mailbox format with a period in the display name", () => { |
| 278 | + expect(isMailboxAddress("My App v1.0 <user@example.com>")).toBe(true); |
| 279 | + }); |
| 280 | + |
| 281 | + it("should accept a mailbox format with quoted display name containing a comma", () => { |
| 282 | + expect( |
| 283 | + isMailboxAddress('"Company, Inc." <user@example.com>') |
| 284 | + ).toBe(true); |
| 285 | + }); |
| 286 | + |
| 287 | + it("should accept a mailbox format with a quoted display name", () => { |
| 288 | + expect(isMailboxAddress('"Outline" <user@example.com>')).toBe(true); |
| 289 | + }); |
| 290 | + |
| 291 | + it("should reject a mailbox format with an unquoted comma in the display name", () => { |
| 292 | + // addressparser splits on commas, so this creates two addresses |
| 293 | + expect(isMailboxAddress("Company, Inc. <user@example.com>")).toBe(false); |
| 294 | + }); |
| 295 | + |
| 296 | + it("should reject a mailbox format with an empty email address", () => { |
| 297 | + expect(isMailboxAddress("Outline <>")).toBe(false); |
| 298 | + }); |
| 299 | + |
| 300 | + it("should reject a mailbox format with an invalid email address", () => { |
| 301 | + expect(isMailboxAddress("Outline <notanemail>")).toBe(false); |
| 302 | + }); |
| 303 | + }); |
| 304 | + |
| 305 | + describe("edge cases", () => { |
| 306 | + it("should reject an empty string", () => { |
| 307 | + expect(isMailboxAddress("")).toBe(false); |
| 308 | + }); |
| 309 | + |
| 310 | + it("should reject a string with only spaces", () => { |
| 311 | + expect(isMailboxAddress(" ")).toBe(false); |
| 312 | + }); |
| 313 | + |
| 314 | + it("should reject a group address", () => { |
| 315 | + expect(isMailboxAddress("Group: user@example.com;")).toBe(false); |
| 316 | + }); |
| 317 | + }); |
| 318 | +}); |
0 commit comments