Skip to content

Commit

Permalink
Add more tests for Postoffice external API (mercadona#43)
Browse files Browse the repository at this point in the history
  • Loading branch information
lonamiaec authored Feb 10, 2020
1 parent 318966f commit 7fe750a
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions test/postoffice/postoffice_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ defmodule Postoffice.PostofficeTest do
type: "http"
}

@external_publisher_attrs %{
"active" => false,
"target" => "http://fake.target2",
"type" => "pubsub"
}

describe "PostofficeWeb external api" do
test "Returns nil if tried to find message by invalid UUID" do
assert Postoffice.find_message_by_uuid(123) == nil
Expand Down Expand Up @@ -74,5 +80,56 @@ defmodule Postoffice.PostofficeTest do

assert Postoffice.count_topics() == 1
end

test "ping postoffice application" do
assert Postoffice.ping() == :ok
end

test "create_publisher to consume messages from_now" do
topic = Fixtures.create_topic()
message = Fixtures.create_message(topic)
external_publisher_attrs = Map.put(@external_publisher_attrs, "topic_id", topic.id)
external_publisher_attrs = Map.put(external_publisher_attrs, "from_now", "true")

{:ok, saved_publisher} = Postoffice.create_publisher(external_publisher_attrs)
assert saved_publisher.initial_message == message.id
end

test "create_publisher to consume messages from first message" do
topic = Fixtures.create_topic()
external_publisher_attrs = Map.put(@external_publisher_attrs, "topic_id", topic.id)

{:ok, saved_publisher} = Postoffice.create_publisher(external_publisher_attrs)
assert saved_publisher.initial_message == 0
end

test "get_message by id returns asked message" do
topic = Fixtures.create_topic()
message = Fixtures.create_message(topic)

assert Postoffice.get_message(message.id).id == message.id
end

test "get_message_success returns list with success for this message" do
topic = Fixtures.create_topic()
message = Fixtures.create_message(topic)
publisher = Fixtures.create_publisher(topic)
Fixtures.create_publisher_success(message, publisher)

retrieved_success = Postoffice.get_message_success(message.id)

assert Kernel.length(retrieved_success) == 1
end

test "get_message_failures returns list with failures for this message" do
topic = Fixtures.create_topic()
message = Fixtures.create_message(topic)
publisher = Fixtures.create_publisher(topic)
Fixtures.create_publishers_failure(message, publisher)

retrieved_failures = Postoffice.get_message_failures(message.id)

assert Kernel.length(retrieved_failures) == 1
end
end
end

0 comments on commit 7fe750a

Please sign in to comment.