@@ -244,19 +244,33 @@ defmodule CodeCorps.MessagesTest do
244244 end
245245
246246 describe "update_conversation/2" do
247- @ reopened "reopned"
248247
249- test "creates a conversation_part of part_type reopened when reopened" do
248+ test "creates a conversation_part of part_type reopened when a conversation is reopened" do
250249 conversation = insert ( :conversation )
251250
252251 assert Repo . aggregate ( ConversationPart , :count , :id ) == 0
252+ conversation = Messages . get_conversation ( conversation . id )
253+ { _ok , _updated } = Messages . update_conversation ( conversation , % { status: "reopened" } )
254+
255+ assert Repo . aggregate ( ConversationPart , :count , :id ) == 1
253256
254- conversation = Messages . get_conversation ( conversation . id )
255-
256- updated = Messages . update_conversation ( conversation , % { status: "reopened" } )
257+ conversation_part = Repo . get_by ( ConversationPart , part_type: "reopened" )
258+ assert conversation_part . author_id == conversation . user_id
259+ assert conversation_part . conversation_id == conversation . id
260+ end
261+
262+ test "creates a conversation_part of part_type closed when a conversation is reopened" do
263+ conversation = insert ( :conversation )
257264
265+ assert Repo . aggregate ( ConversationPart , :count , :id ) == 0
266+ conversation = Messages . get_conversation ( conversation . id )
267+ { _ok , _updated } = Messages . update_conversation ( conversation , % { status: "closed" } )
268+
258269 assert Repo . aggregate ( ConversationPart , :count , :id ) == 1
259- assert Repo . get_by ( ConversationPart , part_type: "reopened" )
270+
271+ conversation_part = Repo . get_by ( ConversationPart , part_type: "closed" )
272+ assert conversation_part . author_id == conversation . user_id
273+ assert conversation_part . conversation_id == conversation . id
260274 end
261275 end
262276
0 commit comments