Skip to content

Commit

Permalink
Simplfy customer test, add spec and documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
sorentwo committed Jun 4, 2016
1 parent 9169c19 commit aae307a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
10 changes: 10 additions & 0 deletions lib/customer.ex
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,16 @@ defmodule Braintree.Customer do
end
end

@doc """
Convert a map into a Company struct along with nested payment options. Credit
cards and paypal accounts are converted to a list of structs as well.
## Example
customer = Braintree.Customer.construct(%{company: "Soren",
email: "parker@example.com"})
"""
@spec construct(Map.t) :: t
def construct(map) do
company = super(map)

Expand Down
22 changes: 6 additions & 16 deletions test/customer_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -22,37 +22,27 @@ defmodule Braintree.CustomerTest do
assert customer.paypal_accounts == []
end

test "construct/1 converts the `credit_cards` to a list of known structs" do
test "construct/1 converts nested payment methods to a list of known structs" do
customer = Customer.construct(%{
"company" => "Soren",
"email" => "parker@example.com",
"credit_cards" => [%{
"bin" => "12345",
"card_type" => "Visa"
}],
"paypal_accounts" => [%{
"email" => "parker@example.com",
"token" => "t0k3n"
}]
})

assert customer.company == "Soren"
assert Enum.any?(customer.credit_cards)
assert Enum.any?(customer.paypal_accounts)

[card] = customer.credit_cards

assert card.bin == "12345"
assert card.card_type == "Visa"
end

test "construct/1 converts the `paypal_accounts` to a list of known structs" do
customer = Customer.construct(%{
"company" => "Soren",
"email" => "parker@example.com",
"paypal_accounts" => [%{
"email" => "parker@example.com",
"token" => "t0k3n"
}]
})

assert customer.company == "Soren"
assert Enum.any?(customer.paypal_accounts)

[paypal] = customer.paypal_accounts

Expand Down

0 comments on commit aae307a

Please sign in to comment.