+ setup do
+ GenServer.start(Streamer, %{}, name: Streamer)
+
+ on_exit(fn ->
+ if pid = Process.whereis(Streamer) do
+ Process.exit(pid, :kill)
+ end
+ end)
+ end
+
+ test "it creates a notification for user and send to the 'user' and the 'user:notification' stream" do
+ user = insert(:user)
+ task = Task.async(fn -> assert_receive {:text, _}, 4_000 end)
+ task_user_notification = Task.async(fn -> assert_receive {:text, _}, 4_000 end)
+ Streamer.add_socket("user", %{transport_pid: task.pid, assigns: %{user: user}})
+
+ Streamer.add_socket(
+ "user:notification",
+ %{transport_pid: task_user_notification.pid, assigns: %{user: user}}
+ )
+
+ activity = insert(:note_activity)
+
+ notify = Notification.create_notification(activity, user)
+ assert notify.user_id == user.id
+ Task.await(task)
+ Task.await(task_user_notification)
+ end
+