@@ -13,9 +13,45 @@ defmodule CodeCorps.Messages.ConversationPartsTest do
1313
1414 describe "create_changeset/2" do
1515 test "with valid attributes" do
16+ user_id = insert ( :user , id: 1 ) . id
17+ insert ( :conversation , id: 1 )
1618 attrs = @ valid_attrs |> Map . merge ( % { author_id: 1 , conversation_id: 1 } )
19+ { :ok , conversation } = ConversationParts . create_changeset ( % ConversationPart { } , attrs ) |> Repo . insert
20+ assert conversation . body == "Test body."
21+ assert conversation . part_type == "comment"
22+ assert conversation . author_id == user_id
23+ end
24+
25+ test "validates part_type inclusion: note" do
26+ insert ( :user , id: 1 )
27+ insert ( :conversation , id: 1 )
28+ attrs = @ valid_attrs |> Map . merge ( % { author_id: 1 , conversation_id: 1 , part_type: "note" } )
29+ changeset = ConversationParts . create_changeset ( % ConversationPart { } , attrs )
30+ assert changeset . valid?
31+ assert changeset . changes . part_type == "note"
32+ end
33+
34+ test "validates part_type inclusion: reopened" do
35+ attrs = @ valid_attrs |> Map . merge ( % { author_id: 1 , conversation_id: 1 , part_type: "reopened" } )
1736 changeset = ConversationParts . create_changeset ( % ConversationPart { } , attrs )
1837 assert changeset . valid?
38+ assert changeset . changes . part_type == "reopened"
39+ end
40+
41+ test "validates part_type inclusion: closed" do
42+ attrs = @ valid_attrs |> Map . merge ( % { author_id: 1 , conversation_id: 1 , part_type: "closed" } )
43+ changeset = ConversationParts . create_changeset ( % ConversationPart { } , attrs )
44+ assert changeset . valid?
45+ assert changeset . changes . part_type == "closed"
46+ end
47+
48+ test "validates part_type inclusion: wat" do
49+ insert ( :user , id: 1 )
50+ insert ( :conversation , id: 1 )
51+ attrs = @ valid_attrs |> Map . merge ( % { author_id: 1 , conversation_id: 1 , part_type: "wat" } )
52+ changeset = ConversationParts . create_changeset ( % ConversationPart { } , attrs )
53+ refute changeset . valid?
54+ assert_error_message ( changeset , :part_type , "is invalid" )
1955 end
2056
2157 test "requires author_id" do
0 commit comments