@@ -3,9 +3,8 @@ defmodule CodeCorpsWeb.ConversationViewTest do
33
44 alias CodeCorps.Repo
55
6- test "renders all attributes and relationships properly" do
6+ test "renders index attributes and relationships properly" do
77 conversation = insert ( :conversation )
8- conversation_part = insert ( :conversation_part , conversation: conversation )
98
109 rendered_json =
1110 CodeCorpsWeb.ConversationView
@@ -19,9 +18,55 @@ defmodule CodeCorpsWeb.ConversationViewTest do
1918 "id" => conversation . id |> Integer . to_string ,
2019 "type" => "conversation" ,
2120 "attributes" => % {
21+ "inserted-at" => conversation . inserted_at ,
2222 "read-at" => conversation . read_at ,
2323 "status" => conversation . status ,
24+ "updated-at" => conversation . updated_at
25+ } ,
26+ "relationships" => % {
27+ "conversation-parts" => % { } ,
28+ "message" => % {
29+ "data" => % {
30+ "id" => conversation . message_id |> Integer . to_string ,
31+ "type" => "message"
32+ }
33+ } ,
34+ "user" => % {
35+ "data" => % {
36+ "id" => conversation . user_id |> Integer . to_string ,
37+ "type" => "user"
38+ }
39+ }
40+ }
41+ } ,
42+ "jsonapi" => % {
43+ "version" => "1.0"
44+ }
45+ }
46+
47+ assert rendered_json == expected_json
48+ end
49+
50+ test "renders show attributes and relationships properly" do
51+ conversation = insert ( :conversation )
52+ conversation_part = insert ( :conversation_part , conversation: conversation )
53+
54+ rendered_json =
55+ CodeCorpsWeb.ConversationView
56+ |> render (
57+ "show.json-api" ,
58+ data: conversation |> Repo . preload ( :conversation_parts ) ,
59+ opts: [ include: "conversation_parts" ]
60+ )
61+
62+ expected_json = % {
63+ "data" => % {
64+ "id" => conversation . id |> Integer . to_string ,
65+ "type" => "conversation" ,
66+ "attributes" => % {
2467 "inserted-at" => conversation . inserted_at ,
68+ "read-at" => conversation . read_at ,
69+ "status" => conversation . status ,
2570 "updated-at" => conversation . updated_at
2671 } ,
2772 "relationships" => % {
@@ -49,7 +94,27 @@ defmodule CodeCorpsWeb.ConversationViewTest do
4994 } ,
5095 "jsonapi" => % {
5196 "version" => "1.0"
52- }
97+ } ,
98+ "included" => [
99+ % {
100+ "attributes" => % {
101+ "body" => conversation_part . body ,
102+ "inserted-at" => conversation_part . inserted_at ,
103+ "read-at" => conversation_part . read_at ,
104+ "updated-at" => conversation_part . updated_at
105+ } ,
106+ "relationships" => % {
107+ "author" => % {
108+ "data" => % {
109+ "id" => conversation_part . author . id |> Integer . to_string ,
110+ "type" => "user"
111+ }
112+ }
113+ } ,
114+ "id" => conversation_part . id |> Integer . to_string ,
115+ "type" => "conversation-part"
116+ }
117+ ]
53118 }
54119
55120 assert rendered_json == expected_json
0 commit comments