defmodule CatalogApi.Fixture do @moduledoc """ Provides `%HTTPoison.Response{}` fixtures of CatalogAPI responses. These can be used to write tests which ensure that everything is wired up correctly through the CatalogApi package. """ alias HTTPoison.Response @response_headers [ {"Access-Control-Allow-Methods", "GET"}, {"Access-Control-Allow-Origin", "*"}, {"Content-Type", "application/json"}, {"Date", "Sat, 17 Feb 2018 23:03:56 GMT"}, {"Server", "nginx/1.1.19"}, {"Content-Length", "113"}, {"Connection", "keep-alive"} ] @fault_json "{\"Fault\": {\"faultcode\": \"Client.ArgumentError\", \"faultstring\": \"A valid socket_id is required.\", \"detail\": null}}" @doc """ Returns a `%HTTPPoison.Response{}` struct with a 400 status code and a body which matches the Fault json structure that CatalogApi returns. Returns only the body text if passed an argument of false to `as_response`. """ @spec fault(boolean()) :: String.t | Response.t def fault(as_response \\ true) do case as_response do true -> @fault_json |> as_response(400) false -> @fault_json end end @internal_error_json "" @doc """ Returns a `%HTTPPoison.Response{}` struct with a 500 status code. """ @spec internal_error() :: Response.t def internal_error, do: @internal_error_json |> as_response(500) @search_catalog_success_json "{\"search_catalog_response\": {\"search_catalog_result\": {\"items\": {\"CatalogItem\": [{\"original_price\": \"11.42\", \"catalog_price\": \"11.42\", \"image_300\": \"https://dck0i7x64ch95.cloudfront.net/asset/b/3/e/b3ead5dc9d8e3b4e39ff4a27e3a183ac_300_.jpg\", \"name\": \"Brown Bear, Brown Bear, What Do You See?: 50th Anniversary Edition\", \"tags\": {\"string\": []}, \"brand\": \"Henry Holt & Company\", \"categories\": {\"integer\": [156, 179]}, \"rank\": 300, \"options\": {}, \"catalog_item_id\": 1168951, \"currency\": \"USD\", \"points\": 229, \"shipping_estimate\": \"4.00\", \"image_150\": \"https://dck0i7x64ch95.cloudfront.net/asset/b/3/e/b3ead5dc9d8e3b4e39ff4a27e3a183ac_150_.jpg\", \"original_points\": 229, \"retail_price\": \"7.95\", \"has_options\": 0, \"model\": \"9780805047905\", \"image_75\": \"https://dck0i7x64ch95.cloudfront.net/asset/b/3/e/b3ead5dc9d8e3b4e39ff4a27e3a183ac_75_.jpg\"}]}, \"pager\": {\"has_next\": 0, \"sort\": \"score desc\", \"page\": 1, \"first_page\": 1, \"last_page\": 1, \"has_previous\": 0, \"per_page\": 10, \"pages\": {\"integer\": [1]}, \"result_count\": 1}, \"credentials\": {\"checksum\": \"Cyawkogo/jPEmTZMD89TqQCUmkc=\", \"method\": \"search_catalog\", \"uuid\": \"5b58c232-5d2b-4bad-be28-1aeed14c6c88\", \"datetime\": \"2018-02-17T23:55:08.262679+00:00\"}}}}" @doc """ Returns a `%HTTPPoison.Response{}` struct with a 200 status code and a body which contains a successful response to the search_catalog method. Returns only the body text if passed an argument of false to `as_response`. """ @spec fault(boolean()) :: String.t | Response.t @spec search_catalog_success(boolean()) :: String.t | Response.t def search_catalog_success(as_response \\ true) do case as_response do true -> @search_catalog_success_json |> as_response(200) false -> @search_catalog_success_json end end @view_item_success_json "{\"view_item_response\": {\"view_item_result\": {\"item\": {\"original_price\": \"28.97\", \"catalog_price\": \"28.97\", \"image_300\": \"https://dck0i7x64ch95.cloudfront.net/asset/1/d/4/1d49ef849ac7d399ccc5ebe0f24d3b7e_300_.jpg\", \"description\": \"