test-order-of-album-groups.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import * as util from 'util';
  2. export default function({
  3. albumData,
  4. groupCategoryData,
  5. }) {
  6. const groupSchemaTemplate = [
  7. ['Projects beyond Homestuck', 'Fandom projects'],
  8. ['Solo musicians', 'Fan-musician groups'],
  9. ['HSMusic'],
  10. ];
  11. const groupSchema =
  12. groupSchemaTemplate.map(names => names.flatMap(
  13. name => groupCategoryData
  14. .find(gc => gc.name === name)
  15. .groups));
  16. const badAlbums = albumData.filter(album => {
  17. const groups = album.groups.slice();
  18. const disallowed = [];
  19. for (const allowed of groupSchema) {
  20. while (groups.length) {
  21. if (disallowed.includes(groups[0]))
  22. return true;
  23. else if (allowed.includes(groups[0]))
  24. groups.shift();
  25. else break;
  26. }
  27. disallowed.push(...allowed);
  28. }
  29. return false;
  30. });
  31. if (!badAlbums.length) return true;
  32. console.log(`Some albums don't list their groups in the right order:`);
  33. for (const album of badAlbums) {
  34. console.log('-', album);
  35. for (const group of album.groups) {
  36. console.log(` - ${util.inspect(group)}`)
  37. }
  38. }
  39. console.log(`Here's the group schema they should be updated to match:`);
  40. for (const section of groupSchemaTemplate) {
  41. if (section.length > 1) {
  42. console.log(`- Groups from any of: ${section.join(', ')}`);
  43. } else {
  44. console.log(`- Groups from: ${section}`);
  45. }
  46. }
  47. return false;
  48. }