Skip to content

Commit 73fa73a

Browse files
pt-arvindjoshsmith
authored andcommitted
Added a test for comment view
1 parent ac51d90 commit 73fa73a

1 file changed

Lines changed: 52 additions & 0 deletions

File tree

test/views/comment_view_test.exs

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
defmodule CodeCorps.CommentViewTest do
2+
use CodeCorps.ConnCase, async: true
3+
4+
alias CodeCorps.Repo
5+
6+
# Bring render/3 and render_to_string/3 for testing custom views
7+
import Phoenix.View
8+
9+
test "renders all attributes and relationships properly" do
10+
task = insert(:task)
11+
user = insert(:user)
12+
comment = insert(:comment, user: user, task: task)
13+
14+
comment = CodeCorps.Comment
15+
|> Repo.get(comment.id)
16+
|> Repo.preload([:task, :user])
17+
18+
rendered_json = render(CodeCorps.CommentView, "show.json-api", data: comment)
19+
20+
expected_json = %{
21+
data: %{
22+
id: comment.id |> Integer.to_string,
23+
type: "comment",
24+
attributes: %{
25+
"body" => comment.body,
26+
"inserted-at" => comment.inserted_at,
27+
"markdown" => comment.markdown,
28+
"updated-at" => comment.updated_at
29+
},
30+
relationships: %{
31+
"task" => %{
32+
data: %{
33+
id: comment.task_id |> Integer.to_string,
34+
type: "task"
35+
}
36+
},
37+
"user" => %{
38+
data: %{
39+
id: comment.user_id |> Integer.to_string,
40+
type: "user"
41+
}
42+
}
43+
}
44+
},
45+
jsonapi: %{
46+
version: "1.0"
47+
}
48+
}
49+
50+
assert expected_json == rendered_json
51+
end
52+
end

0 commit comments

Comments
 (0)