Files
fizzy/test/controllers/accounts/entropies_controller_test.rb
Rob Zolkos 8c2318e267 Add JSON response format to entropy endpoints (#2673)
* Add JSON response format to entropy endpoints

Add account settings JSON endpoint returning account info including auto_postpone_period. Add auto_postpone_period to board JSON responses. Add JSON update support to both account and board entropy controllers.

* Add auto_postpone_period to all board response examples in API docs

* Use auto_postpone_period_in_days in JSON responses and API docs

* Use valid period values in permission tests
2026-03-10 11:31:00 -04:00

56 lines
1.8 KiB
Ruby

require "test_helper"
class Account::EntropiesControllerTest < ActionDispatch::IntegrationTest
setup do
sign_in_as :kevin
end
test "update" do
put account_entropy_path, params: { entropy: { auto_postpone_period_in_days: 7 } }
assert_equal 7.days, entropies("37s_account").auto_postpone_period
assert_redirected_to account_settings_path
end
test "update as JSON" do
put account_entropy_path, params: { entropy: { auto_postpone_period_in_days: 7 } }, as: :json
assert_response :success
assert_equal 7.days, entropies("37s_account").reload.auto_postpone_period
assert_equal 7, @response.parsed_body["auto_postpone_period_in_days"]
end
test "update requires admin" do
logout_and_sign_in_as :david
put account_entropy_path, params: { entropy: { auto_postpone_period_in_days: 7 } }
assert_response :forbidden
end
test "update rejects invalid auto_postpone_period" do
original_period = entropies("37s_account").auto_postpone_period
put account_entropy_path, params: { entropy: { auto_postpone_period_in_days: 1 } }
assert_response :unprocessable_entity
assert_equal original_period, entropies("37s_account").reload.auto_postpone_period
end
test "update as JSON rejects invalid auto_postpone_period" do
original_period = entropies("37s_account").auto_postpone_period
put account_entropy_path, params: { entropy: { auto_postpone_period_in_days: 1 } }, as: :json
assert_response :unprocessable_entity
assert_equal original_period, entropies("37s_account").reload.auto_postpone_period
end
test "update as JSON requires admin" do
logout_and_sign_in_as :david
put account_entropy_path, params: { entropy: { auto_postpone_period_in_days: 7 } }, as: :json
assert_response :forbidden
end
end