@@ -14,6 +14,12 @@ defmodule CodeCorps.MessagesTest do
14
14
records |> Enum . map ( & Map . get ( & 1 , :id ) ) |> Enum . sort
15
15
end
16
16
17
+ defp json_map ( attrs ) do
18
+ attrs
19
+ |> Poison . encode!
20
+ |> Poison . decode!
21
+ end
22
+
17
23
describe "list" do
18
24
test "returns all records by default" do
19
25
insert_list ( 3 , :message )
@@ -249,15 +255,15 @@ defmodule CodeCorps.MessagesTest do
249
255
250
256
describe "add_part/1" do
251
257
test "creates a conversation part" do
252
- conversation = insert ( :conversation )
258
+ conversation = insert ( :conversation , updated_at: Timex . now |> Timex . shift ( minutes: - 5 ) )
253
259
user = insert ( :user )
254
260
attrs = % {
255
261
author_id: user . id ,
256
262
body: "Test body" ,
257
263
conversation_id: conversation . id
258
264
}
259
265
260
- { :ok , % ConversationPart { } = conversation_part } = Messages . add_part ( attrs )
266
+ { :ok , % ConversationPart { } = conversation_part } = Messages . add_part ( attrs |> json_map ( ) )
261
267
262
268
conversation_part =
263
269
conversation_part
@@ -266,6 +272,7 @@ defmodule CodeCorps.MessagesTest do
266
272
assert conversation_part . author_id == user . id
267
273
assert conversation_part . body == "Test body"
268
274
assert conversation_part . conversation_id == conversation . id
275
+ assert conversation_part . updated_at == conversation_part . conversation . updated_at
269
276
end
270
277
271
278
test "broadcasts event on phoenix channel" do
@@ -278,7 +285,7 @@ defmodule CodeCorps.MessagesTest do
278
285
}
279
286
280
287
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 ( ) )
282
289
assert_broadcast ( "new:conversation-part" , % { id: ^ id } )
283
290
CodeCorpsWeb.Endpoint . unsubscribe ( "conversation:#{ conversation . id } " )
284
291
end
@@ -295,7 +302,7 @@ defmodule CodeCorps.MessagesTest do
295
302
conversation_id: conversation . id
296
303
}
297
304
298
- { :ok , % ConversationPart { } = part } = Messages . add_part ( attrs )
305
+ { :ok , % ConversationPart { } = part } = Messages . add_part ( attrs |> json_map ( ) )
299
306
300
307
part = part |> Repo . preload ( [ :author , conversation: [ message: [ [ project: :organization ] ] ] ] )
301
308
@@ -317,7 +324,7 @@ defmodule CodeCorps.MessagesTest do
317
324
conversation_id: conversation . id
318
325
}
319
326
320
- { :ok , % ConversationPart { } = part } = Messages . add_part ( attrs )
327
+ { :ok , % ConversationPart { } = part } = Messages . add_part ( attrs |> json_map ( ) )
321
328
322
329
part = part |> Repo . preload ( [ :author , conversation: [ message: [ [ project: :organization ] ] ] ] )
323
330
0 commit comments