1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
import { isEmailOrPhoneNumber } from "content-src/asrouter/templates/SendToDeviceSnippet/isEmailOrPhoneNumber";
const CONTENT = {};
describe("isEmailOrPhoneNumber", () => {
it("should return 'email' for emails", () => {
assert.equal(isEmailOrPhoneNumber("foobar@asd.com", CONTENT), "email");
assert.equal(isEmailOrPhoneNumber("foobar@asd.co.uk", CONTENT), "email");
});
it("should return 'phone' for valid en-US/en-CA phone numbers", () => {
assert.equal(
isEmailOrPhoneNumber("14582731273", { locale: "en-US" }),
"phone"
);
assert.equal(
isEmailOrPhoneNumber("4582731273", { locale: "en-CA" }),
"phone"
);
});
it("should return an empty string for invalid phone number lengths in en-US/en-CA", () => {
// Not enough digits
assert.equal(isEmailOrPhoneNumber("4522", { locale: "en-US" }), "");
assert.equal(isEmailOrPhoneNumber("4522", { locale: "en-CA" }), "");
});
it("should return 'phone' for valid German phone numbers", () => {
assert.equal(
isEmailOrPhoneNumber("145827312732", { locale: "de" }),
"phone"
);
});
it("should return 'phone' for any number of digits in other locales", () => {
assert.equal(isEmailOrPhoneNumber("4", CONTENT), "phone");
});
it("should return an empty string for other invalid inputs", () => {
assert.equal(
isEmailOrPhoneNumber("abc", CONTENT),
"",
"abc should be invalid"
);
assert.equal(
isEmailOrPhoneNumber("abc@", CONTENT),
"",
"abc@ should be invalid"
);
assert.equal(
isEmailOrPhoneNumber("abc@foo", CONTENT),
"",
"abc@foo should be invalid"
);
assert.equal(
isEmailOrPhoneNumber("123d1232", CONTENT),
"",
"123d1232 should be invalid"
);
});
});
|