Update the FetchJsons to allow use a function to transform the data.
This commit is contained in:
@@ -17,5 +17,21 @@ defmodule DecentralisedBookIndex.Sync.ApiClients.FetchJsonsTest do
|
||||
assert {:ok, records} = FetchJsons.get("#{@test_server_endpoint}/api/v1/json/author")
|
||||
assert length(records) == 11
|
||||
end
|
||||
|
||||
test "get authors names from API" do
|
||||
for number <- 1..11 do
|
||||
Metadata.create_author!("Author#{number}", "An description#{number}")
|
||||
end
|
||||
|
||||
get_author_names = fn data ->
|
||||
Enum.map(data, fn author -> author["attributes"]["name"] end)
|
||||
end
|
||||
|
||||
assert {:ok, records} =
|
||||
FetchJsons.get("#{@test_server_endpoint}/api/v1/json/author", get_author_names)
|
||||
|
||||
assert length(records) == 11
|
||||
assert Enum.all?(records, fn author -> String.contains?(author, "Author") end)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user