Skip to content

Commit

Permalink
Maintenance: Simplify stack routes
Browse files Browse the repository at this point in the history
  • Loading branch information
tschaefer committed Dec 5, 2024
1 parent 4e67cb2 commit ae33a53
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
13 changes: 8 additions & 5 deletions config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
Rails.application.routes.draw do
Healthcheck.routes(self)

resources :stacks, param: :uuid
post 'stacks/:uuid/webhook', to: 'stacks#webhook', as: :stack_webhook
get 'stacks/:uuid/stats', to: 'stacks#stats', as: :stack_stats
post 'stacks/:uuid/control', to: 'stacks#control', as: :stack_control
get 'stacks/:uuid/log', to: 'stacks#log', as: :stack_log
resources :stacks, param: :uuid do
member do
post 'webhook'
get 'stats'
post 'control'
get 'log'
end
end
end
14 changes: 7 additions & 7 deletions spec/requests/stacks_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@
describe 'GET /stats' do
it 'renders a successful response' do
stack = Stack.create! valid_attributes
get stack_stats_url(stack.uuid), headers: valid_headers, as: :json
get stats_stack_url(stack.uuid), headers: valid_headers, as: :json
expect(response).to be_successful
end
end
Expand All @@ -181,7 +181,7 @@
payload = { message: Faker::Lorem.unique.word }.to_json
sha256 = SecureRandom.hex(32)

post stack_webhook_url(stack.uuid), params: JSON.parse(payload),
post webhook_stack_url(stack.uuid), params: JSON.parse(payload),
headers: { 'X-Hub-Signature': "sha256=#{sha256}" }, as: :json
expect(response).not_to be_successful
expect(response).to have_http_status(:bad_request)
Expand All @@ -198,7 +198,7 @@
payload = { message: Faker::Lorem.unique.word }.to_json
sha256 = OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new('sha256'), stack.signature_secret, payload)

post stack_webhook_url(stack.uuid), params: JSON.parse(payload),
post webhook_stack_url(stack.uuid), params: JSON.parse(payload),
headers: { 'X-Hub-Signature': "sha256=#{sha256}" }, as: :json
expect(response).not_to be_successful
expect(response).to have_http_status(:conflict)
Expand All @@ -216,7 +216,7 @@
payload = { message: Faker::Lorem.unique.word }.to_json
sha256 = OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new('sha256'), stack.signature_secret, payload)

post stack_webhook_url(stack.uuid), params: JSON.parse(payload),
post webhook_stack_url(stack.uuid), params: JSON.parse(payload),
headers: { 'X-Hub-Signature': "sha256=#{sha256}" }, as: :json
expect(response).to be_successful
expect(response).to have_http_status(:accepted)
Expand All @@ -229,7 +229,7 @@
context 'with invalid command' do
it 'renders a response with error' do
stack = Stack.create! valid_attributes
post stack_control_url(stack.uuid), params: { command: 'invalid' }, headers: valid_headers, as: :json
post control_stack_url(stack.uuid), params: { command: 'invalid' }, headers: valid_headers, as: :json
expect(response).not_to be_successful
expect(response).to have_http_status(:bad_request)
expect(response.body).to include('Invalid control command')
Expand All @@ -239,7 +239,7 @@
context 'with valid command' do
it 'renders a response with success' do
stack = Stack.create! valid_attributes
post stack_control_url(stack.uuid), params: { command: 'start' }, headers: valid_headers, as: :json
post control_stack_url(stack.uuid), params: { command: 'start' }, headers: valid_headers, as: :json
expect(response).to be_successful
expect(response).to have_http_status(:no_content)
end
Expand All @@ -249,7 +249,7 @@
describe 'GET /log' do
it 'renders a successful response' do
stack = Stack.create! valid_attributes
get stack_log_url(stack.uuid), headers: valid_headers, as: :json
get log_stack_url(stack.uuid), headers: valid_headers, as: :json
expect(response).to be_successful
end
end
Expand Down

0 comments on commit ae33a53

Please sign in to comment.