Skip to content

Commit

Permalink
Set whether stories is enabled in course config (#1053)
Browse files Browse the repository at this point in the history
* Create migration file

* Update API

* Update some tests

* Fix missed tests
  • Loading branch information
RichDom2185 authored Feb 3, 2024
1 parent 96b23a4 commit 4179446
Show file tree
Hide file tree
Showing 13 changed files with 58 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/cadet/courses/course.ex
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ defmodule Cadet.Courses.Course do
enable_game: boolean(),
enable_achievements: boolean(),
enable_sourcecast: boolean(),
enable_stories: boolean(),
source_chapter: integer(),
source_variant: String.t(),
module_help_text: String.t(),
Expand All @@ -26,6 +27,7 @@ defmodule Cadet.Courses.Course do
field(:enable_game, :boolean, default: true)
field(:enable_achievements, :boolean, default: true)
field(:enable_sourcecast, :boolean, default: true)
field(:enable_stories, :boolean, default: false)
field(:source_chapter, :integer)
field(:source_variant, :string)
field(:module_help_text, :string)
Expand All @@ -39,7 +41,7 @@ defmodule Cadet.Courses.Course do
end

@required_fields ~w(course_name viewable enable_game
enable_achievements enable_sourcecast source_chapter source_variant)a
enable_achievements enable_sourcecast enable_stories source_chapter source_variant)a
@optional_fields ~w(course_short_name module_help_text)a

def changeset(course, params) do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ defmodule CadetWeb.AdminCoursesController do
enable_game(:body, :boolean, "Enable game")
enable_achievements(:body, :boolean, "Enable achievements")
enable_sourcecast(:body, :boolean, "Enable sourcecast")
enable_stories(:body, :boolean, "Enable stories")
sublanguage(:body, Schema.ref(:AdminSublanguage), "sublanguage object")
module_help_text(:body, :string, "Module help text")
end
Expand Down
3 changes: 3 additions & 0 deletions lib/cadet_web/controllers/courses_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ defmodule CadetWeb.CoursesController do
enable_game(:body, :boolean, "Enable game", required: true)
enable_achievements(:body, :boolean, "Enable achievements", required: true)
enable_sourcecast(:body, :boolean, "Enable sourcecast", required: true)
enable_stories(:body, :boolean, "Enable stories", required: true)
source_chapter(:body, :number, "Default source chapter", required: true)

source_variant(:body, Schema.ref(:SourceVariant), "Default source variant name",
Expand Down Expand Up @@ -95,6 +96,7 @@ defmodule CadetWeb.CoursesController do
enable_game(:boolean, "Enable game", required: true)
enable_achievements(:boolean, "Enable achievements", required: true)
enable_sourcecast(:boolean, "Enable sourcecast", required: true)
enable_stories(:boolean, "Enable stories", required: true)
source_chapter(:integer, "Source Chapter number from 1 to 4", required: true)
source_variant(Schema.ref(:SourceVariant), "Source Variant name", required: true)
module_help_text(:string, "Module help text", required: true)
Expand All @@ -108,6 +110,7 @@ defmodule CadetWeb.CoursesController do
enable_game: true,
enable_achievements: true,
enable_sourcecast: true,
enable_stories: false,
source_chapter: 1,
source_variant: "default",
module_help_text: "Help text",
Expand Down
2 changes: 2 additions & 0 deletions lib/cadet_web/controllers/user_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,7 @@ defmodule CadetWeb.UserController do
enable_game(:boolean, "Enable game", required: true)
enable_achievements(:boolean, "Enable achievements", required: true)
enable_sourcecast(:boolean, "Enable sourcecast", required: true)
enable_stories(:boolean, "Enable stories", required: true)
source_chapter(:integer, "Source Chapter number from 1 to 4", required: true)
source_variant(Schema.ref(:SourceVariant), "Source Variant name", required: true)
module_help_text(:string, "Module help text", required: true)
Expand All @@ -330,6 +331,7 @@ defmodule CadetWeb.UserController do
enable_game: true,
enable_achievements: true,
enable_sourcecast: true,
enable_stories: false,
source_chapter: 1,
source_variant: "default",
module_help_text: "Help text",
Expand Down
1 change: 1 addition & 0 deletions lib/cadet_web/views/courses_view.ex
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ defmodule CadetWeb.CoursesView do
enableGame: :enable_game,
enableAchievements: :enable_achievements,
enableSourcecast: :enable_sourcecast,
enableStories: :enable_stories,
sourceChapter: :source_chapter,
sourceVariant: :source_variant,
moduleHelpText: :module_help_text,
Expand Down
1 change: 1 addition & 0 deletions lib/cadet_web/views/user_view.ex
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ defmodule CadetWeb.UserView do
enableGame: :enable_game,
enableAchievements: :enable_achievements,
enableSourcecast: :enable_sourcecast,
enableStories: :enable_stories,
sourceChapter: :source_chapter,
sourceVariant: :source_variant,
moduleHelpText: :module_help_text,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
defmodule Cadet.Repo.Migrations.AddStoriesToggleToCourseConfig do
use Ecto.Migration

def up do
alter table(:courses) do
add(:enable_stories, :boolean, null: false, default: false)
end
end

def down do
alter table(:courses) do
remove(:enable_stories)
end
end
end
13 changes: 13 additions & 0 deletions test/cadet/courses/course_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,19 @@ defmodule Cadet.Courses.CourseTest do
:valid
)

