@@ -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
@@ -14,6 +13,52 @@ defmodule CodeCorpsWeb.ConversationViewTest do
1413 data: conversation |> Repo . preload ( :conversation_parts )
1514 )
1615
16+ expected_json = % {
17+ "data" => % {
18+ "id" => conversation . id |> Integer . to_string ,
19+ "type" => "conversation" ,
20+ "attributes" => % {
21+ "read-at" => conversation . read_at ,
22+ "status" => conversation . status ,
23+ "inserted-at" => conversation . inserted_at ,
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+
1762 expected_json = % {
1863 "data" => % {
1964 "id" => conversation . id |> Integer . to_string ,
@@ -49,7 +94,25 @@ defmodule CodeCorpsWeb.ConversationViewTest do
4994 } ,
5095 "jsonapi" => % {
5196 "version" => "1.0"
52- }
97+ } ,
98+ "included" => [ % {
99+ "attributes" => % {
100+ "body" => conversation_part . body ,
101+ "inserted-at" => conversation_part . inserted_at ,
102+ "read-at" => conversation_part . read_at ,
103+ "updated-at" => conversation_part . updated_at
104+ } ,
105+ "relationships" => % {
106+ "author" => % {
107+ "data" => % {
108+ "id" => conversation_part . author . id |> Integer . to_string ,
109+ "type" => "user"
110+ }
111+ }
112+ } ,
113+ "id" => conversation_part . id |> Integer . to_string ,
114+ "type" => "conversation-part"
115+ } ]
53116 }
54117
55118 assert rendered_json == expected_json
0 commit comments