mirror of
https://github.com/we-promise/sure.git
synced 2026-04-22 21:44:11 +00:00
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:
40
test/controllers/api/v1/users_controller_test.rb
Normal file
40
test/controllers/api/v1/users_controller_test.rb
Normal 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
|
||||
Reference in New Issue
Block a user