From fc42284f791b557db393e3b0a31f442254361ae6 Mon Sep 17 00:00:00 2001 From: Sayem Chowdhury Date: Tue, 23 Mar 2021 21:56:28 +0600 Subject: [PATCH] tidal tests --- __tests__/converter/tidal.ts | 85 ++++++++++++++++++++++++++++++++++++ src/converter/tidal.ts | 6 +-- 2 files changed, 88 insertions(+), 3 deletions(-) create mode 100644 __tests__/converter/tidal.ts diff --git a/__tests__/converter/tidal.ts b/__tests__/converter/tidal.ts new file mode 100644 index 0000000..aea2671 --- /dev/null +++ b/__tests__/converter/tidal.ts @@ -0,0 +1,85 @@ +import test from 'ava'; +import {tidal} from '../../src'; + +// Work (feat. Drake) +const SNG_TITLE = 'Work'; +const SNG_ID = '56681096'; +const ISRC = 'QM5FT1600116'; + +// ANTI (Deluxe) (feat. SZA) +const ALB_TITLE = 'ANTI (Deluxe)'; +const ALB_ID = '56681092'; +const UPC = '00851365006554'; + +// Rihanna +const ART_ID = '10665'; + +// Playlists +const PLAYLIST_TITLE = 'Albums'; +const PLAYLIST_ID = 'ed004d2b-b494-42be-8506-b1d23cd3bb80'; + +test('GET TRACK INFO', async (t) => { + const response = await tidal.getTrack(SNG_ID); + + t.is(response.id.toString(), SNG_ID); + t.is(response.title, SNG_TITLE); + t.is(response.isrc, ISRC); +}); + +test('GET ALBUM INFO', async (t) => { + const response = await tidal.getAlbum(ALB_ID); + + t.is(response.id.toString(), ALB_ID); + t.is(response.title, ALB_TITLE); + t.is(response.upc, UPC); +}); + +test('GET ALBUM TRACKS', async (t) => { + const response = await tidal.getAlbumTracks(ALB_ID); + + t.is(response.items.length, response.totalNumberOfItems); + t.is(response.totalNumberOfItems, 16); +}); + +test('GET ARTIST ALBUMS', async (t) => { + const response = await tidal.getArtistAlbums(ART_ID); + + t.is(response.items.length, response.totalNumberOfItems); + t.true(response.totalNumberOfItems > 30); +}); + +test('GET ARTIST TOP TRACKS', async (t) => { + const response = await tidal.getArtistAlbums(ART_ID); + + t.is(response.items.length, response.totalNumberOfItems); + t.true(response.totalNumberOfItems > 30); +}); + +test('GET PLAYLIST INFO', async (t) => { + const response = await tidal.getPlaylist(PLAYLIST_ID); + + t.is(response.title, PLAYLIST_TITLE); + t.is(response.type, 'USER'); +}); + +test('GET PLAYLIST TRACKS', async (t) => { + const response = await tidal.getPlaylistTracks(PLAYLIST_ID); + + t.is(response.items.length, response.totalNumberOfItems); + t.true(response.items.length > 50); +}); + +if (process.env.CI) { + test('GET ARTISTS TO DEEZER TRACKS', async (t) => { + const response = await tidal.artist2Deezer(ART_ID); + + t.true(response.length > 250); + }); + + test('GET PLAYLIST TO DEEZER TRACKS', async (t) => { + const response = await tidal.getPlaylistTracks(PLAYLIST_ID); + + t.is(response.items.length, response.totalNumberOfItems); + t.true(response.totalNumberOfItems > 150); + }); +} diff --git a/src/converter/tidal.ts b/src/converter/tidal.ts index fe6c283..153a582 100644 --- a/src/converter/tidal.ts +++ b/src/converter/tidal.ts @@ -138,9 +138,9 @@ export const getArtistAlbums = async (id: string): Promise => { - const {body}: any = await client(`artists/${id}/toptracks`); - body.items = (body as tidalArtistTopTracksType).items.filter((item) => item.artist.id.toString() === id); - return body; + const {data} = await client(`artists/${id}/toptracks`); + data.items = data.items.filter((item: any) => item.artist.id.toString() === id); + return data; }; /**