From a45eeedc1bf3dd7749437ae44d6aa5d4d242ac77 Mon Sep 17 00:00:00 2001 From: Jon <66625200+Kyro3400@users.noreply.github.com> Date: Mon, 11 Nov 2024 20:18:14 -0500 Subject: [PATCH] Create domains.test.js --- tests/domains.test.js | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 tests/domains.test.js diff --git a/tests/domains.test.js b/tests/domains.test.js new file mode 100644 index 00000000..eddb7833 --- /dev/null +++ b/tests/domains.test.js @@ -0,0 +1,35 @@ +const t = require("ava"); +const fs = require("fs-extra"); +const path = require("path"); + +const domainsPath = path.resolve("domains"); +const files = fs.readdirSync(domainsPath); + +t("Nested subdomains should not exist without a parent subdomain", (t) => { + files.forEach((file) => { + const subdomain = file.replace(".json", ""); + + if (subdomain.split(".").length > 1) { + const parentSubdomain = subdomain.split(".").pop(); + + t.true(files.includes(`${parentSubdomain}.json`), `${file}: Parent subdomain does not exist`); + } + }); + + t.pass(); +}); + +t("Nested subdomains should not exist if the parent subdomain has NS records", (t) => { + files.forEach((file) => { + const subdomain = file.replace(".json", ""); + + if (subdomain.split(".").length > 1) { + const parentSubdomain = subdomain.split(".").pop(); + const parentDomain = fs.readJsonSync(path.join(domainsPath, `${parentSubdomain}.json`)); + + t.is(parentDomain.record.NS, undefined, `${file}: Parent subdomain has NS records`); + } + }); + + t.pass(); +});