Skip to content
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

Closed
wants to merge 7 commits into from

Conversation

kmahern
Copy link
Contributor

@kmahern kmahern commented Nov 16, 2023

What

Link to story

For review/discussion.

Checklist

Before you ask people to review this PR:

  • Tests and rubocop should be passing: bundle exec rake
  • Github should not be reporting conflicts; you should have recently run git rebase main.
  • There should be no unnecessary whitespace changes. These make diffs harder to read and conflicts more likely.
  • The PR description should say what you changed and why, with a link to the JIRA story.
  • You should have looked at the diff against main and ensured that nothing unexpected is included in your changes.
  • You should have checked that the commit messages say why the change was made.

@kmahern kmahern changed the title ap-4463: refactor confirm dwp non passported step ap-4463: poc refactor provider_dwp_override flow Nov 16, 2023
@kmahern kmahern force-pushed the ap-4463-flow-refactoring-poc branch 5 times, most recently from 5c78639 to 100ccb4 Compare November 20, 2023 15:06
@kmahern kmahern force-pushed the ap-4463-flow-refactoring-poc branch from 100ccb4 to 2a51d07 Compare November 21, 2023 08:34
@naseberry
Copy link
Contributor

naseberry commented Nov 21, 2023

♻️ 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

Comment on lines 6 to 28
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
Copy link
Contributor

@jsugarman jsugarman Nov 21, 2023

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

Copy link
Contributor Author

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?

Copy link
Contributor

@jsugarman jsugarman left a 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):

  1. do we want to namespace further into "collections" of steps?
  2. do we want to use keyword args for increased clarity?
  3. do we want to use a custom matcher for testing flow steps?

Otherwise 🎖️

@@ -0,0 +1,31 @@
RSpec::Matchers.define :have_flow_step_args do |_options|
Copy link
Contributor

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Comment on lines 17 to 25
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
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 have made this change

@kmahern kmahern force-pushed the ap-4463-flow-refactoring-poc branch from 6f2b113 to 1b18607 Compare November 23, 2023 09:05
Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@kmahern kmahern marked this pull request as ready for review November 23, 2023 13:01
@kmahern kmahern requested a review from a team as a code owner November 23, 2023 13:01
@kmahern kmahern closed this Mar 19, 2024
@kmahern kmahern deleted the ap-4463-flow-refactoring-poc branch July 22, 2024 12:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants