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

Extract marriage-abroad payment information from templates #2502

Conversation

chrisroos
Copy link
Contributor

@chrisroos chrisroos commented May 3, 2016

This has been superseded by PR #2507, which should hopefully incorporate all the feedback from this PR.

Trello card: https://trello.com/c/K2bUzopZ

The Trello card is about removing payment information and links to consular fees from outcomes that don't display services/fees.

This branch removes the payment information but not the links to consular fees. I plan to deal with that in a separate branch.

Overview of the changes in this branch:

  • Add full set of ceremony countries to regression test data. This allows me to use the marriage-abroad-countries-leading-to-outcome.rb script to determine the countries that might be affected by a change to the outcome template.
  • Extract the payment information from the templates to the marriage_abroad_services.yml file. Update the regression test artefacts where this extraction results in changes to the outcomes.
  • Introduce the _payment_for_services partial to display the relevant payment information for the ceremony country.
  • Move payment partials to the payment_information_partials directory.

I would've preferred to store a set of acceptable payment methods in the YAML file (rather than the partial name) but that doesn't seem possible at the moment given how varied the payment information can be.

I've only added the payment information to the ceremony countries that already have entries in marriage_abroad_services.yml (i.e. the services/fees section is displayed for at least some of the outcomes). This ensures that we're no longer displaying the payment information on outcomes where the services/fees section isn't displayed.

While working on this branch, I used the complete set of regression test artefacts for marriage-abroad so that I could sanity check the changes I was making. I've removed these from the commits now that I'm happy with the changes that have been made.

This branch has exposed a couple of other issues.

  • Outcomes for a number of ceremony countries display services/fees but no payment information.
  • Outcomes for a number of ceremony countries were displaying different payment information depending on the type of ceremony. I think (hope) this is an oversight as the mechanism in this branch only allows for payment information to be specified for the country and not at a more granular level.

I've added comments to the Trello card to ask how we address both of these issues.

I plan to add another Trello card to work out whether we can reduce the number of payment information partials in the system.

Add full set of input countries using:

    $ rails r script/generate-questions-and-responses-for-smart-answer.rb \
    marriage-abroad
Using:

    $ rails r script/generate-responses-and-expected-results-for-smart-answer.rb \
    marriage-abroad
This appears to be a special case for the Philippines. I'm extracting it in
preparation for moving this payment method information to the
marriage_abroad_services.yml file.
…peak.erb

This appears to be specific to South Korea, although it's incredibly similar to
the existing `_pay_by_cash_or_credit_card_no_cheque` partial. I'll make a note
to follow that up separately.

This is in preparation for moving the payment method information to
marriage_abroad_services.yml.
The `outcome_opposite_sex_marriage_in_affirmation_countries` outcome is the
only outcome that renders the `fees` partial. I used the following command to
determine the countries that lead to this outcome:

    $ rails r script/marriage-abroad-countries-leading-to-outcome.rb \
    outcome_opposite_sex_marriage_in_affirmation_countries

I created the add-payment-partials-to-marriage-abroad-services-data.rb to
update the data in marriage_abroad_services.yml. I plan to update this script
as I continue to extract the payment info from the templates.

Running the script in this commit results in no output which means that the
payment information for each of the countries listed has been successfully
added to marriage_abroad_services.yml.
So that I can reuse it in other templates.
In preparation for moving this information to the marriage_abroad_services.yml
file.
In preparation for extracting this payment info to the
marriage_abroad_services.yml file.
In preparation for moving this data to the marriage_abroad_services.yml file.
…ni_countries_when_residing_in_uk_or_ceremony_country

I determined the list of countries that can lead to this outcome by using:

    $ rails r script/marriage-abroad-countries-leading-to-outcome.rb \
    outcome_opposite_sex_marriage_in_consular_cni_countries_when_residing_in_uk_or_ceremony_country

I've updated the add-payment-partials-to-marriage-abroad-services-data.rb
script to extract the payment info for these countries.

The output of running the script was:

