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
This commit is contained in:
Rob Zolkos
2026-03-10 11:31:00 -04:00
committed by GitHub
parent 1cf0406d81
commit 8c2318e267
11 changed files with 143 additions and 21 deletions
@@ -16,8 +16,9 @@ class Account::EntropiesControllerTest < ActionDispatch::IntegrationTest
test "update as JSON" do
put account_entropy_path, params: { entropy: { auto_postpone_period_in_days: 7 } }, as: :json
assert_response :no_content
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
@@ -35,4 +36,20 @@ class Account::EntropiesControllerTest < ActionDispatch::IntegrationTest
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
@@ -16,13 +16,6 @@ class Account::SettingsControllerTest < ActionDispatch::IntegrationTest
assert_redirected_to account_settings_path
end
test "show as JSON" do
get account_settings_path, as: :json
assert_response :success
assert_equal Current.account.name, @response.parsed_body["name"]
end
test "update as JSON" do
put account_settings_path, params: { account: { name: "New Account Name" } }, as: :json
@@ -36,4 +29,13 @@ class Account::SettingsControllerTest < ActionDispatch::IntegrationTest
put account_settings_path, params: { account: { name: "New Account Name" } }
assert_response :forbidden
end
test "show as JSON" do
get account_settings_path, as: :json
assert_response :success
assert_equal Current.account.name, @response.parsed_body["name"]
assert_equal Current.account.cards_count, @response.parsed_body["cards_count"]
assert_equal Current.account.entropy.auto_postpone_period_in_days, @response.parsed_body["auto_postpone_period_in_days"]
end
end
@@ -41,14 +41,14 @@ class FlatJsonParamsTest < ActionDispatch::IntegrationTest
put board_entropy_path(board), params: { auto_postpone_period_in_days: 90 }, as: :json
assert_response :no_content
assert_response :success
assert_equal 90.days, board.entropy.reload.auto_postpone_period
end
test "update account entropy with flat JSON" do
put account_entropy_path, params: { auto_postpone_period_in_days: 7 }, as: :json
assert_response :no_content
assert_response :success
assert_equal 7.days, Current.account.entropy.reload.auto_postpone_period
end
@@ -17,10 +17,13 @@ class Boards::EntropiesControllerTest < ActionDispatch::IntegrationTest
end
test "update as JSON" do
put board_entropy_path(@board), params: { board: { auto_postpone_period_in_days: 90 } }, as: :json
assert_no_difference -> { Current.account.entropy.reload.auto_postpone_period } do
put board_entropy_path(@board), params: { board: { auto_postpone_period_in_days: 90 } }, as: :json
assert_response :no_content
assert_equal 90.days, @board.entropy.reload.auto_postpone_period
assert_response :success
assert_equal 90.days, @board.entropy.reload.auto_postpone_period
assert_equal 90, @response.parsed_body["auto_postpone_period_in_days"]
end
end
test "update requires board admin permission" do
@@ -42,4 +45,24 @@ class Boards::EntropiesControllerTest < ActionDispatch::IntegrationTest
assert_response :unprocessable_entity
assert_equal original_period, @board.entropy.reload.auto_postpone_period
end
test "update as JSON rejects invalid auto_postpone_period" do
original_period = @board.entropy.auto_postpone_period
put board_entropy_path(@board), params: { board: { auto_postpone_period_in_days: 1 } }, as: :json
assert_response :unprocessable_entity
assert_equal original_period, @board.entropy.reload.auto_postpone_period
end
test "update as JSON requires board admin permission" do
logout_and_sign_in_as :jz
original_period = @board.entropy.auto_postpone_period
put board_entropy_path(@board), params: { board: { auto_postpone_period_in_days: 7 } }, as: :json
assert_response :forbidden
assert_equal original_period, @board.entropy.reload.auto_postpone_period
end
end
@@ -258,6 +258,7 @@ class BoardsControllerTest < ActionDispatch::IntegrationTest
get board_path(boards(:writebook)), as: :json
assert_response :success
assert_equal boards(:writebook).name, @response.parsed_body["name"]
assert_equal boards(:writebook).auto_postpone_period_in_days, @response.parsed_body["auto_postpone_period_in_days"]
end
test "show as JSON includes public_url when published" do