Skip to content

Remove achievement ability #796

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 1 addition & 7 deletions lib/cadet/incentives/achievement.ex
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,9 @@ defmodule Cadet.Incentives.Achievement do
alias Cadet.Courses.Course
alias Cadet.Incentives.{AchievementPrerequisite, AchievementToGoal}

@valid_abilities ~w(Core Community Effort Exploration Flex)

@primary_key {:uuid, :binary_id, autogenerate: false}
schema "achievements" do
field(:title, :string)
field(:ability, :string)
field(:card_tile_url, :string)
field(:xp, :integer)
field(:is_variable_xp, :boolean)
Expand All @@ -34,7 +31,7 @@ defmodule Cadet.Incentives.Achievement do
field(:goal_uuids, {:array, :binary_id}, virtual: true)
end

@required_fields ~w(uuid title ability is_task position xp is_variable_xp course_id)a
@required_fields ~w(uuid title is_task position xp is_variable_xp course_id)a
@optional_fields ~w(card_tile_url open_at close_at canvas_url description
completion_text prerequisite_uuids goal_uuids)a

Expand All @@ -47,7 +44,6 @@ defmodule Cadet.Incentives.Achievement do
achievement
|> cast(params, @required_fields ++ @optional_fields)
|> validate_required(@required_fields)
|> validate_inclusion(:ability, @valid_abilities)
|> foreign_key_constraint(:course_id)
|> cast_join_ids(
:prerequisite_uuids,
Expand All @@ -62,6 +58,4 @@ defmodule Cadet.Incentives.Achievement do
:uuid
)
end

def valid_abilities, do: @valid_abilities
end
6 changes: 0 additions & 6 deletions lib/cadet_web/controllers/incentives_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,6 @@ defmodule CadetWeb.IncentivesController do
"If true, XP awarded will depend on the goal progress"
)

ability(
:string,
"Achievement ability i.e. category",
required: true
)

