Skip to content

Commit

Permalink
test: should return 200 when adapter returns error - appleMusic
Browse files Browse the repository at this point in the history
  • Loading branch information
sjdonado committed Oct 19, 2023
1 parent 2dc71f8 commit 1a90421
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions tests/integration/api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -793,6 +793,60 @@ describe('Api router', () => {
expect(redisSetMock).toHaveBeenCalledTimes(2);
});

it('should return 200 when adapter returns error - appleMusic', async () => {
const spotifyLink = 'https://open.spotify.com/track/2KvHC9z14GSl4YpkNMX384';
const query = 'Do%20Not%20Disturb%20Drake';

const appleMusicQuery = `${config.services.appleMusic.baseUrl}${query}`;
const youtubeQuery = `${config.services.youTube.apiSearchUrl}${query}&type=video&key=${config.services.youTube.apiKey}`;
const deezerQuery = `${config.services.deezer.apiUrl}/track?q=${query}&limit=1`;

const request = JSONRequest(endpoint, { spotifyLink });

mock.onGet(spotifyLink).reply(200, spotifySongHeadResponseMock);
mock.onGet(appleMusicQuery).reply(500);
mock.onGet(youtubeQuery).reply(200, youtubeSongResponseMock);
mock.onGet(deezerQuery).reply(200, deezerSongResponseMock);

redisGetMock.mockResolvedValue(0);
redisSetMock.mockResolvedValue('');

const response = await app.handle(request).then(res => res.json());

expect(response).toEqual({
id: '2KvHC9z14GSl4YpkNMX384',
type: 'music.song',
title: 'Do Not Disturb',
description: 'Drake · Song · 2017',
image: 'https://i.scdn.co/image/ab67616d0000b2734f0fd9dad63977146e685700',
audio: 'https://p.scdn.co/mp3-preview/df989a31c8233f46b6a997c59025f9c8021784aa',
source: 'https://open.spotify.com/track/2KvHC9z14GSl4YpkNMX384',
links: [
{
type: 'youTube',
url: 'https://www.youtube.com/watch?v=zhY_0DoQCQs',
isVerified: true,
},
{
type: 'deezer',
url: 'https://www.deezer.com/track/144572248',
isVerified: true,
},
{
type: 'soundCloud',
url: 'https://soundcloud.com/search/sounds?q=Do%20Not%20Disturb%20Drake',
},
{
type: 'tidal',
url: 'https://listen.tidal.com/search?q=Do%20Not%20Disturb%20Drake',
},
],
});

expect(redisGetMock).toHaveBeenCalledTimes(2);
expect(redisSetMock).toHaveBeenCalledTimes(2);
});

it('should return unknown error - could not parse Spotify metadata', async () => {
const request = JSONRequest(endpoint, { spotifyLink: cachedSpotifyLink });

Expand Down

0 comments on commit 1a90421

Please sign in to comment.