-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.test.ts
32 lines (30 loc) · 1.87 KB
/
index.test.ts
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
import {caa, caaMatches} from "./index.ts";
test("tests", async () => {
const tests = [
{promise: caa("silverwind.io"), expect: records => records.map(r => r.value).includes("letsencrypt.org")},
{promise: caa("sub.silverwind.io"), expect: records => records.map(r => r.value).includes("letsencrypt.org")},
{promise: caa("caa-multi.silverwind.io"), expect: records => records.length > 1},
{promise: caa("cname-caa-multi.silverwind.io"), expect: records => records.length > 1},
{promise: caaMatches("silverwind.io", "letsencrypt.org"), expect: true},
{promise: caaMatches("sub.silverwind.io", "letsencrypt.org"), expect: true},
{promise: caaMatches("caa-none.silverwind.io", "letsencrypt.org"), expect: false},
{promise: caaMatches("sub.caa-none.silverwind.io", "letsencrypt.org"), expect: false},
{promise: caaMatches("caa-wild.silverwind.io", "letsencrypt.org"), expect: true},
{promise: caaMatches("*.caa-wild.silverwind.io", "letsencrypt.org"), expect: false},
{promise: caaMatches("sub.caa-wild.silverwind.io", "letsencrypt.org"), expect: true},
{promise: caaMatches("caa-none-cname.silverwind.io", "letsencrypt.org"), expect: false},
{promise: caaMatches("caa-cname.silverwind.io", "letsencrypt.org"), expect: true},
{promise: caaMatches("caa-multi.silverwind.io", "first.com"), expect: true},
{promise: caaMatches("caa-multi.silverwind.io", "second.com"), expect: true},
{promise: caaMatches("cname-caa-multi.silverwind.io", "first.com"), expect: true},
{promise: caaMatches("cname-caa-multi.silverwind.io", "second.com"), expect: true},
];
for (const [i, result] of Object.entries(await Promise.all(tests.map(test => test.promise)))) {
const expected = tests[i].expect;
if (typeof expected === "function") {
expect(expected(result)).toBeTruthy();
} else {
expect(result).toEqual(expected);
}
}
});