Skip to content

Commit 07a6d33

Browse files
committed
Add test coverage for raising/rescuing of InvalidNode
I hope this might help avoid a repeat of #2474 in which the implementation of `Outcome#transition` was accidentally removed [1]. I've also added test coverage for the rescuing of `FlowRegistry::NotFound` while I was at it. [1]: 0929036
1 parent c084664 commit 07a6d33

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
require_relative '../integration_test_helper'
2+
require 'gds_api/test_helpers/content_api'
3+
4+
class SmartAnswersControllerErrorHandlingTest < ActionDispatch::IntegrationTest
5+
include GdsApi::TestHelpers::ContentApi
6+
7+
setup do
8+
@flow_registry = stub('flow-registry')
9+
SmartAnswer::FlowRegistry.stubs(:instance).returns(@flow_registry)
10+
stub_content_api_default_artefact
11+
end
12+
13+
context 'when SmartAnswer::InvalidNode raised' do
14+
setup do
15+
flow = stub('flow', name: 'flow-name')
16+
flow.stubs(:process).raises(SmartAnswer::InvalidNode)
17+
@flow_registry.stubs(:find).returns(flow)
18+
end
19+
20+
should 'set response status code to 404' do
21+
get '/flow-name'
22+
assert_response 404
23+
end
24+
end
25+
26+
context 'when SmartAnswer::InvalidNode raised' do
27+
setup do
28+
flow = stub('flow', name: 'flow-name')
29+
@flow_registry.stubs(:find).raises(SmartAnswer::FlowRegistry::NotFound)
30+
end
31+
32+
should 'set response status code to 404' do
33+
get '/flow-name'
34+
assert_response 404
35+
end
36+
end
37+
end

test/unit/outcome_test.rb

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
require_relative '../test_helper'
2+
3+
module SmartAnswer
4+
class OutcomeTest < ActiveSupport::TestCase
5+
setup do
6+
@outcome = Outcome.new(nil, 'node-name')
7+
end
8+
9+
context '#transition' do
10+
should 'raise InvalidNode exception so app responds with 404 Not Found' do
11+
assert_raises(InvalidNode) do
12+
@outcome.transition
13+
end
14+
end
15+
end
16+
end
17+
end

0 commit comments

Comments
 (0)