assert_changeset(
%{
enable_game: true,
enable_achievements: true,
enable_sourcecast: true,
enable_stories: false,
course_name: "Data Structures and Algorithms",
source_chapter: 1,
source_variant: "default"
},
:valid
)

assert_changeset(
%{
source_chapter: 1,
Expand Down
7 changes: 7 additions & 0 deletions test/cadet/courses/courses_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ defmodule Cadet.CoursesTest do
enable_game: true,
enable_achievements: true,
enable_sourcecast: true,
enable_stories: false,
source_chapter: 1,
source_variant: "default",
module_help_text: "Help Text"
Expand Down Expand Up @@ -55,6 +56,7 @@ defmodule Cadet.CoursesTest do
assert course.enable_game == true
assert course.enable_achievements == true
assert course.enable_sourcecast == true
assert course.enable_stories == false
assert course.source_chapter == 1
assert course.source_variant == "default"
assert course.module_help_text == "Help Text"
Expand All @@ -81,6 +83,7 @@ defmodule Cadet.CoursesTest do
enable_game: false,
enable_achievements: false,
enable_sourcecast: false,
enable_stories: true,
module_help_text: ""
})

Expand All @@ -90,6 +93,7 @@ defmodule Cadet.CoursesTest do
assert updated_course.enable_game == false
assert updated_course.enable_achievements == false
assert updated_course.enable_sourcecast == false
assert updated_course.enable_stories == true
assert updated_course.source_chapter == 1
assert updated_course.source_variant == "default"
assert updated_course.module_help_text == nil
Expand All @@ -107,6 +111,7 @@ defmodule Cadet.CoursesTest do
enable_game: false,
enable_achievements: false,
enable_sourcecast: false,
enable_stories: true,
source_chapter: new_chapter,
source_variant: "default",
module_help_text: "help"
Expand All @@ -118,6 +123,7 @@ defmodule Cadet.CoursesTest do
assert updated_course.enable_game == false
assert updated_course.enable_achievements == false
assert updated_course.enable_sourcecast == false
assert updated_course.enable_stories == true
assert updated_course.source_chapter == new_chapter
assert updated_course.source_variant == "default"
assert updated_course.module_help_text == "help"
Expand All @@ -135,6 +141,7 @@ defmodule Cadet.CoursesTest do
enable_game: false,
enable_achievements: false,
enable_sourcecast: false,
enable_stories: false,
module_help_text: "help"
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ defmodule CadetWeb.AdminCoursesControllerTest do
"enableGame" => false,
"enableAchievements" => false,
"enableSourcecast" => true,
"enableStories" => false,
"sourceChapter" => 1,
"sourceVariant" => "default",
"moduleHelpText" => "help"
Expand All @@ -65,6 +66,7 @@ defmodule CadetWeb.AdminCoursesControllerTest do
"courseName" => "Data Structures and Algorithms",
"courseShortName" => "CS2040S",
"enableGame" => false,
"enableStories" => false,
"enableAchievements" => false,
"enableSourcecast" => true,
"moduleHelpText" => "help"
Expand Down Expand Up @@ -132,6 +134,7 @@ defmodule CadetWeb.AdminCoursesControllerTest do
"enableGame" => false,
"enableAchievements" => false,
"enableSourcecast" => true,
"enableStories" => false,
"moduleHelpText" => "help",
"sourceVariant" => "default"
})
Expand Down
6 changes: 6 additions & 0 deletions test/cadet_web/controllers/courses_controller_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ defmodule CadetWeb.CoursesControllerTest do
"enable_game" => "true",
"enable_achievements" => "true",
"enable_sourcecast" => "true",
"enable_stories" => "true",
"source_chapter" => "1",
"source_variant" => "default",
"module_help_text" => "Help Text"
Expand All @@ -49,6 +50,7 @@ defmodule CadetWeb.CoursesControllerTest do
"viewable" => "true",
"enable_achievements" => "true",
"enable_sourcecast" => "true",
"enable_stories" => "true",
"source_variant" => "default",
"module_help_text" => "Help Text"
}
Expand All @@ -70,6 +72,7 @@ defmodule CadetWeb.CoursesControllerTest do
"enable_game" => "true",
"enable_achievements" => "true",
"enable_sourcecast" => "true",
"enable_stories" => "true",
"source_chapter" => "1",
"source_variant" => "default",
"module_help_text" => "Help Text"
Expand All @@ -92,6 +95,7 @@ defmodule CadetWeb.CoursesControllerTest do
"enable_game" => "true",
"enable_achievements" => "true",
"enable_sourcecast" => "true",
"enable_stories" => "true",
"source_chapter" => "1",
"source_variant" => "default",
"module_help_text" => "Help Text"
Expand All @@ -115,6 +119,7 @@ defmodule CadetWeb.CoursesControllerTest do
"enable_game" => "true",
"enable_achievements" => "true",
"enable_sourcecast" => "true",
"enable_stories" => "true",
"source_chapter" => "1",
"source_variant" => "default",
"module_help_text" => "Help Text"
Expand Down Expand Up @@ -155,6 +160,7 @@ defmodule CadetWeb.CoursesControllerTest do
"enableGame" => true,
"enableAchievements" => true,
"enableSourcecast" => true,
"enableStories" => false,
"sourceChapter" => 1,
"sourceVariant" => "default",
"moduleHelpText" => "Help Text",
Expand Down
2 changes: 2 additions & 0 deletions test/cadet_web/controllers/user_controller_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ defmodule CadetWeb.UserControllerTest do
"enableAchievements" => true,
"enableGame" => true,
"enableSourcecast" => true,
"enableStories" => false,
"courseShortName" => "CS1101S",
"moduleHelpText" => "Help Text",
"courseName" => "Programming Methodology",
Expand Down Expand Up @@ -306,6 +307,7 @@ defmodule CadetWeb.UserControllerTest do
"enableGame" => true,
"enableSourcecast" => true,
"courseShortName" => "CS1101S",
"enableStories" => false,
"moduleHelpText" => "Help Text",
"courseName" => "Programming Methodology",
"sourceChapter" => 1,
Expand Down
1 change: 1 addition & 0 deletions test/factories/courses/course_factory.ex
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ defmodule Cadet.Courses.CourseFactory do
enable_game: true,
enable_achievements: true,
enable_sourcecast: true,
enable_stories: false,
source_chapter: 1,
source_variant: "default",
module_help_text: "Help Text"
Expand Down

0 comments on commit 4179446

Please sign in to comment.