Skip to content

Commit

Permalink
Add test to prove search with undefined stream ID when no streams are…
Browse files Browse the repository at this point in the history
… available
  • Loading branch information
sferra committed Feb 13, 2024
1 parent 0c7c69a commit d6c8ca6
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 1 deletion.
67 changes: 67 additions & 0 deletions packages/app/app/actions/queue.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import { QueueItem } from '../reducers/queue';
import { Queue } from './actionTypes';
import * as QueueOperations from './queue';

describe('Queue actions tests', () => {

describe('finds streams for track', () => {
const getSelectedStreamProvider = jest.spyOn(QueueOperations, 'getSelectedStreamProvider');
const getTrackStreams = jest.spyOn(QueueOperations, 'getTrackStreams');

afterEach(() => {
getSelectedStreamProvider.mockReset();
getTrackStreams.mockReset();
});

test('remote track is removed from the queue when no streams are available', () => {
getTrackStreams.mockResolvedValueOnce([]);
const streamProvider = {
getStreamForId: async (streamId: string) => {
if (!streamId) {
throw new Error('The stream ID must not be undefined');
}
return {};
}
};
getSelectedStreamProvider
.mockReturnValueOnce(streamProvider);

const trackIndex = 123;
const queueItems: QueueItem[] = [];
queueItems[trackIndex] = {
artist: 'Artist Name',
name: 'Track Name',
local: false,
streams: null
};
const stateResolver = () => ({
queue: {
queueItems
},
settings: {
useStreamVerification: false
}
});

const dispatchOperation = jest.fn();
const findStreamsForTrackOperation = QueueOperations.findStreamsForTrack(trackIndex);
findStreamsForTrackOperation(dispatchOperation, stateResolver)
.then(() => {
// no error should have been dispatched
expect(dispatchOperation).not.toHaveBeenCalledWith(
expect.objectContaining({
payload: expect.not.objectContaining({
error: expect.anything()
})
})
);
// assumption:
// track without streams should have been removed from the queue
expect(dispatchOperation).toHaveBeenCalledWith({
type: Queue.REMOVE_QUEUE_ITEM,
payload: { trackIndex }
});
});
});
});
});
2 changes: 1 addition & 1 deletion packages/app/app/actions/queue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export const toQueueItem = (track: Track): QueueItem => ({
streams: track.streams ?? []
});

const getSelectedStreamProvider = (getState) => {
export const getSelectedStreamProvider = (getState) => {
const {
plugin: {
plugins: { streamProviders },
Expand Down

0 comments on commit d6c8ca6

Please sign in to comment.