-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.test.js
55 lines (52 loc) · 1.18 KB
/
index.test.js
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
import test from "node:test";
import assert from "node:assert";
import { isOneTimeMail } from "./index.js";
const ENOTFOUND = new Error("ENOTFOUND");
ENOTFOUND.code = "ENOTFOUND";
const domains = [
{
domain: "google.com",
mx: ["smtp.google.com"],
a: ["64.233.180.26", "142.251.163.27"],
result: false,
},
{
domain: "belgianairways.com",
mx: ["in.mail.tm"],
result: true,
},
{
domain: "uentiheunsthieunst.com",
mx: ENOTFOUND,
result: false,
},
{
domain: "bad-ip.com",
mx: ["mail.bad-ip.com"],
result: true,
a: ["167.172.1.68"],
}
];
for (const domain of domains) {
test(`Check if ${domain.domain} has ${domain.mx}`, async (t) => {
assert.equal(
await isOneTimeMail(domain.domain, {
dns: {
resolveMx: async () => {
if (domain.mx instanceof Error) {
throw domain.mx;
}
return domain.mx.map((exchange) => ({ exchange }));
},
resolve4: async (host) => {
if (domain.a instanceof Error) {
throw domain.a;
}
return domain.a;
}
},
}),
domain.result
);
});
}