Skip to content

Commit

Permalink
Merge pull request #1548 from sferra/fix/bandcamp-search-pagination
Browse files Browse the repository at this point in the history
Fix Bandcamp plugin search aborting after the first page
  • Loading branch information
nukeop authored Feb 11, 2024
2 parents 52827b6 + b8e60f3 commit 0c7c69a
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 1 deletion.
60 changes: 60 additions & 0 deletions packages/core/src/plugins/stream/BandcampPlugin.test.ts
Original file line number Diff line number Diff line change
@@ -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);
});
});
});
2 changes: 1 addition & 1 deletion packages/core/src/plugins/stream/BandcampPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class BandcampPlugin extends StreamProviderPlugin {
item.type === 'track' &&
item.artist.toLowerCase() === query.artist.toLowerCase()
);
if (tracks) {
if (tracks.length > 0) {
break;
}
}
Expand Down

0 comments on commit 0c7c69a

Please sign in to comment.