« get me outta code hell

data steps: move data-tests outside tests - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/data-tests/test-order-of-album-groups.js
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2023-03-25 14:19:23 -0300
committer(quasar) nebula <qznebula@protonmail.com>2023-03-25 14:19:23 -0300
commitfad524ed133af6f094357b94da54e616c7f943b6 (patch)
tree89482c00ea3ffdd0ed2ca7625887c9f077f7a560 /data-tests/test-order-of-album-groups.js
parent8ab00d99fa2f14ac983f0693552b26e4050a939c (diff)
data steps: move data-tests outside tests
These are mostly short REPL-like scripts for testing
actual wiki data, not the codebase. They don't really
belong in the repo at all, but actually cause trouble
by living in the main tests directory!
Diffstat (limited to 'data-tests/test-order-of-album-groups.js')
-rw-r--r--data-tests/test-order-of-album-groups.js55
1 files changed, 55 insertions, 0 deletions
diff --git a/data-tests/test-order-of-album-groups.js b/data-tests/test-order-of-album-groups.js
new file mode 100644
index 00000000..de2fcbed
--- /dev/null
+++ b/data-tests/test-order-of-album-groups.js
@@ -0,0 +1,55 @@
+import * as util from 'util';
+
+export default function({
+  albumData,
+  groupCategoryData,
+}) {
+  const groupSchemaTemplate = [
+    ['Projects beyond Homestuck', 'Fandom projects'],
+    ['Solo musicians', 'Fan-musician groups'],
+    ['HSMusic'],
+  ];
+
+  const groupSchema =
+    groupSchemaTemplate.map(names => names.flatMap(
+      name => groupCategoryData
+        .find(gc => gc.name === name)
+        .groups));
+
+  const badAlbums = albumData.filter(album => {
+    const groups = album.groups.slice();
+    const disallowed = [];
+    for (const allowed of groupSchema) {
+      while (groups.length) {
+        if (disallowed.includes(groups[0]))
+          return true;
+        else if (allowed.includes(groups[0]))
+          groups.shift();
+        else break;
+      }
+      disallowed.push(...allowed);
+    }
+    return false;
+  });
+
+  if (!badAlbums.length) return true;
+
+  console.log(`Some albums don't list their groups in the right order:`);
+  for (const album of badAlbums) {
+    console.log('-', album);
+    for (const group of album.groups) {
+      console.log(`  - ${util.inspect(group)}`)
+    }
+  }
+
+  console.log(`Here's the group schema they should be updated to match:`);
+  for (const section of groupSchemaTemplate) {
+    if (section.length > 1) {
+      console.log(`- Groups from any of: ${section.join(', ')}`);
+    } else {
+      console.log(`- Groups from: ${section}`);
+    }
+  }
+
+  return false;
+}