diff --git a/lib/bokken/uploaders/emblem.ex b/lib/bokken/uploaders/emblem.ex index ae1c3b3a..6493317e 100644 --- a/lib/bokken/uploaders/emblem.ex +++ b/lib/bokken/uploaders/emblem.ex @@ -31,10 +31,6 @@ defmodule Bokken.Uploaders.Emblem do # Provide a default URL if there hasn't been a file uploaded def default_url(_version, _scope) do - base_url() <> "/images/default_badge.png" - end - - defp base_url do - Application.fetch_env!(:waffle, :asset_host) + "/images/default_badge.png" end end diff --git a/lib/bokken_web/controllers/badge_controller.ex b/lib/bokken_web/controllers/badge_controller.ex index f426e344..23fb94d2 100644 --- a/lib/bokken_web/controllers/badge_controller.ex +++ b/lib/bokken_web/controllers/badge_controller.ex @@ -7,7 +7,7 @@ defmodule BokkenWeb.BadgeController do action_fallback BokkenWeb.FallbackController - def index(conn, params) when is_map_key(params, :ninja_id) do + def index(conn, params) when is_map_key(params, "ninja_id") do badges = Gamification.list_badges(params) render(conn, "index.json", badges: badges) end diff --git a/test/bokken_web/controllers/badge_controller_test.exs b/test/bokken_web/controllers/badge_controller_test.exs index 607cae74..881bf6bc 100644 --- a/test/bokken_web/controllers/badge_controller_test.exs +++ b/test/bokken_web/controllers/badge_controller_test.exs @@ -2,6 +2,7 @@ defmodule BokkenWeb.BadgeControllerTest do use BokkenWeb.ConnCase import Bokken.GamificationFixtures + import Bokken.Factory alias Bokken.Gamification.Badge @@ -41,6 +42,23 @@ defmodule BokkenWeb.BadgeControllerTest do conn = get(conn, Routes.badge_path(conn, :index)) assert json_response(conn, 200)["data"] == [] end + + test "lists all badges of ninja", %{conn: conn} do + ninja = insert(:ninja) + %{id: badge_id, description: badge_description, name: badge_name} = badge = insert(:badge) + insert(:badge_ninja, badge: badge, ninja: ninja) + + conn = get(conn, Routes.ninja_badge_path(conn, :index, ninja.id)) + + assert [ + %{ + "id" => ^badge_id, + "description" => ^badge_description, + "image" => "/images/default_badge.png", + "name" => ^badge_name + } + ] = json_response(conn, 200)["data"] + end end describe "create badge" do diff --git a/test/support/factories/gamification_factory.ex b/test/support/factories/gamification_factory.ex new file mode 100644 index 00000000..bcc7ed24 --- /dev/null +++ b/test/support/factories/gamification_factory.ex @@ -0,0 +1,26 @@ +defmodule Bokken.Factories.GamificationFactory do + @moduledoc """ + A factory to generate gamification related structs + """ + defmacro __using__(_opts) do + quote do + alias Bokken.Accounts.Ninja + alias Bokken.Gamification.{Badge, BadgeNinja} + + def badge_factory do + %Badge{ + name: Faker.Commerce.product_name(), + description: Faker.Lorem.sentence(), + image: nil + } + end + + def badge_ninja_factory do + %BadgeNinja{ + badge: build(:badge), + ninja: build(:ninja) + } + end + end + end +end diff --git a/test/support/factory.ex b/test/support/factory.ex index 8d425c8a..a911ee0f 100644 --- a/test/support/factory.ex +++ b/test/support/factory.ex @@ -6,6 +6,7 @@ defmodule Bokken.Factory do AccountFactory, TokenFactory, CurriculumFactory, - EventFactory + EventFactory, + GamificationFactory } end