From c17b6404b8b8769d808b01f5f95e07f521983104 Mon Sep 17 00:00:00 2001 From: William Harrison <87287585+wdhdev@users.noreply.github.com> Date: Fri, 14 Mar 2025 16:34:23 +0800 Subject: [PATCH] move special tests to domains --- tests/domains.test.js | 36 ++++++++++++++++++++++++++++++ tests/special.test.js | 51 ------------------------------------------- 2 files changed, 36 insertions(+), 51 deletions(-) delete mode 100644 tests/special.test.js diff --git a/tests/domains.test.js b/tests/domains.test.js index 1804e5037..9df9598f4 100644 --- a/tests/domains.test.js +++ b/tests/domains.test.js @@ -64,3 +64,39 @@ t("Nested subdomains should be owned by the parent subdomain's owner", (t) => { } }); }); + +t("Users are limited to one single character subdomain", (t) => { + const results = []; + + files.forEach((file) => { + const subdomain = file.replace(/\.json$/, ""); + const data = getDomainData(subdomain); + + if (subdomain.length === 1 && data.owner.username.toLowerCase() !== "is-a-dev") { + results.push({ + subdomain, + owner: data.owner.username.toLowerCase() + }); + } + }); + + const duplicates = results.filter((result) => results.filter((r) => r.owner === result.owner).length > 1); + const output = duplicates.reduce((acc, curr) => { + if (!acc[curr.owner]) { + acc[curr.owner] = []; + } + + acc[curr.owner].push(`${curr.subdomain}.is-a.dev`); + return acc; + }, {}); + + t.is( + duplicates.length, + 0, + Object.keys(output) + .map((owner) => `${owner} - ${output[owner].join(", ")}`) + .join("\n") + ); + + t.pass(); +}); diff --git a/tests/special.test.js b/tests/special.test.js deleted file mode 100644 index eb8ca52e0..000000000 --- a/tests/special.test.js +++ /dev/null @@ -1,51 +0,0 @@ -const t = require("ava"); -const fs = require("fs-extra"); -const path = require("path"); - -const domainsPath = path.resolve("domains"); -const files = fs.readdirSync(domainsPath).filter((file) => file.endsWith(".json")); - -function getDomainData(subdomain) { - try { - const data = fs.readJsonSync(path.join(domainsPath, `${subdomain}.json`)); - return data; - } catch (error) { - throw new Error(`Failed to read JSON for ${subdomain}: ${error.message}`); - } -} - -t("Users are limited to one single character subdomain", (t) => { - const results = []; - - files.forEach((file) => { - const subdomain = file.replace(/\.json$/, ""); - const data = getDomainData(subdomain); - - if (subdomain.length === 1 && data.owner.username.toLowerCase() !== "is-a-dev") { - results.push({ - subdomain, - owner: data.owner.username.toLowerCase() - }); - } - }); - - const duplicates = results.filter((result) => results.filter((r) => r.owner === result.owner).length > 1); - const output = duplicates.reduce((acc, curr) => { - if (!acc[curr.owner]) { - acc[curr.owner] = []; - } - - acc[curr.owner].push(`${curr.subdomain}.is-a.dev`); - return acc; - }, {}); - - t.is( - duplicates.length, - 0, - Object.keys(output) - .map((owner) => `${owner} - ${output[owner].join(", ")}`) - .join("\n") - ); - - t.pass(); -});