Write a test for an api request

hey there, basically what I am working on is an APi Wrapper. I now want to “test” my code/request by writing a test. How would I do that? I have the following code to lookup players

defmodule Clashapi.Player do
  import Clashapi.Client

  def get(tag) do
    request(
      :get,
      "v1/players/#{url_encode(tag)}"
    )
  end

  def find_by_name(playername) do
    request(
      :get,
      "v1/players/#{url_encode(playername)}"
    )
  end

  def verify(tag, token) do
    request(
      :post,
      "v1/players/#{url_encode(tag)}/verifytoken",
      %{token: token}
    )
  end
end

and my client

lines (30 sloc)  664 Bytes
   
defmodule Clashapi.Client do
  @token Application.compile_env(:clashapi, :token)
  @base_url "https://api.clashofclans.com/"
  def request(method, path, body \\ %{}, opts \\ []) do
    :hackney.request(
      method,
      @base_url <> path,
      headers(),
      body |> Jason.encode!(),
      opts
    )
    |> case do
      {:ok, _, _, body} ->
        Jason.decode(body)

      {:error, reason} ->
        {:error, %{reason: reason}}

      other ->
        other
    end
  end

  defp headers do
    [
      {"Content-Type", "application/json"},
      {"Authorization", "Bearer #{@token}"}
    ]
  end

  def url_encode(str) do
    URI.encode(str)
  end
end

I would be happy about any hints/tips - its my first time writing tests :slight_smile:

You could test for correctness of API Wrapper, that when you call your API Wrapper, it call clash of clans HTTP API with correct parameter and body. You could use Bypass — bypass v2.1.0 to help you with assert HTTP API request generated.