aboutsummaryrefslogtreecommitdiff
path: root/test/zendex/ticket_test.exs
blob: c4250d11f8862b9c2d792f14bbb33854a2e11791 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
defmodule Zendex.TicketTest do
  use ExUnit.Case, async: false

  setup do
    %{conn: Zendex.Connection.setup("http://test.zendesk.com",
                                    "User",
                                    "Password123!")}
  end

  setup_all do
    :meck.new(HTTPoison)
    on_exit fn -> :meck.unload end
    :ok
  end

  test "getting tickets", %{conn: conn} do
    stub = fn("http://test.zendesk.com/api/v2/tickets.json",
              [{"Authorization", "Basic VXNlcjpQYXNzd29yZDEyMyE="}]) ->
      %HTTPoison.Response{body: Poison.encode!("ticket")}
    end
    :meck.expect(HTTPoison, :get!, stub)

    assert "ticket" == Zendex.Ticket.list(conn)
  end

  test "creating a ticket", %{conn: conn} do
    stub = fn("http://test.zendesk.com/api/v2/tickets.json",
              "{\"ticket\":{\"title\":\"HELP!\"}}",
              [{"Authorization", "Basic VXNlcjpQYXNzd29yZDEyMyE="},
               {"Content-Type", "application/json"}]) ->
      %HTTPoison.Response{body: Poison.encode!("Ticket created successfully!")}
    end
    :meck.expect(HTTPoison, :post!, stub)

    assert "Ticket created successfully!" ==
      Zendex.Ticket.create(conn, %{"ticket": %{"title": "HELP!"}})
  end
end