Entry not found for afghanistan.
Entry not found for american-samoa.
Entry not found for andorra.
Entry not found for benin.
Entry not found for bhutan.
Entry not found for brazil.
Entry not found for burkina-faso.
Entry not found for cape-verde.
Entry not found for central-african-republic.
Entry not found for chad.
Entry not found for comoros.
Entry not found for congo.
Entry not found for djibouti.
Entry not found for equatorial-guinea.
Entry not found for eritrea.
Entry not found for gabon.
Entry not found for guinea.
Entry not found for guinea-bissau.
Entry not found for haiti.
Entry not found for iraq.
Entry not found for libya.
Entry not found for liechtenstein.
Entry not found for mali.
Entry not found for marshall-islands.
Entry not found for mauritania.
Entry not found for micronesia.
Entry not found for niger.
Payment method partial already set for norway. Existing value: pay_by_visas_or_mastercard. New value: pay_by_cash_or_credit_card_no_cheque.
Entry not found for palau.
Entry not found for paraguay.
Entry not found for rwanda.
Entry not found for san-marino.
Entry not found for sao-tome-and-principe.
Entry not found for south-sudan.
Entry not found for suriname.
Entry not found for timor-leste.
Entry not found for togo.
Entry not found for western-sahara.

I've confirmed that the changes the regression test artefacts are all expected
based on the output from running the script. The payment information has been
removed from all those listed, apart from Norway. The payment information for
Norway has changed. I plan to follow up on this to work out what the payment
information should be.
In preparation for moving this data to the marriage_abroad_services.yml file.
…tries

Although this outcome is used for a number of ceremony countries, only Saudi
Arabia displays the _consular_fees_table partial, so that's the only country we
need to add payment information for in marriage_abroad_services.yml.
…mation_countries

I determined the countries that lead to this outcome using:

    $ rails r script/marriage-abroad-countries-leading-to-outcome.rb \
    outcome_same_sex_civil_partnership_in_affirmation_countries

belgium
norway

The payment partial to use for both Belgium and Norway is already in
marriage_abroad_services.yml.
…lar_countries

I used the following script to determine which countries lead to this outcome:

    $ rails r script/marriage-abroad-countries-leading-to-outcome.rb \
    outcome_same_sex_civil_partnership_in_consular_countries

I updated the add-payment-partials-to-marriage-abroad-services-data.rb script
and ran it. There was no output and the marriage_abroad_services.yml file
didn't change which means that the payment information for these countries must
already be present.
I determined the countries that lead to this outcome by running:

    $ rails r script/marriage-abroad-countries-leading-to-outcome.rb \
    outcome_same_sex_civil_partnership

I updated the add-payment-partials-to-marriage-abroad-services-data.rb script
and ran it. This was the output:

Entry not found for brazil.
Payment method partial already set for finland. Existing value:
pay_in_euros_or_visa_electron. New value: pay_by_cash_or_credit_card_no_cheque.

I'll add a separate task to investigate the difference for Finland.

I've updated the regression test artefacts. The changes to Brazil and Finland
are expected based on the output from the script above.
…ship

I determined which countries lead to this outcome by using:

    $ rails r script/marriage-abroad-countries-leading-to-outcome.rb \
    outcome_same_sex_marriage_and_civil_partnership

I updated and ran the add-payment-partials-to-marriage-abroad-services-data.rb
script, which gave the following output:

Payment method partial already set for japan. Existing value: pay_by_credit_card_but_not_personal_cheque. New value: pay_by_cash_or_credit_card_no_cheque.
Payment method partial already set for latvia. Existing value: pay_in_local_currency_ceremony_country_name. New value: pay_by_cash_or_credit_card_no_cheque.
Payment method partial already set for philippines. Existing value: pay_by_cash_or_bank_cheque. New value: pay_by_cash_or_credit_card_no_cheque.
Payment method partial already set for russia. Existing value: pay_by_mastercard_and_visa_only. New value: pay_by_cash_or_credit_card_no_cheque.

I'll add a separate task to investigate the correct information for each of
these countries.

I've updated the regression test artefacts as part of this commit:

* Payment info for same sex ceremonies in Japan, Latvia, Philippines and Russia
  has been updated. The info displayed is the info already in the
  marriage_abroad_services.yml file.

* Payment info for same sex ceremonies in Vietnam has been added. This looks
  correct as we're displaying the services/fees section for these outcomes.
…brazil_or_third_country

This outcome doesn't display the _consular_fees_table partial so shouldn't
render the payment information partial either.

NOTE. The link_to_consular_fees_pay_in_local_currency partial should almost
certainly be removed too but I'll deal with that separately.
…n_residing_in_ceremony_or_third_country

This outcome doesn't display the _consular_fees_table partial so shouldn't
render the payment information partial either.

NOTE. The link_to_consular_fees_pay_in_local_currency partial should almost
certainly be removed too but I'll deal with that separately.

I've confirmed that the changes to the regression test artefacts look correct.
I compared the list of countries that lead to this outcome to the changes to
the artefacts:

