mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-08-21 06:32:16 +03:00
Updated mask-email.test.mjs and model-sync-route.test.mjs to match the revised maskEmail function that preserves full domain names for account differentiation (die********@gmail.com vs old di*********@g****.com).
69 lines
2.2 KiB
JavaScript
69 lines
2.2 KiB
JavaScript
import { describe, it } from "node:test";
|
|
import assert from "node:assert/strict";
|
|
import {
|
|
maskEmail,
|
|
maskEmailLikeValue,
|
|
pickMaskedDisplayValue,
|
|
} from "../../src/shared/utils/maskEmail.ts";
|
|
|
|
describe("maskEmail", () => {
|
|
it("masks standard email correctly", () => {
|
|
assert.equal(maskEmail("diego.souza@gmail.com"), "die********@gmail.com");
|
|
});
|
|
|
|
it("masks email with short username (exactly visibleChars)", () => {
|
|
// username "ab" has length 2 = visibleChars, so returns as-is
|
|
assert.equal(maskEmail("ab@gmail.com"), "ab@gmail.com");
|
|
});
|
|
|
|
it("masks email with longer username", () => {
|
|
const result = maskEmail("hello@example.com");
|
|
assert.equal(result, "hel**@example.com");
|
|
});
|
|
|
|
it("returns empty string for null", () => {
|
|
assert.equal(maskEmail(null), "");
|
|
});
|
|
|
|
it("returns empty string for undefined", () => {
|
|
assert.equal(maskEmail(undefined), "");
|
|
});
|
|
|
|
it("returns empty string for empty string", () => {
|
|
assert.equal(maskEmail(""), "");
|
|
});
|
|
|
|
it("returns original if no @ symbol", () => {
|
|
assert.equal(maskEmail("notanemail"), "notanemail");
|
|
});
|
|
|
|
it("handles multi-part TLDs correctly", () => {
|
|
const result = maskEmail("user@company.co.uk");
|
|
assert.ok(result.endsWith(".co.uk"), `Expected .co.uk suffix, got: ${result}`);
|
|
assert.ok(result.includes("@"), "Should contain @");
|
|
});
|
|
|
|
it("handles single-char domain name", () => {
|
|
const result = maskEmail("user@x.com");
|
|
assert.ok(result.includes("@x.com"), `Expected @x.com in: ${result}`);
|
|
});
|
|
|
|
it("allows customizing visibleChars", () => {
|
|
const result = maskEmail("hello@example.com", 3);
|
|
assert.ok(result.startsWith("hel"), `Expected to start with 'hel', got: ${result}`);
|
|
});
|
|
|
|
it("masks email-like values stored in generic labels", () => {
|
|
assert.equal(maskEmailLikeValue("person@example.com"), "per***@example.com");
|
|
assert.equal(maskEmailLikeValue("Work Account"), "Work Account");
|
|
});
|
|
|
|
it("picks the first non-empty masked display value", () => {
|
|
assert.equal(
|
|
pickMaskedDisplayValue(["", "person@example.com", "fallback"], "fallback"),
|
|
"per***@example.com"
|
|
);
|
|
assert.equal(pickMaskedDisplayValue([null, "Workspace"], "fallback"), "Workspace");
|
|
});
|
|
});
|