mirror of
https://github.com/d-fi/d-fi-core.git
synced 2025-07-22 05:05:03 +02:00
spotify tests
This commit is contained in:
parent
fc42284f79
commit
4e078b5ac0
28
__tests__/converter/spotify.ts
Normal file
28
__tests__/converter/spotify.ts
Normal file
@ -0,0 +1,28 @@
|
||||
import test from 'ava';
|
||||
import {spotify} from '../../src';
|
||||
|
||||
const PLAYLIST_TITLE = 'This Is Eminem';
|
||||
const PLAYLIST_ID = '37i9dQZF1DX1clOuib1KtQ';
|
||||
const ARTIST_ID = '7dGJo4pcD2V6oG8kP0tJRR';
|
||||
|
||||
test.serial('SET ANONYMOUS TOKEN', async (t) => {
|
||||
const response = await spotify.setSpotifyAnonymousToken();
|
||||
|
||||
t.truthy(response.accessToken, 'string');
|
||||
t.true(response.isAnonymous);
|
||||
});
|
||||
|
||||
test('GET ARTIST TO DEEZER TRACKS', async (t) => {
|
||||
const tracks = await spotify.artist2Deezer(ARTIST_ID);
|
||||
|
||||
t.is(tracks.length, 10);
|
||||
});
|
||||
|
||||
if (process.env.CI) {
|
||||
test('GET PLAYLIST TO DEEZER TRACKS', async (t) => {
|
||||
const [playlist, tracks] = await spotify.playlist2Deezer(PLAYLIST_ID);
|
||||
|
||||
t.is(playlist.TITLE, PLAYLIST_TITLE);
|
||||
t.true(tracks.length > 50);
|
||||
});
|
||||
}
|
@ -1,2 +1,3 @@
|
||||
export * from './deezer';
|
||||
export * as tidal from './tidal';
|
||||
export * as spotify from './spotify';
|
||||
|
@ -24,9 +24,17 @@ const getOffset = (next: null | string): number => {
|
||||
|
||||
const queue = new PQueue({concurrency: 25});
|
||||
|
||||
export const spotifyApi = new SpotifyWebApi();
|
||||
const spotifyApi = new SpotifyWebApi();
|
||||
|
||||
export const spotifyPlaylist2Deezer = async (
|
||||
export const setSpotifyAnonymousToken = async () => {
|
||||
const {data}: {data: tokensType} = await axios.get(
|
||||
'https://open.spotify.com/get_access_token?reason=transport&productType=embed',
|
||||
);
|
||||
spotifyApi.setAccessToken(data.accessToken);
|
||||
return data;
|
||||
};
|
||||
|
||||
export const playlist2Deezer = async (
|
||||
id: string,
|
||||
onError?: (item: SpotifyApi.PlaylistTrackObject, index: number, err: Error) => void,
|
||||
): Promise<[playlistInfo, trackType[]]> => {
|
||||
@ -86,7 +94,7 @@ export const spotifyPlaylist2Deezer = async (
|
||||
return [playlistInfoData, tracks];
|
||||
};
|
||||
|
||||
export const spotifyArtist2Deezer = async (
|
||||
export const artist2Deezer = async (
|
||||
id: string,
|
||||
onError?: (item: SpotifyApi.TrackObjectFull, index: number, err: Error) => void,
|
||||
): Promise<trackType[]> => {
|
||||
@ -112,10 +120,3 @@ export const spotifyArtist2Deezer = async (
|
||||
|
||||
return tracks;
|
||||
};
|
||||
|
||||
export const setSpotifyAnonymousToken = async () => {
|
||||
const {data}: {data: tokensType} = await axios.get(
|
||||
'https://open.spotify.com/get_access_token?reason=transport&productType=embed',
|
||||
);
|
||||
spotifyApi.setAccessToken(data.accessToken);
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user