Update the FetchJsons to allow use a function to transform the data.

This commit is contained in:
2025-03-19 13:38:05 +02:00
parent 57ead52ba2
commit d398cc1594
2 changed files with 25 additions and 8 deletions
@@ -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