shopify v0.4.0 Shopify.Adapters.MockUtils
Some useful functions to help implementing a mock adapter.
Link to this section Summary
Functions
Filter resources if query params given and the resource is a list
Puts an id into resources, usefull for create options that would otherwise return the resource built from the body without an id
Link to this section Functions
Link to this function
filter_resources(resp, arg2)
filter_resources( Shopify.Adapters.Base.success() | Shopify.Adapters.Base.error(), Shopify.Request.t() ) :: Shopify.Adapters.Base.success() | Shopify.Adapters.Base.error()
Filter resources if query params given and the resource is a list.
This is a naive implementation that will fail whenever the query parameter keys do not correspond to the resource keys.
Examples
iex> Shopify.Adapters.MockUtils.filter_resources({:ok, %Shopify.Response{data: [%{a: "a"}, %{a: "b"}]}}, %Shopify.Request{query_params: %{a: "a"}})
{:ok, %Shopify.Response{code: nil, data: [%{a: "a"}]}}
iex> Shopify.Adapters.MockUtils.filter_resources({:ok, %Shopify.Response{data: [%{a: "a"}, %{a: "b"}, %{a: "c"}]}}, %Shopify.Request{query_params: %{a: ["a", "b"]}})
{:ok, %Shopify.Response{code: nil, data: [%{a: "a"}, %{a: "b"}]}}
Puts an id into resources, usefull for create options that would otherwise return the resource built from the body without an id.