CommcareAPI.FakeCommcare (commcare_api v0.3.1) View Source
Statefully mocks the CommCare API.
Usage
iex> FakeCommcare.start_link("path/to/initial/state.json")
iex> FakeCommcare.add_contact(body)
iex> FakeCommcare.get_json()
Link to this section Summary
Functions
Adds a contact in XML form to the server state.
Returns a specification to start this module under a supervisor.
Returns the state of the server as JSON.
Spins up the fake server by populating some initial based on the contents of the file.
Link to this section Functions
Specs
add_contact(binary()) :: :ok
Adds a contact in XML form to the server state.
Example
iex> CommcareAPI.FakeCommcare.start_link("path/to/state.json")
iex> xml = "<?xml version="1.0" ?>
<data>
...
</data>"
iex> CommcareAPI.FakeCommcare.add_contact(xml)
:ok
iex> CommcareAPI.FakeCommcare.get_json()
"{ json with the XML as contact }"
Returns a specification to start this module under a supervisor.
See Supervisor
.
Specs
get_json() :: binary()
Returns the state of the server as JSON.
Example
iex> File.read!("path/to/state.json")
"{
"my": "state" }"
iex> CommcareAPI.FakeCommcare.start_link("path/to/state.json")
{:ok, pid}
iex> CommcareAPI.FakeCommcare.get_json()
"{"my": "state"}"
Specs
Spins up the fake server by populating some initial based on the contents of the file.
Example
iex> start_link("path/to/state.json")