• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

parroty / exvcr / dbffa5f39277b0e25e1cc297b5c1cb5f78ab7929

21 Sep 2024 10:59AM UTC coverage: 92.224%. Remained the same
dbffa5f39277b0e25e1cc297b5c1cb5f78ab7929

push

github

web-flow
remove kramdown syntax from links (#222)

676 of 733 relevant lines covered (92.22%)

944.91 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

100.0
/lib/exvcr/adapter/finch/converter.ex
1
if Code.ensure_loaded?(Finch) do
2
  defmodule ExVCR.Adapter.Finch.Converter do
3
    @moduledoc """
4
    Provides helpers to mock Finch methods.
5
    """
6

7
    use ExVCR.Converter
8

9
    alias ExVCR.Util
10

11
    defp string_to_response(string) do
12
      response = Enum.map(string, fn {x, y} -> {String.to_atom(x), y} end)
225✔
13
      response = struct(ExVCR.Response, response)
225✔
14

15
      response =
225✔
16
        if response.type == "error" do
225✔
17
          body = string_to_error_reason(response.body)
63✔
18
          %{response | body: body}
63✔
19
        else
20
          response
162✔
21
        end
22

23
      response =
225✔
24
        if is_map(response.headers) do
225✔
25
          headers =
162✔
26
            response.headers
162✔
27
            |> Map.to_list()
28
            |> Enum.map(fn {k, v} -> {k, v} end)
580✔
29

30
          %{response | headers: headers}
162✔
31
        else
32
          response
63✔
33
        end
34

35
      response
225✔
36
    end
37

38
    defp string_to_error_reason(reason) do
39
      {reason_struct, _} = Code.eval_string(reason)
63✔
40
      reason_struct
63✔
41
    end
42

43
    defp request_to_string([request, finch_module]) do
44
      request_to_string([request, finch_module, []])
81✔
45
    end
46

47
    defp request_to_string([request, _finch_module, opts]) do
48
      url =
90✔
49
        Util.build_url(request.scheme, request.host, request.path, request.port, request.query)
90✔
50

51
      %ExVCR.Request{
90✔
52
        url: parse_url(url),
53
        headers: parse_headers(request.headers),
90✔
54
        method: String.downcase(request.method),
90✔
55
        body: parse_request_body(request.body),
90✔
56
        options: parse_options(sanitize_options(opts))
57
      }
58
    end
59

60
    # If option value is tuple, make it as list, for encoding as json.
61
    defp sanitize_options(options) do
62
      Enum.map(options, fn {key, value} ->
90✔
63
        if is_tuple(value) do
9✔
64
          {key, Tuple.to_list(value)}
65
        else
66
          {key, value}
2✔
67
        end
68
      end)
69
    end
70

71
    defp response_to_string({:ok, %Finch.Response{} = response}), do: response_to_string(response)
76✔
72

73
    defp response_to_string(%Finch.Response{} = response) do
74
      %ExVCR.Response{
81✔
75
        type: "ok",
76
        status_code: response.status,
81✔
77
        headers: parse_headers(response.headers),
81✔
78
        body: to_string(response.body)
81✔
79
      }
80
    end
81

82
    defp response_to_string({:error, reason}) do
83
      %ExVCR.Response{
9✔
84
        type: "error",
85
        body: error_reason_to_string(reason)
86
      }
87
    end
88

89
    defp error_reason_to_string(reason), do: Macro.to_string(reason)
9✔
90
  end
91
end
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc