Skip to content

Commit

Permalink
Added Messages.add_part test for channel
Browse files Browse the repository at this point in the history
  • Loading branch information
begedin committed Dec 18, 2017
1 parent ab765e3 commit 2c31b58
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions test/lib/code_corps/messages/messages_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ defmodule CodeCorps.MessagesTest do
@moduledoc false

use CodeCorps.DbAccessCase
use Phoenix.ChannelTest

import Ecto.Query, only: [where: 2]

Expand Down Expand Up @@ -327,6 +328,21 @@ defmodule CodeCorps.MessagesTest do
assert conversation_part.body == "Test body"
assert conversation_part.conversation_id == conversation.id
end

test "broadcasts event on phoenix channel" do
conversation = insert(:conversation)
user = insert(:user)
attrs = %{
author_id: user.id,
body: "Test body",
conversation_id: conversation.id
}

CodeCorpsWeb.Endpoint.subscribe("conversation:#{conversation.id}")
{:ok, %ConversationPart{id: id}} = Messages.add_part(attrs)
assert_broadcast("new:conversation-part", %{id: ^id})
CodeCorpsWeb.Endpoint.unsubscribe("conversation:#{conversation.id}")
end
end

describe "create/1" do
Expand Down

0 comments on commit 2c31b58

Please sign in to comment.