Skip to content

Commit

Permalink
Add next level idx
Browse files Browse the repository at this point in the history
  • Loading branch information
iHiD committed Jan 16, 2025
1 parent 9738248 commit 7002869
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
2 changes: 2 additions & 0 deletions app/controllers/api/bootcamp/solutions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@ def complete

if num_level_exercises == num_level_solutions
completed_level_idx = level_idx
next_level_idx = Bootcamp::Settings.level_idx > completed_level_idx ? completed_level_idx + 1 : nil
else
next_exercise = Bootcamp::SelectNextExercise.(current_user)
end

render json: {
completed_level_idx:,
next_level_idx:,
next_exercise: SerializeBootcampExercise.(next_exercise)
}, status: :ok
end
Expand Down
14 changes: 14 additions & 0 deletions test/controllers/api/bootcamp/solutions_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class API::Bootcamp::SolutionsControllerTest < API::BaseTestCase
assert_response :ok
assert_json_response({
completed_level_idx: 1,
next_level_idx: nil,
next_exercise: nil
})
end
Expand All @@ -31,13 +32,16 @@ class API::Bootcamp::SolutionsControllerTest < API::BaseTestCase
assert_response :ok
assert_json_response({
completed_level_idx: nil,
next_level_idx: nil,
next_exercise: SerializeBootcampExercise.(next_exercise)
})
end
end

# rubocop:disable Naming/VariableNumber
test "complete: handles completed_level_idx properly" do
Bootcamp::Settings.instance.update(level_idx: 2)

freeze_time do
user = create :user
2.times { create :bootcamp_level }
Expand All @@ -52,13 +56,23 @@ class API::Bootcamp::SolutionsControllerTest < API::BaseTestCase
assert_response :ok
assert_json_response({
completed_level_idx: nil,
next_level_idx: nil,
next_exercise: SerializeBootcampExercise.(l1e2)
})

patch complete_api_bootcamp_solution_url(solutions.second), headers: @headers
assert_response :ok
assert_json_response({
completed_level_idx: 1,
next_level_idx: 2,
next_exercise: nil
})

patch complete_api_bootcamp_solution_url(solutions.third), headers: @headers
assert_response :ok
assert_json_response({
completed_level_idx: 2,
next_level_idx: nil,
next_exercise: nil
})
end
Expand Down

0 comments on commit 7002869

Please sign in to comment.