From 93a1042e03c84e0c1ad6101f1a0bb3266a2de67a Mon Sep 17 00:00:00 2001 From: Exerra Date: Wed, 15 Jul 2026 16:21:10 +0300 Subject: [PATCH] test(applemusic): add tests for stripping EP/Single album suffixes Added test cases to ensure that ' - EP' and ' - Single' suffixes are correctly stripped from Apple Music album names during the formatting process. --- .../tests/applemusic/applemusic.test.ts | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/src/backend/tests/applemusic/applemusic.test.ts b/src/backend/tests/applemusic/applemusic.test.ts index 43d19e33..4679f065 100644 --- a/src/backend/tests/applemusic/applemusic.test.ts +++ b/src/backend/tests/applemusic/applemusic.test.ts @@ -245,4 +245,60 @@ describe('Apple Music - Timestamp Estimation', function () { const diffMiddleToOldest = middlePlayTime!.diff(oldestPlayTime!, 'seconds'); expect(diffMiddleToOldest).to.be.closeTo(200, 1); }); +}); + +describe('Apple Music - Format Play Object', function () { + + it(`Strips " - EP" and " - Single" suffixes from album names`, function () { + // Mock Apple Music API Song objects + const trackEP = { + id: '1', + type: 'songs', + name: 'SONG A', + artistName: 'ARIST A', + albumName: 'ALBUM A - EP', + durationInMillis: 200000 + } as any; // Cast as any to bypass TS complaining about missing API fields (artworks, etc.) + + const trackSingle = { + id: '2', + type: 'songs', + name: 'SONG B', + artistName: 'ARIST B', + albumName: 'ALBUM B - Single', + durationInMillis: 200000 + } as any; + + const trackNormal = { + id: '3', + type: 'songs', + name: 'SONG C', + artistName: 'ARIST C', + albumName: 'ALBUM C - The 2nd Album', + durationInMillis: 200000 + } as any; + + const trackLowercase = { + id: '4', + type: 'songs', + name: 'song d', + artistName: 'artist d', + albumName: 'album d - ep', + durationInMillis: 200000 + } as any; + + // Run them through the formatter + const playEP = AppleMusicSource.formatPlayObj(trackEP); + const playSingle = AppleMusicSource.formatPlayObj(trackSingle); + const playNormal = AppleMusicSource.formatPlayObj(trackNormal); + const playLowercase = AppleMusicSource.formatPlayObj(trackLowercase); + + // Assert the suffixes are removed + expect(playEP.data.album).to.equal('ALBUM A'); + expect(playSingle.data.album).to.equal('ALBUM B'); + expect(playLowercase.data.album).to.equal('album d'); + + // Assert normal album names are untouched + expect(playNormal.data.album).to.equal(trackNormal.albumName); + }); }); \ No newline at end of file -- 2.51.2