Skip to content

Commit 57de2f6

Browse files
committed
test(bandcamp): add test cases
1 parent f7110f7 commit 57de2f6

File tree

11 files changed

+1480
-0
lines changed

11 files changed

+1480
-0
lines changed

providers/Bandcamp/__snapshots__/mod.test.ts.snap

Lines changed: 1300 additions & 0 deletions
Large diffs are not rendered by default.

providers/Bandcamp/mod.test.ts

Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import { afterAll, describe } from '@std/testing/bdd';
55
import { assertSnapshot } from '@std/testing/snapshot';
66

77
import BandcampProvider from './mod.ts';
8+
import { isDefined } from '@/utils/predicate.ts';
9+
import { assertEquals } from 'std/assert/assert_equals.ts';
810

911
describe('Bandcamp provider', () => {
1012
const bc = new BandcampProvider(makeProviderOptions());
@@ -58,6 +60,175 @@ describe('Bandcamp provider', () => {
5860
'Bandcamp account should not be linked to an artist',
5961
);
6062
},
63+
}, {
64+
description: 'subscriber-only release',
65+
release: 'arbee/des-papiers-ii',
66+
assert: async (release, ctx) => {
67+
await assertSnapshot(ctx, release);
68+
69+
const recordingBandcampLinks = release.media.flatMap((medium) =>
70+
medium.tracklist.map((track) => track.recording?.externalIds?.find((link) => link.provider === 'bandcamp'))
71+
).filter(isDefined);
72+
73+
assertEquals(
74+
recordingBandcampLinks.filter((link) => link.linkTypes?.includes('free streaming')).length,
75+
0,
76+
'0 tracks should be free streaming',
77+
);
78+
79+
assertEquals(
80+
recordingBandcampLinks.filter((link) => link.linkTypes?.includes('paid download')).length,
81+
1,
82+
'1 tracks should be paid download',
83+
);
84+
85+
assertEquals(
86+
recordingBandcampLinks.filter((link) => link.linkTypes?.includes('free download')).length,
87+
0,
88+
'0 tracks should be free download',
89+
);
90+
91+
const releaseBandcampLink = release.externalLinks.find((link) => link.url.includes('bandcamp.com'));
92+
93+
const isFreeStreaming = releaseBandcampLink?.types?.includes('free streaming');
94+
assert(!isFreeStreaming, 'Release should not be free streaming');
95+
96+
const isPaidDownload = releaseBandcampLink?.types?.includes('paid download');
97+
assert(isPaidDownload, 'Release should be paid download');
98+
99+
const isFreeDownload = releaseBandcampLink?.types?.includes('free download');
100+
assert(!isFreeDownload, 'Release should not be free download');
101+
},
102+
}, {
103+
description: 'subscriber-only release with Creative Commons license',
104+
release: 'stevelawson/ambiguous-hands',
105+
assert: async (release, ctx) => {
106+
await assertSnapshot(ctx, release);
107+
108+
const hasLicense = release.externalLinks.some((link) => link.types?.includes('license'));
109+
assert(hasLicense, 'Release should have a linked license');
110+
111+
const license = release.externalLinks.find((link) => link.types?.includes('license'));
112+
assert(
113+
license?.url === 'http://creativecommons.org/licenses/by-nc-sa/3.0/',
114+
'Release should link to Creative Commons license page',
115+
);
116+
},
117+
}, {
118+
description: 'single track release',
119+
release: 'svenfredrik/track/mr-florida-81',
120+
assert: async (release, ctx) => {
121+
await assertSnapshot(ctx, release);
122+
123+
const hasSingleReleaseGroupType = release.types?.includes('Single');
124+
assert(hasSingleReleaseGroupType, 'Release should be type Single');
125+
126+
const tracksWithIsrc = release.media.flatMap((medium) =>
127+
medium.tracklist.filter((track) => typeof track.isrc === 'string' && track.isrc.length > 0)
128+
);
129+
assertEquals(tracksWithIsrc.length, 1, 'Release tracks should have ISRCs');
130+
},
131+
}, {
132+
description: 'release with name your price (non-minimum price), but tracks have minimum price',
133+
release: 'frisyr/demo',
134+
assert: async (release, ctx) => {
135+
await assertSnapshot(ctx, release);
136+
137+
const releaseBandcampLink = release.externalLinks.find((link) => link.url.includes('bandcamp.com'));
138+
139+
const isPaidDownload = releaseBandcampLink?.types?.includes('paid download');
140+
assert(isPaidDownload, 'Release should be paid download');
141+
142+
const isFreeDownload = releaseBandcampLink?.types?.includes('free download');
143+
assert(isFreeDownload, 'Release should be free download');
144+
145+
const recordingBandcampLinks = release.media.flatMap((medium) =>
146+
medium.tracklist.map((track) => track.recording?.externalIds?.find((link) => link.provider === 'bandcamp'))
147+
).filter(isDefined);
148+
149+
assertEquals(
150+
recordingBandcampLinks.filter((link) => link.linkTypes?.includes('paid download')).length,
151+
3,
152+
'3 tracks should be paid download (the other 3 can only be downloaded by acquiring the whole album)',
153+
);
154+
155+
assertEquals(
156+
recordingBandcampLinks.filter((link) => link.linkTypes?.includes('free download')).length,
157+
0,
158+
'0 tracks should be free download',
159+
);
160+
},
161+
}, {
162+
description: 'release with name your price (non-minimum price), but most tracks have non-minimum price',
163+
release: 'muzea/ambient-energy-name-your-price',
164+
assert: async (release, ctx) => {
165+
await assertSnapshot(ctx, release);
166+
167+
const recordingBandcampLinks = release.media.flatMap((medium) =>
168+
medium.tracklist.map((track) => track.recording?.externalIds?.find((link) => link.provider === 'bandcamp'))
169+
).filter(isDefined);
170+
171+
assertEquals(
172+
recordingBandcampLinks.filter((link) => link.linkTypes?.includes('paid download')).length,
173+
5,
174+
'5 tracks should be paid download',
175+
);
176+
177+
// TODO: This case should pass. It would require minimum prices of the individual tracks, which require data from the track page.
178+
// assertEquals(
179+
// recordingBandcampLinks.filter((link) => link.linkTypes?.includes('free download')).length,
180+
// 4,
181+
// '4 tracks should be free download (one track has a minimum price)',
182+
// );
183+
},
184+
}, {
185+
description: 'release with some download only tracks and one streamable track',
186+
release: 'hipdozer/futon-feels',
187+
assert: async (release, ctx) => {
188+
await assertSnapshot(ctx, release);
189+
},
190+
}, {
191+
description: 'release with a hidden track',
192+
release: 'spinningrust/do-you-like-acid-ep',
193+
assert: async (release, ctx) => {
194+
await assertSnapshot(ctx, release);
195+
196+
const hasHiddenTrackWarning = release.info.messages.some((message) =>
197+
message.provider === 'Bandcamp' &&
198+
message.type === 'warning' &&
199+
message.text === '1\xa0track is hidden and only available with the download'
200+
);
201+
assert(hasHiddenTrackWarning, 'Should display warning about the hidden track');
202+
203+
const trackCount = release.media.flatMap((medium) => medium.tracklist).length;
204+
assertEquals(trackCount, 6, 'Release should have 6 tracks (5 listed and 1 hidden)');
205+
},
206+
}, {
207+
description:
208+
'release with 7/12 tracks streamable, i.e. more than half track as streamable while rest is download only',
209+
release: 'lunar-module/bear-creek',
210+
assert: async (release, ctx) => {
211+
await assertSnapshot(ctx, release);
212+
213+
const hasPhysicalReleaseInfo = release.info.messages.some((message) =>
214+
message.provider === 'Bandcamp' &&
215+
message.type === 'info' &&
216+
message.text ===
217+
'Available physical release packages:\n- **Bear Creek CD**: Compact Disc (CD) (edition of null, GTIN: 5060889590868)'
218+
);
219+
assert(hasPhysicalReleaseInfo, 'Should display info about physical release');
220+
221+
const isFreeStreaming = release.externalLinks.some((link) => link.types?.includes('free streaming'));
222+
assert(!isFreeStreaming, 'Release should not be free streaming');
223+
224+
const freeStreamingTrackCount = release.media.flatMap((medium) =>
225+
medium.tracklist.map((track) =>
226+
track.recording?.externalIds?.find((link) => link.provider === 'bandcamp')
227+
)
228+
).filter((link) => link?.linkTypes?.includes('free streaming')).length;
229+
230+
assertEquals(freeStreamingTrackCount, 7, '7 tracks should be free streaming');
231+
},
61232
}],
62233
});
63234

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"tralbum":{"for the curious":"https://bandcamp.com/help/audio_basics#steal https://bandcamp.com/terms_of_use","current":{"audit":5,"title":"Des papiers II","new_date":"01 May 2025 01:54:43 GMT","mod_date":"01 May 2025 01:56:42 GMT","publish_date":"01 May 2025 01:56:42 GMT","private":null,"killed":null,"download_pref":2,"require_email":null,"is_set_price":null,"set_price":9.0,"minimum_price":9.0,"minimum_price_nonzero":9.0,"require_email_0":null,"artist":null,"about":"Des papiers II.\r\n\r\nSubscriber-exclusive ambient.","credits":null,"auto_repriced":null,"new_desc_format":1,"band_id":4038363339,"selling_band_id":4038363339,"art_id":1289075493,"download_desc_id":null,"release_date":"30 Apr 2025 00:00:00 GMT","upc":null,"purchase_url":null,"purchase_title":null,"featured_track_id":3305703503,"id":948735258,"type":"album"},"preorder_count":null,"hasAudio":true,"art_id":1289075493,"packages":null,"defaultPrice":9.0,"freeDownloadPage":null,"FREE":1,"PAID":2,"artist":"arbee","item_type":"album","id":948735258,"last_subscription_item":null,"has_discounts":false,"is_bonus":false,"play_cap_data":{"streaming_limits_enabled":false,"streaming_limit":3},"is_purchased":null,"items_purchased":null,"is_private_stream":null,"is_band_member":null,"licensed_version_ids":null,"package_associated_license_id":null,"has_video":null,"tralbum_subscriber_only":true,"featured_track_id":3305703503,"initial_track_num":null,"is_preorder":false,"album_is_preorder":false,"album_release_date":"30 Apr 2025 00:00:00 GMT","trackinfo":[{"id":3305703503,"track_id":3305703503,"file":null,"artist":null,"title":"Des papiers II","encodings_id":1048994955,"license_type":1,"private":null,"track_num":1,"album_preorder":false,"unreleased_track":false,"title_link":"/track/des-papiers-ii","has_lyrics":false,"has_info":false,"streaming":1,"is_downloadable":true,"has_free_download":null,"free_album_download":false,"duration":181.519,"lyrics":null,"sizeof_lyrics":0,"is_draft":false,"video_source_type":null,"video_source_id":null,"video_mobile_url":null,"video_poster_url":null,"video_id":null,"video_caption":null,"video_featured":null,"alt_link":null,"encoding_error":null,"encoding_pending":null,"play_count":null,"is_capped":null,"track_license_id":null}],"playing_from":"album page","url":"https://arbee.bandcamp.com/album/des-papiers-ii","use_expando_lyrics":false},"band":{"id":4038363339,"name":"arbee","fan_email":null,"account_id":1320876912,"facebook_like_enabled":1,"has_discounts":true,"image_id":14017},"og:description":"1 track album"}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"tralbum":{"for the curious":"https://bandcamp.com/help/audio_basics#steal https://bandcamp.com/terms_of_use","current":{"audit":0,"title":"Guide Us Jah/ Pretendah 12\" Exclusive VINYL and/or Download - MATUMBI","new_date":"28 Mar 2020 15:33:27 GMT","mod_date":"04 Mar 2022 10:16:35 GMT","publish_date":"28 Mar 2020 16:39:00 GMT","private":null,"killed":null,"download_pref":2,"require_email":null,"is_set_price":null,"set_price":9.0,"minimum_price":3.0,"minimum_price_nonzero":3.0,"require_email_0":null,"artist":"Matumbi","about":"Guide Us Jah and Pretendah 12\" original mixes by Matumbi have previously only been available on vinyl. Now exclusively available for download here on Old School","credits":null,"auto_repriced":null,"new_desc_format":1,"band_id":2371876871,"selling_band_id":2371876871,"art_id":799938629,"download_desc_id":null,"release_date":"01 Jan 2022 00:00:00 GMT","upc":null,"purchase_url":null,"purchase_title":null,"featured_track_id":1068935279,"id":859543207,"type":"album"},"preorder_count":null,"hasAudio":true,"art_id":799938629,"packages":[{"id":1910990595,"url":"https://dennisbovell.bandcamp.com/album/guide-us-jah-pretendah-12-exclusive-vinyl-and-or-download-matumbi","url_for_app":"https://dennisbovell.bandcamp.com/album/guide-us-jah-pretendah-12-exclusive-vinyl-and-or-download-matumbi","type_id":18,"type_name":"Other Vinyl","title":"Matumbi -Guide Us Jah/Pretendah 12inch","description":"Fresh from the press a brand new NEW YEAR 2022 release. A 12inch with two major Matumbi classics. It's a double AA!\n\nA limited rare release!!","desc_pt1":"Fresh from the press a brand new NEW YEAR 2022 release. A 12inch with two major Matumbi classics. It's a double AA!\n\nA limited rare release!!","desc_pt2":null,"new_desc_format":1,"grid_index":8,"private":null,"subscriber_only":null,"price":14.0,"is_set_price":null,"is_live_ticket":null,"live_event_over":null,"live_event_id":null,"live_event_title":null,"live_event_url":null,"live_event_gcal_url":null,"live_event_ical_url":null,"live_event_replays_enabled":null,"live_event_image_color_one":null,"live_event_image_color_two":null,"sku":"DB-GUP1-MGUJ","upc":null,"band_id":2371876871,"selling_band_id":2371876871,"label":null,"currency":"GBP","country":null,"tax_rate":null,"options_title":null,"options":null,"origins":[{"id":1206887,"quantity":null,"quantity_sold":null,"quantity_available":0,"package_id":1910990595,"option_id":0}],"arts":[{"id":3146000589,"file_name":"3697142756","index":0,"image_id":27219201,"width":1400,"height":1400,"crc":3697829650},{"id":3445366718,"file_name":"839031125","index":1,"image_id":27219205,"width":1400,"height":1400,"crc":521646648}],"album_art":null,"album_art_id":799938629,"shipping_exception_mode":null,"download_type":"a","download_id":859543207,"download_is_preorder":null,"download_release_date":"01 Jan 2022 00:00:00 GMT","download_title":"Guide Us Jah/ Pretendah 12\" Exclusive VINYL and/or Download - MATUMBI","download_url":"https://dennisbovell.bandcamp.com/album/guide-us-jah-pretendah-12-exclusive-vinyl-and-or-download-matumbi","download_has_audio":true,"download_track_count":2,"download_art_id":799938629,"download_artist":"Matumbi","fulfillment_days":7,"release_date":null,"new_date":"01 Jan 2022 14:19:20 GMT","edition_size":null,"quantity_sold":null,"quantity_available":0,"quantity_limits":1,"quantity_warning":true,"album_id":859543207,"album_title":"Guide Us Jah/ Pretendah 12\" Exclusive VINYL and/or Download - MATUMBI","album_artist":"Matumbi","album_private":null,"album_publish_date":"28 Mar 2020 16:39:00 GMT","album_release_date":"01 Jan 2022 00:00:00 GMT","subscriber_only_published":false,"featured_date":null,"certified_seller":1,"limited_checkout":false,"associated_license_id":null,"live_event_scheduled_start_date":null,"live_event_scheduled_end_date":null,"live_event_start_date":null,"live_event_end_date":null,"live_event_timezone":null,"live_event_type":null,"listening_party_duration":null,"is_cardable":true}],"defaultPrice":9.0,"freeDownloadPage":null,"FREE":1,"PAID":2,"artist":"Matumbi","item_type":"album","id":859543207,"last_subscription_item":null,"has_discounts":false,"is_bonus":null,"play_cap_data":{"streaming_limits_enabled":true,"streaming_limit":3},"is_purchased":null,"items_purchased":null,"is_private_stream":null,"is_band_member":null,"licensed_version_ids":null,"package_associated_license_id":null,"has_video":null,"tralbum_subscriber_only":false,"featured_track_id":1068935279,"initial_track_num":null,"is_preorder":false,"album_is_preorder":false,"album_release_date":"01 Jan 2022 00:00:00 GMT","trackinfo":[{"id":1068935279,"track_id":1068935279,"file":{"mp3-128":"https://t4.bcbits.com/stream/b7e07f1271193e70864115e5917d3963/mp3-128/1068935279?p=0&ts=1758053651&t=430d3838fedff7603e87bd5388dca09ce36858cb&token=1758053651_94b45c7643ed7ddfc4705ff11ebbba5ebcf962ff"},"artist":null,"title":"Guide Us Jah 12\"","encodings_id":2658587331,"license_type":1,"private":null,"track_num":1,"album_preorder":false,"unreleased_track":false,"title_link":"/track/guide-us-jah-12","has_lyrics":false,"has_info":true,"streaming":1,"is_downloadable":true,"has_free_download":null,"free_album_download":false,"duration":425.0,"lyrics":null,"sizeof_lyrics":0,"is_draft":false,"video_source_type":null,"video_source_id":null,"video_mobile_url":null,"video_poster_url":null,"video_id":null,"video_caption":null,"video_featured":null,"alt_link":null,"encoding_error":null,"encoding_pending":null,"play_count":0,"is_capped":false,"track_license_id":null},{"id":721099376,"track_id":721099376,"file":null,"artist":null,"title":"Pretendah 12\"","encodings_id":632037049,"license_type":1,"private":null,"track_num":2,"album_preorder":false,"unreleased_track":false,"title_link":"/track/pretendah-12","has_lyrics":false,"has_info":true,"streaming":null,"is_downloadable":true,"has_free_download":null,"free_album_download":false,"duration":332.147,"lyrics":null,"sizeof_lyrics":0,"is_draft":false,"video_source_type":null,"video_source_id":null,"video_mobile_url":null,"video_poster_url":null,"video_id":null,"video_caption":null,"video_featured":null,"alt_link":null,"encoding_error":null,"encoding_pending":null,"play_count":0,"is_capped":false,"track_license_id":null}],"playing_from":"album page","url":"https://dennisbovell.bandcamp.com/album/guide-us-jah-pretendah-12-exclusive-vinyl-and-or-download-matumbi","use_expando_lyrics":false},"band":{"id":2371876871,"name":"Dennis Bovell MBE","fan_email":null,"account_id":1274800450,"facebook_like_enabled":1,"has_discounts":true,"image_id":37484978},"og:description":"2 track album"}

0 commit comments

Comments
 (0)