@@ -3,9 +3,8 @@ defmodule CodeCorpsWeb.ConversationViewTest do
3
3
4
4
alias CodeCorps.Repo
5
5
6
- test "renders all attributes and relationships properly" do
6
+ test "renders index attributes and relationships properly" do
7
7
conversation = insert ( :conversation )
8
- conversation_part = insert ( :conversation_part , conversation: conversation )
9
8
10
9
rendered_json =
11
10
CodeCorpsWeb.ConversationView
@@ -19,9 +18,55 @@ defmodule CodeCorpsWeb.ConversationViewTest do
19
18
"id" => conversation . id |> Integer . to_string ,
20
19
"type" => "conversation" ,
21
20
"attributes" => % {
21
+ "inserted-at" => conversation . inserted_at ,
22
22
"read-at" => conversation . read_at ,
23
23
"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" => % {
24
67
"inserted-at" => conversation . inserted_at ,
68
+ "read-at" => conversation . read_at ,
69
+ "status" => conversation . status ,
25
70
"updated-at" => conversation . updated_at
26
71
} ,
27
72
"relationships" => % {
@@ -49,7 +94,27 @@ defmodule CodeCorpsWeb.ConversationViewTest do
49
94
} ,
50
95
"jsonapi" => % {
51
96
"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
+ ]
53
118
}
54
119
55
120
assert rendered_json == expected_json
0 commit comments