jsonld-ex/test/support/test_document_loader.ex
rustra 140faf4741
Add unit tests for remote context (#4)
* Improve RemoteDocTest
* Add unit tests for remote context
* Add unit tests for default document loader
2020-06-19 01:41:34 +02:00

24 lines
600 B
Elixir

defmodule JSON.LD.DocumentLoader.Test do
@behaviour JSON.LD.DocumentLoader
alias JSON.LD.DocumentLoader.RemoteDocument
def load(url, _options) do
with {:ok, data} <- load_context(url) do
{:ok, %RemoteDocument{document: data, document_url: url}}
end
end
defp load_context("http://example.com/test-context") do
{:ok,
%{
"@context" => %{
"homepage" => %{"@id" => "http://xmlns.com/foaf/0.1/homepage", "@type" => "@id"},
"name" => "http://xmlns.com/foaf/0.1/name"
}
}}
end
defp load_context(_), do: {:error, :invalid_url}
end