diff --git a/packages/core/src/plugins/stream/BandcampPlugin.test.ts b/packages/core/src/plugins/stream/BandcampPlugin.test.ts new file mode 100644 index 0000000000..06e59a1c8e --- /dev/null +++ b/packages/core/src/plugins/stream/BandcampPlugin.test.ts @@ -0,0 +1,60 @@ +import { BandcampPlugin } from '.'; +import { Bandcamp } from '../../rest'; +import spyOn = jest.spyOn; +import { BandcampSearchResult } from '../../rest/Bandcamp'; + +describe('Bandcamp plugin tests', () => { + let plugin: BandcampPlugin; + + beforeEach(() => { + plugin = new BandcampPlugin(); + }); + + describe('find track URLs', () => { + const streamQuery = { + artist: 'Artist Name', + track: 'Track Name' + }; + const trackQuery = 'Track Name'; + const bandcampSearch = spyOn(Bandcamp, 'search'); + + afterEach(() => { + bandcampSearch.mockReset(); + }); + + test('finds track', async () => { + const matchingSearchResult: BandcampSearchResult = { + type: 'track', + artist: 'Artist Name', + name: 'Track Name', + url: 'URL', + imageUrl: 'image URL', + tags: [] + }; + bandcampSearch.mockResolvedValueOnce([]) + .mockResolvedValueOnce([]) + .mockResolvedValueOnce([]) + .mockResolvedValueOnce([]) + .mockResolvedValueOnce([matchingSearchResult]); + + await expect(plugin.findTrackUrls(streamQuery)) + .resolves.toEqual([matchingSearchResult]); + + expect(bandcampSearch).toHaveBeenCalledTimes(5); + expect(bandcampSearch).toHaveBeenNthCalledWith(1, trackQuery, 0); + expect(bandcampSearch).toHaveBeenNthCalledWith(2, trackQuery, 1); + expect(bandcampSearch).toHaveBeenNthCalledWith(3, trackQuery, 2); + expect(bandcampSearch).toHaveBeenNthCalledWith(4, trackQuery, 3); + expect(bandcampSearch).toHaveBeenNthCalledWith(5, trackQuery, 4); + }); + + test('doesn\'t find tracks', async () => { + bandcampSearch.mockResolvedValue([]); + + await expect(plugin.findTrackUrls(streamQuery)) + .resolves.toEqual([]); + + expect(bandcampSearch).toHaveBeenCalledTimes(5); + }); + }); +}); diff --git a/packages/core/src/plugins/stream/BandcampPlugin.ts b/packages/core/src/plugins/stream/BandcampPlugin.ts index 08d48b90cc..6e52e4bc3b 100644 --- a/packages/core/src/plugins/stream/BandcampPlugin.ts +++ b/packages/core/src/plugins/stream/BandcampPlugin.ts @@ -24,7 +24,7 @@ class BandcampPlugin extends StreamProviderPlugin { item.type === 'track' && item.artist.toLowerCase() === query.artist.toLowerCase() ); - if (tracks) { + if (tracks.length > 0) { break; } }