Skip to content

Commit

Permalink
fix: ninja listings
Browse files Browse the repository at this point in the history
  • Loading branch information
danielsp45 committed Oct 9, 2023
1 parent 89ca96a commit 19f3e88
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
6 changes: 3 additions & 3 deletions lib/bokken_web/controllers/skill/skill_json.ex
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
defmodule BokkenWeb.SkillJSON do
def index(%{skills: skills}) do
%{data: for(skill <- skills, do: data(%{skill: skill}))}
%{data: for(skill <- skills, do: data(skill))}
end

def show(%{skill: skill}) do
%{data: data(%{skill: skill})}
%{data: data(skill)}
end

def error(%{reason: reason}) do
%{error: reason}
end

def data(%{skill: skill}) do
def data(skill) do
%{
id: skill.id,
name: skill.name,
Expand Down
5 changes: 5 additions & 0 deletions test/bokken_web/controllers/ninja_json_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,9 @@ defmodule Bokken.NinjaJSONTest do
data: Enum.map(ninjas, &NinjaJSON.data(&1))
}
end

test "ninja" do


Check warning on line 44 in test/bokken_web/controllers/ninja_json_test.exs

View workflow job for this annotation

GitHub Actions / OTP 25.x / Elixir 1.14.x

There should be no trailing white-space at the end of a line.
end
end
12 changes: 6 additions & 6 deletions test/bokken_web/controllers/skill_json_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ defmodule Bokken.SkillJSONTest do
alias BokkenWeb.SkillJSON

test "data" do
skill = build(:skill)
rendered_skill = SkillJSON.data(%{skill: skill})
skill = insert(:skill)
rendered_skill = SkillJSON.data(skill)

assert rendered_skill == %{
id: skill.id,
Expand All @@ -17,19 +17,19 @@ defmodule Bokken.SkillJSONTest do
end

test "show" do
skill = build(:skill)
skill = insert(:skill)
rendered_skill = SkillJSON.show(%{skill: skill})

assert rendered_skill == %{
data: SkillJSON.data(%{skill: skill})
data: SkillJSON.data(skill)
}
end

test "index" do
skills = build_list(5, :skill)
skills = insert_list(5, :skill)
rendered_skills = SkillJSON.index(%{skills: skills})

expected_data = Enum.map(skills, &SkillJSON.data(%{skill: &1}))
expected_data = for(skill <- skills, do: SkillJSON.data(skill))

assert rendered_skills == %{
data: expected_data
Expand Down

0 comments on commit 19f3e88

Please sign in to comment.