Skip to content

Commit

Permalink
Add options for institutions.get_by_id
Browse files Browse the repository at this point in the history
Add options for institutions.get_by_id
  • Loading branch information
jacobcovington authored May 15, 2021
2 parents 34b5210 + 798f25a commit cbd0332
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
12 changes: 8 additions & 4 deletions lib/plaid/institutions.ex
Original file line number Diff line number Diff line change
Expand Up @@ -119,13 +119,17 @@ defmodule Plaid.Institutions do
end

@doc """
Gets an institution by id.
Parameters
```
"ins_109512"
OR
%{institution_id: "ins_109512", options: %{include_optional_metadata: true, include_status: false}}
"""
@spec get_by_id(String.t(), config | nil) ::
@spec get_by_id(String.t() | params, config | nil) ::
{:ok, Plaid.Institutions.Institution.t()} | {:error, Plaid.Error.t()}
def get_by_id(id, config \\ %{}) do
def get_by_id(params, config \\ %{}) do
config = validate_cred(config)
params = %{institution_id: id}
params = if is_binary(params), do: %{institution_id: params}, else: params
endpoint = "#{@endpoint}/get_by_id"

make_request_with_cred(:post, endpoint, config, params)
Expand Down
19 changes: 18 additions & 1 deletion test/lib/plaid/institutions_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ defmodule Plaid.InstitutionsTest do
assert {:ok, _} = Jason.encode(resp)
end

test "get_by_id/1 requests POST and returns Plaid.Institutions.Institution", %{bypass: bypass} do
test "get_by_id/1 requests POST with string params and returns Plaid.Institutions.Institution", %{bypass: bypass} do
body = http_response_body(:institution)

Bypass.expect(bypass, fn conn ->
Expand All @@ -38,6 +38,23 @@ defmodule Plaid.InstitutionsTest do
assert {:ok, _} = Jason.encode(resp)
end

test "get_by_id/1 requests POST with map params and returns Plaid.Institutions.Institution", %{bypass: bypass} do
body = http_response_body(:institution)

Bypass.expect(bypass, fn conn ->
assert "POST" == conn.method
assert "institutions/get_by_id" == Enum.join(conn.path_info, "/")
{:ok, request_body, _conn} = Plug.Conn.read_body(conn)
{institution_id, options} = Jason.decode(request_body)

Plug.Conn.resp(conn, 200, Poison.encode!(body))
end)

assert {:ok, resp} = Plaid.Institutions.get_by_id(%{institution_id: "ins_109512", options: %{include_optional_metadata: true}})
assert Plaid.Institutions.Institution == resp.__struct__
assert {:ok, _} = Jason.encode(resp)
end

test "search/1 requests POST and returns Plaid.Institutions", %{bypass: bypass} do
body = http_response_body(:institutions)

Expand Down

0 comments on commit cbd0332

Please sign in to comment.