I used the following command to get the list of countries leading to this
outcome:

    $ rails r script/marriage-abroad-countries-leading-to-outcome.rb \
    outcome_opposite_sex_in_no_cni_countries_when_residing_in_ceremony_or_third_country

NOTE. The remainder of this commit note was written when I had a complete set
(i.e. for every ceremony country) of regression test artefacts for
marriage-abroad. I think the information is still useful so I'm leaving it in.

The following countries lead to this outcome and have had the payment
information removed from their artefacts:

* afghanistan
* american-samoa
* andorra
* benin
* bhutan
* burkina-faso
* cape-verde
* central-african-republic
* chad
* comoros
* congo
* djibouti
* equatorial-guinea
* eritrea
* gabon
* guinea
* guinea-bissau
* haiti
* iraq
* liechtenstein
* mali
* marshall-islands
* mauritania
* micronesia
* niger
* palau
* paraguay
* rwanda
* san-marino
* sao-tome-and-principe
* south-sudan
* suriname
* timor-leste
* togo
* western-sahara

The following countries lead to this outcome but are in the
`COUNTRIES_WITHOUT_CONSULAR_FACILITIES` array (i.e.
`#country_without_consular_facilities?` is true) so they weren't displaying any
payment information anyway.

* aruba
* bonaire-st-eustatius-saba
* burundi
* curacao
* saint-barthelemy
* st-maarten
* st-martin
I prefer having these related partials in a single directory.
This has served its purpose and can be safely removed.
This reverts commit 401e6dfd570d40f1cce5fca92ae7ccf6df0859a6.

This has served its purpose now that I've extracted all the payment information
from the marriage-abroad outcome templates.
This reverts commit 4685f7e0e793989e3ca10162ef06383d10583988.

This has served its purpose now that I've extracted all the payment information
from the marriage-abroad outcome templates.
The marriage-abroad regression tests are passing.
@floehopper floehopper self-assigned this May 3, 2016
if @services_data[ceremony_country].present?
@services_data[ceremony_country]['payment_partial_name']
end
end
Copy link
Contributor

@floehopper floehopper May 3, 2016

Choose a reason for hiding this comment

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

Minor: I think you could use the (relatively new) Ruby Hash#dig method here to make the code a bit more succinct:

def services_payment_partial_name
  @services_data.dig(ceremony_country, 'payment_partial_name')
end

Copy link
Contributor

Choose a reason for hiding this comment

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

Minor: Since this is arguably presentational logic, did you consider making this a view helper method? I think I'm happy with the approach you've taken, because you've talked about ideally wanting to store the source data (as opposed to the partial template name) in the YAML.

Copy link
Contributor

Choose a reason for hiding this comment

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

Minor: Thinking about it a bit more, rather than use Hash#dig, perhaps we could extract a method like this to avoid the if statement:

def ceremony_country_data
  @services_data[ceremony_country] || {}
end

def services_payment_partial_name
  ceremony_country_data['payment_partial_name']
end

Copy link
Contributor

Choose a reason for hiding this comment

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

Minor: what about renaming payment_partial_name into payment_type? And getting the partial name using something like the code below in the calculator?

def services_payment_partial_name
  ceremony_country_data['payment_type']
end

Not sure about talking about partials in the config file?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Minor: Since this is arguably presentational logic, did you consider making this a view helper method? I think I'm happy with the approach you've taken, because you've talked about ideally wanting to store the source data (as opposed to the partial template name) in the YAML.

@floehopper: It didn't cross my mind to add it as a helper method. The MarriageAbroadCalculator felt like the natural place for it given how closely this relates to the other service information the calculator is responsible for. If we are able to store acceptable payment types, instead of names of partials, then I can imagine using the MarriageAbroadCalculator to retrieve the data and a new helper method to turn it into a sentence.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Minor: what about renaming payment_partial_name into payment_type?

Not sure about talking about partials in the config file?

@pmanrubia: I agree that mentioning partials in the data isn't ideal. Given that I can't see an easy way round it at the moment I prefer to make it explicit that the data represents the name of a partial to render. Using something like payment_type might lead someone to think they can store an arbitrary string against that key.

Copy link
Contributor Author

@chrisroos chrisroos May 6, 2016

Choose a reason for hiding this comment

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

Minor: Thinking about it a bit more, rather than use Hash#dig, perhaps we could extract a method like this to avoid the if statement:

@floehopper: I've extracted such a method in 3fb1059.

@floehopper
Copy link
Contributor

