Skip to content

Commit

Permalink
Improve formatting of ActionsHandler spec file
Browse files Browse the repository at this point in the history
  • Loading branch information
y9v committed Jan 20, 2025
1 parent 4d47360 commit 5a05cab
Showing 1 changed file with 26 additions and 33 deletions.
59 changes: 26 additions & 33 deletions spec/datadog/appsec/actions_handler_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,45 +21,41 @@
end

it 'calls generate_stack with action parameters' do
expect(described_class).to(
receive(:generate_stack).with(generate_stack_action['generate_stack']).and_call_original
)
expect(described_class).to receive(:generate_stack)
.with(generate_stack_action['generate_stack']).and_call_original

described_class.handle(generate_stack_action)
end

it 'calls generate_schema with action parameters' do
expect(described_class).to(
receive(:generate_schema).with(generate_schema_action['generate_schema']).and_call_original
)
expect(described_class).to receive(:generate_schema)
.with(generate_schema_action['generate_schema']).and_call_original

described_class.handle('generate_schema' => generate_schema_action['generate_schema'])
end

it 'calls redirect_request with action parameters' do
expect(described_class).to(
receive(:redirect_request).with(redirect_request_action['redirect_request']).and_call_original
)
expect(described_class).to receive(:redirect_request)
.with(redirect_request_action['redirect_request']).and_call_original

catch(Datadog::AppSec::Ext::INTERRUPT) do
described_class.handle(redirect_request_action)
end
end

it 'calls block_request with action parameters' do
expect(described_class).to(
receive(:block_request).with(block_request_action['block_request']).and_call_original
)
expect(described_class).to receive(:block_request)
.with(block_request_action['block_request']).and_call_original

catch(Datadog::AppSec::Ext::INTERRUPT) do
described_class.handle(block_request_action)
end
end

it 'calls redirect_request only when both block_request and redirect_request are present' do
expect(described_class).to(
receive(:redirect_request).with(redirect_request_action['redirect_request']).and_call_original
)
expect(described_class).to receive(:redirect_request)
.with(redirect_request_action['redirect_request']).and_call_original

expect(described_class).not_to receive(:block_request)

catch(Datadog::AppSec::Ext::INTERRUPT) do
Expand All @@ -68,36 +64,33 @@
end

it 'calls both generate_stack and generate_schema when both are present' do
expect(described_class).to(
receive(:generate_stack).with(generate_stack_action['generate_stack']).and_call_original
)
expect(described_class).to(
receive(:generate_schema).with(generate_schema_action['generate_schema']).and_call_original
)
expect(described_class).to receive(:generate_stack)
.with(generate_stack_action['generate_stack']).and_call_original

expect(described_class).to receive(:generate_schema)
.with(generate_schema_action['generate_schema']).and_call_original

described_class.handle(generate_stack_action.merge(generate_schema_action))
end

it 'calls both generate_stack and block_request when both are present' do
expect(described_class).to(
receive(:generate_stack).with(generate_stack_action['generate_stack']).and_call_original
)
expect(described_class).to(
receive(:block_request).with(block_request_action['block_request']).and_call_original
)
expect(described_class).to receive(:generate_stack)
.with(generate_stack_action['generate_stack']).and_call_original

expect(described_class).to receive(:block_request)
.with(block_request_action['block_request']).and_call_original

catch(Datadog::AppSec::Ext::INTERRUPT) do
described_class.handle(generate_stack_action.merge(block_request_action))
end
end

it 'calls both generate_stack and redirect_request when both are present' do
expect(described_class).to(
receive(:generate_stack).with(generate_stack_action['generate_stack']).and_call_original
)
expect(described_class).to(
receive(:redirect_request).with(redirect_request_action['redirect_request']).and_call_original
)
expect(described_class).to receive(:generate_stack)
.with(generate_stack_action['generate_stack']).and_call_original

expect(described_class).to receive(:redirect_request)
.with(redirect_request_action['redirect_request']).and_call_original

catch(Datadog::AppSec::Ext::INTERRUPT) do
described_class.handle(generate_stack_action.merge(redirect_request_action))
Expand Down

0 comments on commit 5a05cab

Please sign in to comment.