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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user