As you will probably have gathered from my previous comments, I found this PR a bit hard to follow:

  • I may have missed it, but it would help if there was a general explanation of what the marriage-abroad-countries-leading-to-outcome.rb script does and how you used it.
  • I think most commits in this PR are of 2 (or possibly 3) types, but all of their commit note subject lines start with the word "Extract". This makes it hard to discriminate between the different types of commit.
  • The commit notes didn't seem to make it clear how you decided that the changes to the regression test artefacts were acceptable.
  • I think my confusion about the changes to the regression test artefacts was made worse, because I initially overlooked the fact that the purpose of the PR is to "remove payment information from outcomes that don't display services/fees", so I was expecting this PR to just be a refactoring.
  • It feels as if there is some sense in which single commits are doing both refactoring and making a change to the behaviour. Or have I got that wrong?
  • In general I'm in favour of the refactoring aspect of this PR - I think it's much better if we store data about each country rather than conditionals which use lists of countries which share some random characteristic.
  • It's great that you've identified some discrepancies. I hope you get some answers relatively quickly.
  • I reckon it would be worthwhile flagging up some of the (accidental?) variation in the payment partials to see whether this list can be further consolidated and ideally converted into list of acceptable/unacceptable payment types for each country. The benefit to the FCO & the Content Team would be that it would be much easier to update this data.
  • All in all it looks great (good work!), but I think I need to come back to it once you've explained more about the marriage-abroad-countries-leading-to-outcome.rb script and the changes to the regression test artefacts. Hence I'm not marking it as LGTM for now.

@chrisroos
Copy link
Contributor Author

Thanks for reviewing, @floehopper and @pmanrubia.

I'm going to close this open a new PR that addresses your feedback.

@chrisroos chrisroos closed this May 6, 2016
@chrisroos chrisroos deleted the extract-marriage-abroad-payment-information-from-templates branch May 6, 2016 04:14
@chrisroos chrisroos restored the extract-marriage-abroad-payment-information-from-templates branch May 6, 2016 04:20
@chrisroos chrisroos deleted the extract-marriage-abroad-payment-information-from-templates branch May 6, 2016 04:21

countries.each do |country|
payment_partial_name = payment_method_partial[country] ||
payment_method_partial['default']
Copy link
Contributor Author

Choose a reason for hiding this comment

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

What's the purpose of this default value? It doesn't look as if it's being used in the app code.

@floehopper: It's used on this line in the temporary script. It's the default value stored in the marriage_abroad_services.yml file when no country specific value exists.

@chrisroos
Copy link
Contributor Author

  • I may have missed it, but it would help if there was a general explanation of what the marriage-abroad-countries-leading-to-outcome.rb script does and how you used it.

@floehopper: I've attempted to explain the use of this script in the following paragraph in the description of PR #2507:

For outcomes that are rendered for multiple countries, I used the marriage-abroad-countries-leading-to-outcome.rb script to get a list of those countries before updating the add-payment-partials-to-marriage-abroad-services-data.rb script.

I've also got a separate note to add some more information about that script. Either to the script itself, or to some docs.

@chrisroos
Copy link
Contributor Author

  • I think most commits in this PR are of 2 (or possibly 3) types, but all of their commit note subject lines start with the word "Extract". This makes it hard to discriminate between the different types of commit.

@floehopper: I've attempted to improve this slightly in PR #2507 by making it clearer when the commit extracts a partial, versus when it extracts payment information from a template. I can see that it's still not very clear but hopefully it's slightly better.

@chrisroos
Copy link
Contributor Author

  • The commit notes didn't seem to make it clear how you decided that the changes to the regression test artefacts were acceptable.

@floehopper: I've attempted to improve this in PR #2507. See 9a91b1f for an example.

@chrisroos
Copy link
Contributor Author

  • I think my confusion about the changes to the regression test artefacts was made worse, because I initially overlooked the fact that the purpose of the PR is to "remove payment information from outcomes that don't display services/fees", so I was expecting this PR to just be a refactoring.

@floehopper: I've renamed the branch in PR #2507 to (hopefully) make its purpose clearer.

@chrisroos
Copy link
Contributor Author

  • It feels as if there is some sense in which single commits are doing both refactoring and making a change to the behaviour. Or have I got that wrong?

@floehopper. That's correct in the case of some commits. I think it would've been possible to create a branch that just refactored how the payment information was displayed before then separately removing it for those countries that shouldn't display it. While possible, I think this would've been quite a lot more work as I would've had to support displaying different payment information for a single country. I believe this only exists by mistake (i.e. templates have been split causing differences between the information displayed for the same country).

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.

None yet

3 participants