<commit_before>defmodule JsonTest do
  use ExUnit.Case

  defmodule Client do
    use Tesla.Builder

    with Tesla.Middleware.EncodeJson
    with Tesla.Middleware.DecodeJson

    adapter fn (env) ->
      case env.url do
        "/decode" ->
          {200, %{}, "{\"value\": 123}"}
        "/encode" ->
          {200, %{}, env.body |> String.replace("foo", "baz")}
      end
    end
  end

  test "Tesla.Middleware.DecodeJson" do
    assert Client.get("/decode").body == %{"value" => 123}
  end

  test "Tesla.Middleware.EndcodeJson" do
    assert Client.post("/encode", %{"foo" => "bar"}).body == %{"baz" => "bar"}
  end
end<commit_msg>More test coverage for JSON middleware<commit_after>defmodule JsonTest do
  use ExUnit.Case

  defmodule Client do
    use Tesla.Builder

    with Tesla.Middleware.EncodeJson
    with Tesla.Middleware.DecodeJson

    adapter fn (env) ->
      case env.url do
        "/decode" ->
          {200, %{}, "{\"value\": 123}"}
        "/encode" ->
          {200, %{}, env.body |> String.replace("foo", "baz")}
        "/empty" ->
          {200, %{}, nil}
      end
    end
  end

  test "decode JSON body" do
    assert Client.get("/decode").body == %{"value" => 123}
  end

  test "do not decode empty body" do
    assert Client.get("/empty").body == nil
  end

  test "encode body as JSON" do
    assert Client.post("/encode", %{"foo" => "bar"}).body == %{"baz" => "bar"}
  end
end
{'fraction_non_alphanumeric': 0.16842847075405215, 'fraction_numerical': 0.019027484143763214, 'mean_word_length': 2.380952380952381, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 18, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3196136', 'n_tokens_mistral': 493, 'n_tokens_neox': 453, 'n_words': 125}