View Source Authoritex.Mock (Authoritex v1.1.1)
Mock Authority for testing Authoritex consumers
Examples:
# In test.exs:
# config :authoritex, authorities: [Authoritex.Mock]
# In test_helper.exs:
# Authoritex.Mock.init()
# In test case:
iex> Authoritex.Mock.set_data([
%{id: "mock:result1", label: "First Result", qualified_label: "First Result (1)", hint: "(1)"},
%{id: "mock:result2", label: "Second Result", qualified_label: "Second Result (2)", hint: "(2)"},
%{id: "mock:result3", label: "Third Result", qualified_label: "Third Result (3)", hint: "(3)"}])
:ok
iex> Authoritex.fetch("mock:result2")
{:ok, %{id: "mock:result2", label: "Second Result", qualified_label: "Second Result (2)", hint: "(2)"}}
iex> Authoritex.fetch("missing_id_authority:anything")
{:error, 404}
iex> Authoritex.fetch("wrong")
{:error, :unknown_authority}
iex> Authoritex.search("mock", "test")
{:ok, [
%{id: "mock:result1", label: "First Result", hint: "(1)"},
%{id: "mock:result2", label: "Second Result", hint: "(2)"},
%{id: "mock:result3", label: "Third Result", hint: "(3)"}
]}
iex> Authoritex.search("mock", :no_results)
{:ok, []}
iex> Authoritex.search("mock", :error)
{:error, 500}