Skip to content

Commit

Permalink
fix: ninja listings (#201)
Browse files Browse the repository at this point in the history
  • Loading branch information
danielsp45 authored Oct 9, 2023
1 parent a3ee731 commit 972b1e4
Show file tree
Hide file tree
Showing 2 changed files with 9 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
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 972b1e4

Please sign in to comment.