Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tests for the API #40

Open
danluki opened this issue May 1, 2023 · 1 comment
Open

Tests for the API #40

danluki opened this issue May 1, 2023 · 1 comment

Comments

@danluki
Copy link
Contributor

danluki commented May 1, 2023

describe("getEpisode", async () => {
  test("returns an episode object", async () => {
    const episode_id = "123";
    const market = "EN" as Market;
    const spotify_episode_response = {
      description:
        "A Spotify podcast sharing fresh insights on important topics of the moment—in a way only Spotify can. You’ll hear from experts in the music, podcast and tech industries as we discover and uncover stories about our work and the world around us.",
      html_description:
        "<p>A Spotify podcast sharing fresh insights on important topics of the moment—in a way only Spotify can. You’ll hear from experts in the music, podcast and tech industries as we discover and uncover stories about our work and the world around us.</p>",
      duration_ms: 1686230,
      explicit: false,
      external_urls: {
        spotify: "string"
      },
      href: "https://api.spotify.com/v1/episodes/5Xt5DXGzch68nYYamXrNxZ",
      id: "5Xt5DXGzch68nYYamXrNxZ",
      images: [
        {
          url: "https://i.scdn.co/image/ab67616d00001e02ff9ca10b55ce82ae553c8228",
          height: 300,
          width: 300
        }
      ],
      is_externally_hosted: false,
      is_playable: false,
      language: "en",
      languages: ["fr", "en"],
      name: "Starting Your Own Podcast: Tips, Tricks, and Advice From Anchor Creators",
      release_date: "1981-12-15",
      release_date_precision: "day",
      resume_point: {
        fully_played: false,
        resume_position_ms: 0
      },
      type: "episode",
      uri: "spotify:episode:0zLhl3WsOCQHbe1BPTiHgr",
      restrictions: {
        reason: "string"
      },
      show: {
        available_markets: ["string"],
        copyrights: [
          {
            text: "string",
            type: "string"
          }
        ],
        description: "string",
        html_description: "string",
        explicit: false,
        external_urls: {
          spotify: "string"
        },
        href: "string",
        id: "string",
        images: [
          {
            url: "https://i.scdn.co/image/ab67616d00001e02ff9ca10b55ce82ae553c8228",
            height: 300,
            width: 300
          }
        ],
        languages: ["string"],
        media_type: "string",
        name: "string",
        publisher: "string",
        type: "show",
        uri: "string",
        total_episodes: 0
      }
    };

    const mockedFetch = vi.fn();
    mockedFetch.mockResolvedValue(spotify_episode_response);
    const client: HTTPClient = {
      fetch: mockedFetch
    };

    const result = await getEpisode(client, episode_id, market);

    expect(client.fetch).toHaveBeenCalledWith(
      `/episodes/${episode_id}`,
      "json",
      { query: { market } }
    );
    expect(result).toBeDefined();
    expect(result).toMatchObject(spotify_episode_response);
  });
});

There is what i got for getEpisode, wanna see you opinion is this enough or we need more tests for api methods. Because I think it's not full. Or, I just want to see you @MellKam code for this tests as a example.

@MellKam
Copy link
Owner

MellKam commented May 3, 2023

In my opinion, the endpoints don't need much testing with mocks. What you wrote should be quite enough.

I'm thinking about additionally making tests with real api without mocks. But, I don't know how much it's needed and whether it's worth it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants