Skip to content

Commit

Permalink
add test for Quotes.parse_json() #4 🔴
Browse files Browse the repository at this point in the history
  • Loading branch information
nelsonic committed Oct 13, 2019
1 parent 290ed1f commit 0d02d87
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions test/quotes_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,25 @@ defmodule QuotesTest do
test "greets the world" do
assert Quotes.hello() == :world
end

test "parse_json returns a list of maps containing quotes" do
list = Quotes.parse_json()
assert Enum.count(list) == Utils.count()

# sample quote we know is in the list
sample = %{
"author" => "Albert Einstein",
"text" => "A person who never made a mistake never tried anything new."
}

# find the sample quote in the List of Maps:
[found] = Enum.map(list, fn q ->
if q["author"] == sample["author"] && q["text"] == sample["text"] do
q
end
end)
|> Enum.filter(& !is_nil(&1)) # filter out any nil values
assert sample == found # sample quote was found in the list
end

end

0 comments on commit 0d02d87

Please sign in to comment.