cardBackground(
:string,
"URL of the achievement's background image"
Expand Down
1 change: 0 additions & 1 deletion lib/cadet_web/views/incentives_view.ex
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ defmodule CadetWeb.IncentivesView do
transform_map_for_view(achievement, %{
uuid: :uuid,
title: :title,
ability: :ability,
xp: :xp,
isVariableXp: :is_variable_xp,
release: &format_datetime(&1.open_at),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
defmodule Cadet.Repo.Migrations.RemoveAchievementAbility do
use Ecto.Migration

def change do
alter table(:achievements) do
remove(:ability, :text, null: false, default: "Core")
end
end
end
11 changes: 0 additions & 11 deletions priv/repo/seeds.exs
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,6 @@ if Cadet.Env.env() == :dev do
# achievement_0 =
# insert(:achievement, %{
# title: "Rune Master",
# ability: "Core",
# is_task: true,
# position: 1,
# card_tile_url:
Expand All @@ -264,7 +263,6 @@ if Cadet.Env.env() == :dev do
# achievement_1 =
# insert(:achievement, %{
# title: "Beyond the Second Dimension",
# ability: "Core",
# is_task: false,
# position: 0,
# card_tile_url:
Expand All @@ -280,7 +278,6 @@ if Cadet.Env.env() == :dev do
# achievement_2 =
# insert(:achievement, %{
# title: "Colorful Carpet",
# ability: "Core",
# is_task: false,
# position: 0,
# card_tile_url:
Expand All @@ -296,7 +293,6 @@ if Cadet.Env.env() == :dev do
# achievement_3 =
# insert(:achievement, %{
# title: "Unpublished",
# ability: "Core",
# is_task: false,
# position: 0,
# card_tile_url:
Expand All @@ -306,7 +302,6 @@ if Cadet.Env.env() == :dev do
# achievement_4 =
# insert(:achievement, %{
# title: "Curve Wizard",
# ability: "Core",
# is_task: true,
# position: 4,
# card_tile_url:
Expand All @@ -323,7 +318,6 @@ if Cadet.Env.env() == :dev do
# achievement_5 =
# insert(:achievement, %{
# title: "Curve Introduction",
# ability: "Core",
# is_task: false,
# position: 0,
# card_tile_url:
Expand All @@ -339,7 +333,6 @@ if Cadet.Env.env() == :dev do
# achievement_6 =
# insert(:achievement, %{
# title: "Curve Manipulation",
# ability: "Core",
# is_task: false,
# position: 0,
# card_tile_url:
Expand All @@ -355,7 +348,6 @@ if Cadet.Env.env() == :dev do
# achievement_7 =
# insert(:achievement, %{
# title: "The Source-rer",
# ability: "Effort",
# is_task: true,
# position: 3,
# card_tile_url:
Expand All @@ -371,7 +363,6 @@ if Cadet.Env.env() == :dev do
# achievement_8 =
# insert(:achievement, %{
# title: "Power of Friendship",
# ability: "Community",
# is_task: true,
# position: 2,
# card_tile_url:
Expand All @@ -386,7 +377,6 @@ if Cadet.Env.env() == :dev do
# achievement_9 =
# insert(:achievement, %{
# title: "Piazza Guru",
# ability: "Community",
# is_task: false,
# position: 0,
# card_tile_url:
Expand All @@ -399,7 +389,6 @@ if Cadet.Env.env() == :dev do
# achievement_10 =
# insert(:achievement, %{
# title: "Thats the Spirit",
# ability: "Exploration",
# is_task: true,
# position: 5,
# card_tile_url:
Expand Down
2 changes: 0 additions & 2 deletions test/cadet/incentives/achievement_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ defmodule Cadet.Incentives.AchievementTest do
uuid: "d1fdae3f-2775-4503-ab6b-e043149d4a15",
title: "Hello World",
course_id: course.id,
ability: "Core",
open_at: DateTime.from_naive!(~N[2016-05-24 13:26:08.003], "Etc/UTC"),
close_at: DateTime.from_naive!(~N[2016-05-27 13:26:08.003], "Etc/UTC"),
is_task: false,
Expand All @@ -29,7 +28,6 @@ defmodule Cadet.Incentives.AchievementTest do
%{
uuid: "d1fdae3f-2775-4503-ab6b-e043149d4a15",
title: "Hello World",
ability: "Core",
open_at: DateTime.from_naive!(~N[2016-05-27 13:26:08.003], "Etc/UTC"),
close_at: DateTime.from_naive!(~N[2016-05-24 13:26:08.003], "Etc/UTC")
},
Expand Down
27 changes: 12 additions & 15 deletions test/cadet/incentives/achievements_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,18 @@ defmodule Cadet.Incentives.AchievementsTest do
test "create achievements" do
course = insert(:course)

for ability <- Achievement.valid_abilities() do
{:ok, %{uuid: uuid}} =
Achievements.upsert(%{
uuid: Ecto.UUID.generate(),
course_id: course.id,
title: ability,
ability: ability,
is_task: false,
position: 0,
xp: 0,
is_variable_xp: false
})

assert %{title: ^ability, ability: ^ability} = Repo.get(Achievement, uuid)
end
{:ok, %{uuid: uuid}} =
Achievements.upsert(%{
uuid: Ecto.UUID.generate(),
course_id: course.id,
title: "test achievement",
is_task: false,
position: 0,
xp: 0,
is_variable_xp: false
})

assert %{title: "test achievement"} = Repo.get(Achievement, uuid)
end

test "create achievement with prerequisites as id" do
Expand Down
1 change: 0 additions & 1 deletion test/factories/achievements/achievement_factory.ex
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ defmodule Cadet.Incentives.AchievementFactory do
uuid: UUID.generate(),
course: insert(:course),
title: Faker.Food.dish(),
ability: Enum.random(Achievement.valid_abilities()),
is_task: false,
position: 0,
xp: 0,
Expand Down
2 changes: 0 additions & 2 deletions test/support/test_entity_helper.ex
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ defmodule Cadet.TestEntityHelper do
defmacro achievement_literal(id) do
Macro.escape(%{
title: "Achievement #{id}",
ability: "Core",
is_task: false,
xp: 0,
is_variable_xp: false,
Expand All @@ -20,7 +19,6 @@ defmodule Cadet.TestEntityHelper do

defmacro achievement_json_literal(id) do
Macro.escape(%{
"ability" => "Core",
"position" => id,
"title" => "Achievement #{id}",
"xp" => 0,
Expand Down