Skip to content

Commit

Permalink
test: should return unknown error - could not parse Spotify metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
sjdonado committed Oct 18, 2023
1 parent f3fef01 commit c14c0f3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
4 changes: 1 addition & 3 deletions src/parsers/spotify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@ export const parseSpotifyMetadata = async (
: metaTagContent(doc, 'og:type', 'property');

if (!title || !description || !type || !image) {
throw new Error(
`Could not parse Spotify metadata. ${title} ${description} ${type} ${image}`
);
throw new Error(`Could not parse Spotify metadata.`);
}

return {
Expand Down
14 changes: 14 additions & 0 deletions tests/integration/api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,20 @@ describe('Api router', () => {
expect(redisSetMock).toHaveBeenCalledTimes(0);
});

it('should return unknown error - could not parse Spotify metadata', async () => {
const request = new Request(`${endpoint}?spotifyLink=${cachedSpotifyLink}`);

mock.onGet(cachedSpotifyLink).reply(200, '<html></html>');

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

expect(response).toEqual({
code: 'UNKNOWN',
message:
'[Spotify Parser] (https://open.spotify.com/track/2KvHC9z14GSl4YpkNMX384) Error: Could not parse Spotify metadata.',
});
});

it('should return bad request - invalid spotifyLink', async () => {
const spotifyLink = 'https://open.spotify.com/invalid';

Expand Down

0 comments on commit c14c0f3

Please sign in to comment.