« get me outta code hell

test: general refactor instantiating things & managing wikiData - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/test/lib
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2024-08-05 20:39:44 -0300
committer(quasar) nebula <qznebula@protonmail.com>2024-08-05 20:42:09 -0300
commit91469b51fe10fbedaece83dafb07e1fd6730e11c (patch)
tree22a0b2e82f891ce4f0f4c5309be2166190aabe2e /test/lib
parent4cb5d1d0c231afad0175b2824320d0612f0eceef (diff)
test: general refactor instantiating things & managing wikiData
Diffstat (limited to 'test/lib')
-rw-r--r--test/lib/wiki-data.js98
1 files changed, 98 insertions, 0 deletions
diff --git a/test/lib/wiki-data.js b/test/lib/wiki-data.js
index c373aadd..7c3d2147 100644
--- a/test/lib/wiki-data.js
+++ b/test/lib/wiki-data.js
@@ -1,6 +1,8 @@
 import CacheableObject from '#cacheable-object';
 import find from '#find';
 import {withEntries} from '#sugar';
+import Thing from '#thing';
+import thingConstructors from '#things';
 import {linkWikiDataArrays} from '#yaml';
 
 export function linkAndBindWikiData(wikiData, {
@@ -53,3 +55,99 @@ export function linkAndBindWikiData(wikiData, {
         .bind(null, wikiData, {XXX_decacheWikiData: true}),
   };
 }
+
+export function stubWikiData() {
+  return {
+    albumData: [],
+    artistData: [],
+    artTagData: [],
+    flashData: [],
+    flashActData: [],
+    flashSideData: [],
+    groupData: [],
+    groupCategoryData: [],
+    newsData: [],
+    staticPageData: [],
+    trackData: [],
+    trackSectionData: [],
+  };
+}
+
+export function stubThing(wikiData, constructor, properties = {}) {
+  const thing = Reflect.construct(constructor, []);
+  Object.assign(thing, properties);
+
+  const wikiDataSpec = {
+    Album: 'albumData',
+    Artist: 'artistData',
+    ArtTag: 'artTagData',
+    Flash: 'flashData',
+    FlashAct: 'flashActData',
+    FlashSide: 'flashSideData',
+    Group: 'groupData',
+    GroupCategory: 'groupCategoryData',
+    NewsEntry: 'newsData',
+    StaticPage: 'staticPageData',
+    Track: 'trackData',
+    TrackSection: 'trackSectionData',
+  };
+
+  const wikiDataMap =
+    new Map(
+      Object.entries(wikiDataSpec)
+        .map(([thingKey, wikiDataKey]) => [
+          thingConstructors[thingKey],
+          wikiData[wikiDataKey],
+        ]));
+
+  const wikiDataArray =
+    wikiDataMap.get(constructor);
+
+  wikiDataArray.push(thing);
+
+  return thing;
+}
+
+export function stubTrackAndAlbum(wikiData, trackDirectory = null, albumDirectory = null) {
+  const {Track, TrackSection, Album} = thingConstructors;
+
+  const track =
+    stubThing(wikiData, Track, {directory: trackDirectory});
+
+  const section =
+    stubThing(wikiData, TrackSection, {tracks: [track]});
+
+  const album =
+    stubThing(wikiData, Album, {directory: albumDirectory, trackSections: [section]});
+
+  return {track, album, section};
+}
+
+export function stubArtistAndContribs(wikiData, artistName = `Test Artist`) {
+  const {Artist} = thingConstructors;
+
+  const artist =
+    stubThing(wikiData, Artist, {name: artistName});
+
+  const contribs =
+    [{artist: artistName, annotation: null}];
+
+  const badContribs =
+    [{artist: `Figment of Your Imagination`, annotation: null}];
+
+  return {artist, contribs, badContribs};
+}
+
+export function stubFlashAndAct(wikiData, flashDirectory = null) {
+  const {Flash, FlashAct} = thingConstructors;
+
+  const flash =
+    stubThing(wikiData, Flash, {directory: flashDirectory});
+
+  const flashAct =
+    stubThing(wikiData, FlashAct, {
+      flashes: [Thing.getReference(flash)],
+    });
+
+  return {flash, flashAct};
+}