55 lines
1.6 KiB
TypeScript
55 lines
1.6 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import {
|
|
formatInviteCountWord,
|
|
parseInvitePaste,
|
|
splitInvitePasteTokens,
|
|
} from "../../lib/create/parseInviteEmails";
|
|
|
|
describe("parseInviteEmails", () => {
|
|
it("splits comma, semicolon, and whitespace lists", () => {
|
|
expect(
|
|
splitInvitePasteTokens("rosa@example.org, dev@example.org; sam@example.org\nlee@example.org"),
|
|
).toEqual([
|
|
"rosa@example.org",
|
|
"dev@example.org",
|
|
"sam@example.org",
|
|
"lee@example.org",
|
|
]);
|
|
});
|
|
|
|
it("adds valid addresses and leaves invalid tokens in the remainder", () => {
|
|
const result = parseInvitePaste(
|
|
"rosa@example.org, jo@example, sam@example.org",
|
|
["maya@example.org"],
|
|
30,
|
|
);
|
|
expect(result.added).toEqual(["rosa@example.org", "sam@example.org"]);
|
|
expect(result.invalidRemainder).toBe("jo@example");
|
|
});
|
|
|
|
it("skips duplicates already on the list", () => {
|
|
const result = parseInvitePaste(
|
|
"maya@example.org, rosa@example.org",
|
|
["maya@example.org"],
|
|
30,
|
|
);
|
|
expect(result.added).toEqual(["rosa@example.org"]);
|
|
expect(result.skippedDuplicate).toBe(1);
|
|
});
|
|
|
|
it("keeps overflow addresses in the remainder once the max is hit", () => {
|
|
const result = parseInvitePaste(
|
|
"a@example.org, b@example.org, c@example.org",
|
|
[],
|
|
2,
|
|
);
|
|
expect(result.added).toEqual(["a@example.org", "b@example.org"]);
|
|
expect(result.invalidRemainder).toBe("c@example.org");
|
|
});
|
|
|
|
it("uses words for counts through ten", () => {
|
|
expect(formatInviteCountWord(5)).toBe("five");
|
|
expect(formatInviteCountWord(11)).toBe("11");
|
|
});
|
|
});
|