@@ -14,6 +14,12 @@ defmodule CodeCorps.MessagesTest do
1414 records |> Enum . map ( & Map . get ( & 1 , :id ) ) |> Enum . sort
1515 end
1616
17+ defp json_map ( attrs ) do
18+ attrs
19+ |> Poison . encode!
20+ |> Poison . decode!
21+ end
22+
1723 describe "list" do
1824 test "returns all records by default" do
1925 insert_list ( 3 , :message )
@@ -249,15 +255,15 @@ defmodule CodeCorps.MessagesTest do
249255
250256 describe "add_part/1" do
251257 test "creates a conversation part" do
252- conversation = insert ( :conversation )
258+ conversation = insert ( :conversation , updated_at: Timex . now |> Timex . shift ( minutes: - 5 ) )
253259 user = insert ( :user )
254260 attrs = % {
255261 author_id: user . id ,
256262 body: "Test body" ,
257263 conversation_id: conversation . id
258264 }
259265
260- { :ok , % ConversationPart { } = conversation_part } = Messages . add_part ( attrs )
266+ { :ok , % ConversationPart { } = conversation_part } = Messages . add_part ( attrs |> json_map ( ) )
261267
262268 conversation_part =
263269 conversation_part
@@ -266,6 +272,7 @@ defmodule CodeCorps.MessagesTest do
266272 assert conversation_part . author_id == user . id
267273 assert conversation_part . body == "Test body"
268274 assert conversation_part . conversation_id == conversation . id
275+ assert conversation_part . updated_at == conversation_part . conversation . updated_at
269276 end
270277
271278 test "broadcasts event on phoenix channel" do
@@ -278,7 +285,7 @@ defmodule CodeCorps.MessagesTest do
278285 }
279286
280287 CodeCorpsWeb.Endpoint . subscribe ( "conversation:#{ conversation . id } " )
281- { :ok , % ConversationPart { id: id } } = Messages . add_part ( attrs )
288+ { :ok , % ConversationPart { id: id } } = Messages . add_part ( attrs |> json_map ( ) )
282289 assert_broadcast ( "new:conversation-part" , % { id: ^ id } )
283290 CodeCorpsWeb.Endpoint . unsubscribe ( "conversation:#{ conversation . id } " )
284291 end
@@ -295,7 +302,7 @@ defmodule CodeCorps.MessagesTest do
295302 conversation_id: conversation . id
296303 }
297304
298- { :ok , % ConversationPart { } = part } = Messages . add_part ( attrs )
305+ { :ok , % ConversationPart { } = part } = Messages . add_part ( attrs |> json_map ( ) )
299306
300307 part = part |> Repo . preload ( [ :author , conversation: [ message: [ [ project: :organization ] ] ] ] )
301308
@@ -317,7 +324,7 @@ defmodule CodeCorps.MessagesTest do
317324 conversation_id: conversation . id
318325 }
319326
320- { :ok , % ConversationPart { } = part } = Messages . add_part ( attrs )
327+ { :ok , % ConversationPart { } = part } = Messages . add_part ( attrs |> json_map ( ) )
321328
322329 part = part |> Repo . preload ( [ :author , conversation: [ message: [ [ project: :organization ] ] ] ] )
323330
0 commit comments