« get me outta code hell

hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--src/data/things/track.js9
-rw-r--r--test/unit/data/things/track.js25
2 files changed, 29 insertions, 5 deletions
diff --git a/src/data/things/track.js b/src/data/things/track.js
index 22043688..9b1a8226 100644
--- a/src/data/things/track.js
+++ b/src/data/things/track.js
@@ -192,11 +192,10 @@ export class Track extends Thing {
       Thing.composite.exposeDependency('#hasUniqueCoverArt'),
     ]),
 
-    originalReleaseTrack: Thing.common.dynamicThingFromSingleReference(
-      'originalReleaseTrackByRef',
-      'trackData',
-      find.track
-    ),
+    originalReleaseTrack: Thing.composite.from(`Track.originalReleaseTrack`, [
+      Track.composite.withOriginalRelease(),
+      Thing.composite.exposeDependency('#originalRelease'),
+    ]),
 
     otherReleases:
       Thing.composite.from(`Track.otherReleases`, [
diff --git a/test/unit/data/things/track.js b/test/unit/data/things/track.js
index 9132376c..97d664ee 100644
--- a/test/unit/data/things/track.js
+++ b/test/unit/data/things/track.js
@@ -272,6 +272,31 @@ t.test(`Track.hasUniqueCoverArt`, t => {
     `hasUniqueCoverArt #7: is false if track's coverArtistContribsByRef resolve empty`);
 });
 
+t.only(`Track.originalReleaseTrack`, t => {
+  t.plan(3);
+
+  const {track: track1, album: album1} = stubTrackAndAlbum('track1');
+  const {track: track2, album: album2} = stubTrackAndAlbum('track2');
+
+  const {wikiData, linkWikiDataArrays, XXX_decacheWikiData} = linkAndBindWikiData({
+    trackData: [track1, track2],
+    albumData: [album1, album2],
+  });
+
+  t.equal(track2.originalReleaseTrack, null,
+    `originalReleaseTrack #1: defaults to null`);
+
+  track2.originalReleaseTrackByRef = 'track:track1';
+
+  t.equal(track2.originalReleaseTrack, track1,
+    `originalReleaseTrack #2: is resolved from originalReleaseTrackByRef`);
+
+  track2.trackData = [];
+
+  t.equal(track2.originalReleaseTrack, null,
+    `originalReleaseTrack #3: is null when track missing trackData`);
+});
+
 t.test(`Track.otherReleases`, t => {
   t.plan(6);