All files / Rindu/utils getArtistsOfTheWeek.ts

15.38% Statements 2/13
0% Branches 0/3
0% Functions 0/1
15.38% Lines 2/13

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 3445x                     4x                                            
import { lastFmApiKey } from "./environment";
 
interface IArtistOfTheWeek {
  artists: {
    artist: {
      name: string;
    }[];
  };
  error?: number;
  message?: string;
}
export async function getArtistsOfTheWeek(): Promise<IArtistOfTheWeek | null> {
  Iif (!lastFmApiKey) {
    console.error("No lastFmApiKey found");
    return null;
  }
  const artistsOfTheWeekRes = await fetch(
    `https://ws.audioscrobbler.com/2.0/?method=chart.gettopartists&api_key=${lastFmApiKey}&format=json`
  );
  const artistsOfTheWeek =
    (await artistsOfTheWeekRes.json()) as IArtistOfTheWeek;
 
  Iif (artistsOfTheWeek.error) {
    console.error(`${artistsOfTheWeek.error}: ${artistsOfTheWeek.message}`);
    return null;
  }
 
  Iif (!artistsOfTheWeekRes.ok) {
    return null;
  }
 
  return artistsOfTheWeek;
}