closex v0.8.2 Closex.MockClient
This module is for testing, it allows you to stub requests to CloseIO.
It behaves like the standard client so you can drop it into your code via configuration in your testing environment, but it will return the test objects for each method.
It gets these test objects from json files, for more detail see the test/fixtures/*.json
files.
However, you can override the response of the mock client with json more specific to your domain:
# your_app/config/test.exs
config :yourapp,
closeio_client: Closex.MockClient,
...other configuration...
config :closex,
mock_client_fixtures_dir: Path.join([File.cwd!, "path", "to", "your", "fixtures"])
If you’d like to emulate not finding an object, pass in the Closex.MockClient.not_found_id
value.
For specific examples please see the documentation for the method you’re using.
Link to this section Summary
Functions
Creates a lead in CloseIO
Creates an opportunity in CloseIO
Stubs finding leads in CloseIO
Finds an opportunity in CloseIO
Gets a lead from CloseIO
Gets a lead custom field from CloseIO
Gets the potential statuses of a lead from CloseIO
Gets an opportunity from CloseIO
Gets the potential statuses of an opportunity from CloseIO
Gets an organization from CloseIO
Gets the users available in CloseIO
Sends an email CloseIO
Update a lead in CloseIO
Update an Opportunity in CloseIO
Link to this section Functions
Creates a lead in CloseIO.
Returns {:ok, lead}
Examples
> Closex.MockClient.create_lead(%{}) …contents of test/fixtures/create_lead.json…
Creates an opportunity in CloseIO.
Returns {:ok, opportunity}
Examples
> Closex.MockClient.create_opportunity(%{}) …contents of test/fixtures/create_opportunity.json…
Stubs finding leads in CloseIO.
Returns {:ok, leads}
or {:error, error}
tuple.
Examples
By default, this returns the contents of the find_one_lead.json
fixture.
> Closex.MockClient.find_leads("foo")
...contents of test/fixtures/find_one_lead.json...
Specific search results can be returned by storing a response in your
test/fixtures
directly which corresponds to the specific query. It must
be named find_leads_<search>.json
, otherwise we will use default. Note, we
turn spaces into underscores.
> Closex.MockClient.find_leads("some lead")
...contents of test/fixtures/find_leads_some_lead.json
Additional helper queries available are:
iex> Closex.MockClient.find_leads(Closex.MockClient.not_found_query())
{:ok, %{"data" => [], "has_more" => false, "total_results" => 0}}
> Closex.MockClient.find_leads(Closex.MockClient.multiple_results_query())
...contents of test/fixtures/find_multiple_leads.json...
iex> Closex.MockClient.find_leads(Closex.MockClient.timeout_query())
{:error, %HTTPoison.Error{id: nil, reason: :timeout}}
Finds an opportunity in CloseIO.
Returns {:ok, opportunities}
.
You can hand in any search term you like and it will return an example search which finds one example lead.
You can also search for something you are not expecting to find with our not_found_id. This will provide the empty result set in find_no_opportunities.json.
We have provided an example search term to use when the search term doesn’t matter to you.
Examples
> Closex.MockClient.find_opportunities(“foo”) …contents of test/fixtures/find_one_opportunity.json…
iex> Closex.MockClient.find_opportunities(Closex.MockClient.not_found_query()) {:ok, %{“data” => [], “has_more” => false, “total_results” => 0}}
> Closex.MockClient.find_opportunities(Closex.MockClient.multiple_results_query()) …contents of test/fixtures/find_multiple_opportunities.json…
Gets a lead from CloseIO.
Returns {:ok, lead}
.
You can hand in any lead id you like and it will return an example lead with that id.
We have provided an example id to use when the id doesn’t matter to you.
Examples
> Closex.MockClient.get_lead(Closex.MockClient.lead_id()) …contents of test/fixtures/lead.json…
iex> Closex.MockClient.get_lead(Closex.MockClient.not_found_id())
iex> Closex.MockClient.get_lead(Closex.MockClient.timeout_query()) {:error, %HTTPoison.Error{id: nil, reason: :timeout}}
Gets a lead custom field from CloseIO.
Returns {:ok, lead_custom_field}
.
You can hand in any custom field id you like and it will return an example custom field with that id.
We have provided an example id to use when the id doesn’t matter to you.
Examples
> Closex.MockClient.get_lead_custom_field(Closex.MockClient.lead_custom_field_id()) …contents of test/fixtures/lead_custom_field.json…
iex> Closex.MockClient.get_lead_custom_field(Closex.MockClient.not_found_id())
Gets the potential statuses of a lead from CloseIO.
Returns {:ok, lead_statuses}
.
Examples
> Closex.MockClient.get_lead_statuses() …contents of test/fixtures/lead_statuses.json…
Gets an opportunity from CloseIO.
Returns {:ok, opportunity}
.
You can hand in any opportunity id you like and it will return an example opportunity with that id.
We have provided an example id to use when the id doesn’t matter to you.
Examples
> Closex.MockClient.get_opportunity(Closex.MockClient.opportunity_id()) …contents of test/fixtures/opportunity.json…
iex> Closex.MockClient.get_opportunity(Closex.MockClient.not_found_id())
Gets the potential statuses of an opportunity from CloseIO.
Returns {:ok, opportunity_statuses}
.
Examples
> Closex.MockClient.get_opportunity_statuses() …contents of test/fixtures/opportunity_statuses.json…
Gets an organization from CloseIO.
Returns {:ok, organization}
.
You can hand in any organization id you like and it will return an example organization with that id.
We have provided an example id to use when the id doesn’t matter to you.
Examples
> Closex.MockClient.get_organization(Closex.MockClient.organization_id()) …contents of test/fixtures/organization.json…
iex> Closex.MockClient.get_organization(Closex.MockClient.not_found_id())
Gets the users available in CloseIO.
Returns {:ok, users}
.
Examples
> Closex.MockClient.get_users() …contents of test/fixtures/users.json…
Sends an email CloseIO.
Returns {:ok, email}
Examples
> Closex.MockClient.send_email(%{}) …contents of test/fixtures/send_email.json…
Update a lead in CloseIO.
Returns {:ok, lead}
.
You can hand in any lead id you like and it will return an example lead with that id, with your updates merged in. Any dates you hand in to be merged will be parsed to strings when they are returned.
We have provided an example id to use when the id doesn’t matter to you.
Examples
> Closex.MockClient.update_lead(Closex.MockClient.lead_id(), %{}) …contents of test/fixtures/organization.json…
iex> Closex.MockClient.update_lead(Closex.MockClient.not_found_id(), %{})
iex> Closex.MockClient.update_lead(Closex.MockClient.not_found_id(), %{“foo” => “bar”})
Update an Opportunity in CloseIO.
Returns {:ok, opportunity}
.
You can hand in any opportunity id you like and it will return an example opportunity with that id, with your updates merged in.
We have provided an example id to use when the id doesn’t matter to you.
Examples
> Closex.MockClient.update_opportunity(Closex.MockClient.opportunity_id(), %{}) …contents of test/fixtures/organization.json…
iex> Closex.MockClient.update_opportunity(Closex.MockClient.not_found_id(), %{})
iex> Closex.MockClient.update_opportunity(Closex.MockClient.not_found_id(), %{“foo” => “bar”})