Update domains.test.js

This commit is contained in:
Jon authored and GitHub committed 2024-11-17 16:40:03 -05:00
1 parent be09e47c82
commit 6fd20b1c7d
1 file changed
+24 -4
+24 -4
View File
@@ -7,12 +7,20 @@ const files = fs.readdirSync(domainsPath);
t("Nested subdomains should not exist without a parent subdomain", (t) => {
files.forEach((file) => {
// Skip directories and process only .json files
const filePath = path.join(domainsPath, file);
if (fs.lstatSync(filePath).isDirectory()) {
return; // Skip directories
}
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.true(
files.includes(`${parentSubdomain}.json`),
`${file}: Parent subdomain does not exist`
);
}
});
@@ -21,13 +29,25 @@ t("Nested subdomains should not exist without a parent subdomain", (t) => {
t("Nested subdomains should not exist if the parent subdomain has NS records", (t) => {
files.forEach((file) => {
// Skip directories and process only .json files
const filePath = path.join(domainsPath, file);
if (fs.lstatSync(filePath).isDirectory()) {
return; // Skip directories
}
const subdomain = file.replace(".json", "");
if (subdomain.split(".").length > 1) {
const parentSubdomain = subdomain.split(".").pop();
const parentDomain = fs.readJsonSync(path.join(domainsPath, `${parentSubdomain}.json`));
const parentFilePath = path.join(domainsPath, `${parentSubdomain}.json`);
t.is(parentDomain.record.NS, undefined, `${file}: Parent subdomain has NS records`);
// Check if the parent file exists before attempting to read it
if (fs.existsSync(parentFilePath)) {
const parentDomain = fs.readJsonSync(parentFilePath);
t.is(parentDomain.record.NS, undefined, `${file}: Parent subdomain has NS records`);
} else {
t.fail(`${parentSubdomain}.json file does not exist`);
}
}
});