parent
259fce7580
commit
2d9cd92def
@ -0,0 +1,20 @@ |
||||
defmodule ExplorerWeb.AddressChannelTest do |
||||
use ExplorerWeb.ChannelCase |
||||
|
||||
describe "addresses channel tests" do |
||||
test "subscribed user can receive channel message" do |
||||
channel = "addresses" |
||||
@endpoint.subscribe(channel) |
||||
|
||||
ExplorerWeb.Endpoint.broadcast(channel, "transaction", %{body: "test"}) |
||||
|
||||
receive do |
||||
%Phoenix.Socket.Broadcast{event: "transaction", topic: ^channel, payload: %{body: body}} -> |
||||
assert body == "test" |
||||
after |
||||
5_000 -> |
||||
assert false, "Expected message received nothing." |
||||
end |
||||
end |
||||
end |
||||
end |
@ -0,0 +1,41 @@ |
||||
defmodule ExplorerWeb.ChannelCase do |
||||
@moduledoc """ |
||||
This module defines the test case to be used by |
||||
channel tests. |
||||
|
||||
Such tests rely on `Phoenix.ChannelTest` and also |
||||
import other functionality to make it easier |
||||
to build common datastructures and query the data layer. |
||||
|
||||
Finally, if the test case interacts with the database, |
||||
it cannot be async. For this reason, every test runs |
||||
inside a transaction which is reset at the beginning |
||||
of the test unless the test case is marked as async. |
||||
""" |
||||
|
||||
use ExUnit.CaseTemplate |
||||
|
||||
using do |
||||
quote do |
||||
# Import conveniences for testing with channels |
||||
use Phoenix.ChannelTest |
||||
|
||||
# The default endpoint for testing |
||||
@endpoint ExplorerWeb.Endpoint |
||||
|
||||
import Explorer.Factory |
||||
end |
||||
end |
||||
|
||||
@dialyzer {:nowarn_function, __ex_unit_setup_0: 1} |
||||
setup tags do |
||||
:ok = Ecto.Adapters.SQL.Sandbox.checkout(Explorer.Repo) |
||||
|
||||
unless tags[:async] do |
||||
Ecto.Adapters.SQL.Sandbox.mode(Explorer.Repo, {:shared, self()}) |
||||
end |
||||
|
||||
:ok |
||||
# {k:ok, conn: %Plug.Conn{} |> Plug.Conn.put_private(:phoenix_endpoint, ExplorerWeb.Endpoint)} |
||||
end |
||||
end |
Loading…
Reference in new issue