Skip to content

Commit

Permalink
Adds header as an option to new_request
Browse files Browse the repository at this point in the history
This had to be done instead of extracting out the headers in options for
all functions that call request.
  • Loading branch information
elijahkim authored and subsetpark committed Feb 22, 2021
1 parent b0d1651 commit fa0e350
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/stripe/request.ex
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ defmodule Stripe.Request do
"""
@spec new_request(Stripe.options(), map) :: t
def new_request(opts \\ [], headers \\ %{}) do
headers =
opts
|> Keyword.get(:headers, %{})
|> Map.merge(headers)

%Request{opts: opts, headers: headers}
end

Expand Down
10 changes: 10 additions & 0 deletions test/stripe/request_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,14 @@ defmodule Stripe.RequestTest do
assert request.opts == opts
end
end

describe "new_request/2" do
test "new_request/1 extracts headers from options and puts it on headers" do
new_request = Request.new_request(headers: %{foo: "bar"})

assert new_request.headers == %{
foo: "bar"
}
end
end
end

0 comments on commit fa0e350

Please sign in to comment.