forked from nsweeting/shopify
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make mock adapter usable for testing
Make adapter configurable and make mock adapter public
- Loading branch information
Showing
4 changed files
with
50 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,13 @@ | ||
defmodule Shopify.Client do | ||
@moduledoc false | ||
|
||
@adapter Shopify.Config.get(:client_adapter) || Shopify.Adapters.HTTP | ||
alias Shopify.Config | ||
|
||
def get(request), do: @adapter.get(request) | ||
def get(request), do: Config.client_adapter.get(request) | ||
|
||
def post(request), do: @adapter.post(request) | ||
def post(request), do: Config.client_adapter.post(request) | ||
|
||
def put(request), do: @adapter.put(request) | ||
def put(request), do: Config.client_adapter.put(request) | ||
|
||
def delete(request), do: @adapter.delete(request) | ||
def delete(request), do: Config.client_adapter.delete(request) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,21 @@ | ||
defmodule Shopify.Config do | ||
@moduledoc false | ||
|
||
def get(name, default \\ nil) do | ||
Application.get_env(:shopify, name, default) | ||
end | ||
|
||
def client_adapter, do: get(:client_adapter, Shopify.Adapters.HTTP) | ||
|
||
def shop_name, do: get(:shop_name) | ||
|
||
def api_key, do: get(:api_key) | ||
|
||
def password, do: get(:password) | ||
|
||
def version, do: Mix.Project.config[:version] | ||
end | ||
|
||
def fixtures_path do | ||
get(:fixtures_path) || Path.expand("../../test/fixtures/", __DIR__) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
defmodule Shopify.Adapters.Mocktest do | ||
use ExUnit.Case, async: true | ||
|
||
alias Shopify.{Webhook, Request, Adapters.Mock} | ||
|
||
test "it puts an id for created resources" do | ||
body = "{\"webhook\": {\"address\": \"http://www.yoloship.it/webhook\"}}" | ||
|
||
{:ok, %{data: resource}} = Shopify.session | ||
|> Request.new(Webhook.all_url(), %{}, Webhook.singular_resource(), body) | ||
|> Mock.post | ||
|
||
assert resource.id != nil | ||
end | ||
|
||
end |