-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ap-4463: poc refactor provider_dwp_override flow #6002
Conversation
5c78639
to
100ccb4
Compare
100ccb4
to
2a51d07
Compare
♻️ Looks good The helper seems straightforward, so does the flow update and spec pattern 👍 Depending on how complex or how many more params are required by other flows, would it be ideal to use named params in structs |
describe "#path" do | ||
subject(:path) { described_class.path.call(legal_aid_application) } | ||
|
||
it "returns the check_client_details_path when called" do | ||
expect(path).to eq "/providers/applications/#{legal_aid_application.id}/check_client_details?locale=en" | ||
end | ||
end | ||
|
||
describe "#forward" do | ||
subject(:forward) { described_class.forward } | ||
|
||
it "returns the about_financial_means step when called" do | ||
expect(forward).to eq(:received_benefit_confirmations) | ||
end | ||
end | ||
|
||
describe "#check_answers" do | ||
subject(:check_answers) { described_class.check_answers } | ||
|
||
it "returns nil" do | ||
expect(check_answers).to be_nil | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could use a generic custom matcher since we are going to do a lot of these
quick example:
# spec/support/have_flow_step_args.rb
RSpec::Matchers.define :have_flow_step_args do |expected|
results = { path: nil, forward: nil, check_answers: nil }
match do |actual|
results[:path] = actual.path.call(legal_aid_application) == expected[:path]
results[:forward] = actual.forward == expected[:forward]
results[:check_answers] = actual.check_answers == expected[:check_answers]
results.values.all?(true)
end
failure_message do |actual|
message = ""
message += "expected #{actual.path.call(legal_aid_application)} to equal #{expected[:path]}\n" if actual.path.call(legal_aid_application) != expected[:path]
message += "expected #{actual.forward} to equal #{expected[:forward]}\n" if actual.forward != expected[:forward]
message += "expected #{actual.check_answers} to equal #{expected[:check_answers]}\n" if actual.check_answers != expected[:check_answers]
message
end
description do
"have matching flow step arguments"
end
end
And use:
it "has expected flow step" do
expect(described_class).to have_flow_step_args(path: "/providers/applications/#{legal_aid_application.id}/check_client_details?locale=en",
forward: :reeived_benefit_confirmations,
check_answers: nil)
end
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have added a commit to add a custom_matcher similar to the above. To make it generic, I have had to use a common name for the second paramater that is sometimes passed to the step lambda in the specs - I have called it args, but am not sure whether this is confusing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good.
Additional considerations (see comments for examples and details):
- do we want to namespace further into "collections" of steps?
- do we want to use keyword args for increased clarity?
- do we want to use a custom matcher for testing flow steps?
Otherwise 🎖️
spec/support/have_flow_steps_args.rb
Outdated
@@ -0,0 +1,31 @@ | |||
RSpec::Matchers.define :have_flow_step_args do |_options| |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isn't _options
the expected
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
spec/support/have_flow_steps_args.rb
Outdated
message = "" | ||
message += "expected #{actual.path.call(legal_aid_application)} to equal #{expected[:path]}\n" if actual.path.call(legal_aid_application) != expected[:path] | ||
if actual.forward.is_a?(Proc) | ||
message += "expected #{actual.forward.call(legal_aid_application, args)} to equal #{expected[:forward]}\n" if actual.forward.call(legal_aid_application, args) != expected[:forward] | ||
elsif actual.forward != expected[:forward] | ||
message += "expected #{actual.forward} to equal #{expected[:forward]}\n" | ||
end | ||
message += "expected #{actual.check_answers} to equal #{expected[:check_answers]}\n" if actual.check_answers != expected[:check_answers] | ||
message |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can probably be neatened up by constructing the message as part of the test above and then just results.join("\n")
in this block - see be_soap_envelope_with
for example.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 have made this change
6f2b113
to
1b18607
Compare
Kudos, SonarCloud Quality Gate passed! 0 Bugs No Coverage information |
What
Link to story
For review/discussion.
Checklist
Before you ask people to review this PR:
bundle exec rake
git rebase main
.