0435db30ba
* Add JSON response format to webhooks Support JSON responses for all webhook endpoints: index, show, create, update, destroy, and activation. Adds jbuilder views, updates controllers to use respond_to, and documents the API in docs/API.md. * Address PR review feedback - Use distinct board ID in API docs webhook example - Use render "webhooks/show" in activations controller for consistency * Address PR review feedback from flavorjones - Include webhook.board in cache key to avoid stale board data - Use _url instead of _path for location header consistency * Fix webhook create test to match Location header format Use board_webhook_url instead of board_webhook_path since the controller returns a full URL in the Location header. * Fix board ID in Location header example in API docs Use distinct board ID in the Location URL to match the JSON body example.
68 lines
1.8 KiB
Ruby
68 lines
1.8 KiB
Ruby
require "test_helper"
|
|
|
|
class Webhooks::ActivationsControllerTest < ActionDispatch::IntegrationTest
|
|
setup do
|
|
sign_in_as :kevin
|
|
end
|
|
|
|
test "create" do
|
|
webhook = webhooks(:inactive)
|
|
|
|
assert_not webhook.active?
|
|
|
|
assert_changes -> { webhook.reload.active? }, from: false, to: true do
|
|
post board_webhook_activation_path(webhook.board, webhook)
|
|
end
|
|
|
|
assert_redirected_to board_webhook_path(webhook.board, webhook)
|
|
end
|
|
|
|
test "cannot activate webhook on board without access" do
|
|
logout_and_sign_in_as :jason
|
|
webhook = webhooks(:inactive) # on private board, jason has no access
|
|
|
|
post board_webhook_activation_path(webhook.board, webhook)
|
|
assert_response :not_found
|
|
end
|
|
|
|
test "non-admin cannot activate webhook" do
|
|
logout_and_sign_in_as :jz # member with writebook access, but not admin
|
|
webhook = webhooks(:active) # on writebook board
|
|
|
|
post board_webhook_activation_path(webhook.board, webhook)
|
|
assert_response :forbidden
|
|
end
|
|
|
|
test "create as JSON" do
|
|
webhook = webhooks(:inactive)
|
|
|
|
assert_not webhook.active?
|
|
|
|
assert_changes -> { webhook.reload.active? }, from: false, to: true do
|
|
post board_webhook_activation_path(webhook.board, webhook), as: :json
|
|
end
|
|
|
|
assert_response :created
|
|
assert_equal webhook.id, @response.parsed_body["id"]
|
|
assert_equal true, @response.parsed_body["active"]
|
|
end
|
|
|
|
test "cannot activate webhook on board without access as JSON" do
|
|
logout_and_sign_in_as :jason
|
|
webhook = webhooks(:inactive)
|
|
|
|
post board_webhook_activation_path(webhook.board, webhook), as: :json
|
|
|
|
assert_response :not_found
|
|
end
|
|
|
|
test "non-admin cannot activate webhook as JSON" do
|
|
logout_and_sign_in_as :jz
|
|
webhook = webhooks(:active)
|
|
|
|
post board_webhook_activation_path(webhook.board, webhook), as: :json
|
|
|
|
assert_response :forbidden
|
|
end
|
|
end
|