Move AI enable endpoint to user scope

Replace /api/v1/auth/enable_ai with /api/v1/user/enable_ai by moving the action into Api::V1::UsersController, updating Flutter client calls, tests, and OpenAPI docs.
This commit is contained in:
Juan José Mata
2026-02-16 20:18:56 +01:00
parent d9acf19038
commit 9d61216518
13 changed files with 759 additions and 103 deletions

View File

@@ -0,0 +1,40 @@
require "test_helper"
class Api::V1::UsersControllerTest < ActionDispatch::IntegrationTest
setup do
@user = users(:family_admin)
@user.update!(ai_enabled: false)
@shared_app = Doorkeeper::Application.find_or_create_by!(name: "Sure Mobile") do |app|
app.redirect_uri = "sureapp://oauth/callback"
app.scopes = "read_write"
app.confidential = false
end
@token = Doorkeeper::AccessToken.create!(
application: @shared_app,
resource_owner_id: @user.id,
scopes: "read_write"
)
end
test "should enable ai for authenticated user" do
patch "/api/v1/user/enable_ai", headers: {
"Authorization" => "Bearer #{@token.token}",
"Content-Type" => "application/json"
}
assert_response :success
response_data = JSON.parse(response.body)
assert_equal true, response_data.dig("user", "ai_enabled")
assert_equal @user.ui_layout, response_data.dig("user", "ui_layout")
assert @user.reload.ai_enabled?
end
test "should require authentication when enabling ai" do
patch "/api/v1/user/enable_ai", headers: { "Content-Type" => "application/json" }
assert_response :unauthorized
end
end