|
| 1 | +defmodule SparkPost.SuppressionListTest do |
| 2 | + @moduledoc false |
| 3 | + |
| 4 | + use ExUnit.Case, async: false |
| 5 | + |
| 6 | + alias SparkPost.{MockServer, SuppressionList} |
| 7 | + alias SparkPost.SuppressionList.{SearchResult, ListEntry} |
| 8 | + |
| 9 | + import Mock |
| 10 | + |
| 11 | + test_with_mock "SuppressionList.search succeeds with SuppressionList.SearchResult", |
| 12 | + HTTPoison, [request: fn (method, url, body, headers, opts) -> |
| 13 | + assert method == :get |
| 14 | + fun = MockServer.mk_http_resp(200, MockServer.get_json("suppressionsearch")) |
| 15 | + fun.(method, url, body, headers, opts) |
| 16 | + end] do |
| 17 | + resp = SuppressionList.search() |
| 18 | + assert %SearchResult{} = resp |
| 19 | + end |
| 20 | + |
| 21 | + test_with_mock "SuppressionList.search fails with Endpoint.Error", HTTPoison, |
| 22 | + [request: MockServer.mk_fail] do |
| 23 | + resp = SuppressionList.search() |
| 24 | + assert %SparkPost.Endpoint.Error{} = resp |
| 25 | + end |
| 26 | + |
| 27 | + test_with_mock "SuppressionList.search creates ListEntry structs", HTTPoison, |
| 28 | + [request: fn (method, url, body, headers, opts) -> |
| 29 | + assert method == :get |
| 30 | + fun = MockServer.mk_http_resp(200, MockServer.get_json("suppressionsearch")) |
| 31 | + fun.(method, url, body, headers, opts) |
| 32 | + end] do |
| 33 | + resp = SuppressionList.search() |
| 34 | + assert %SearchResult{ |
| 35 | + results: [ |
| 36 | + %ListEntry{ |
| 37 | + recipient: "test@marketing.com", |
| 38 | + type: "non_transactional", |
| 39 | + source: nil, |
| 40 | + description: nil, |
| 41 | + non_transactional: nil |
| 42 | + } |
| 43 | + ], |
| 44 | + links: [], |
| 45 | + total_count: 1 |
| 46 | + } == resp |
| 47 | + end |
| 48 | + |
| 49 | + test_with_mock "SuppressionList.search parses out cursor info", HTTPoison, |
| 50 | + [request: fn (method, url, body, headers, opts) -> |
| 51 | + assert method == :get |
| 52 | + fun = MockServer.mk_http_resp(200, MockServer.get_json("suppressionsearch_links")) |
| 53 | + fun.(method, url, body, headers, opts) |
| 54 | + end] do |
| 55 | + resp = SuppressionList.search() |
| 56 | + assert %SearchResult{ |
| 57 | + results: [ |
| 58 | + %ListEntry{ |
| 59 | + recipient: "test@marketing.com", |
| 60 | + type: "non_transactional", |
| 61 | + source: nil, |
| 62 | + description: nil, |
| 63 | + non_transactional: nil |
| 64 | + } |
| 65 | + ], |
| 66 | + links: [ |
| 67 | + %{href: "/currentlink", rel: "first"}, |
| 68 | + %{href: "/linkwithcursor", rel: "next"} |
| 69 | + ], |
| 70 | + total_count: 1 |
| 71 | + } == resp |
| 72 | + end |
| 73 | +end |
0 commit comments