album.spec.ts 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import { baseUrl, defaultFetchOpts } from "./constants";
  2. import { checkAlbumProps, checkArtistProps } from "./hooks";
  3. describe("GET /album/:id", () => {
  4. //#region /album/:id
  5. it("Album details yields correct props", async () => {
  6. const res = await fetch(`${baseUrl}/album/7105950`, defaultFetchOpts);
  7. const body = await res.json();
  8. expect(res.status).toBe(200);
  9. expect(body?.error).toEqual(false);
  10. expect(body?.matches).toEqual(1);
  11. checkAlbumProps(body?.album);
  12. checkArtistProps(body?.album?.artist);
  13. });
  14. //#region inv /album/:id
  15. it("Invalid album yields error", async () => {
  16. const res = await fetch(`${baseUrl}/album/0`, defaultFetchOpts);
  17. const body = await res.json();
  18. expect(res.status).toBe(400);
  19. expect(body?.error).toEqual(true);
  20. expect(body?.matches).toEqual(0);
  21. expect(body?.message).toBeDefined();
  22. });
  23. //#region inv /album
  24. it("Album path without ID yields error", async () => {
  25. const res = await fetch(`${baseUrl}/album`, defaultFetchOpts);
  26. const body = await res.json();
  27. expect(res.status).toBe(400);
  28. expect(body?.error).toEqual(true);
  29. expect(body?.matches).toEqual(null);
  30. expect(body?.message).toBeDefined();
  31. });
  32. });