Skip to content

fix: Govern minimum-donation validation with unit testing

An earlier MR was made against a regression which crept into the codebase that prevented custom donations from being donateable. A comment was made at the time which went something like, "Interesting how that could have escaped unit testing."

It is interesting! It is in fact SO interesting that my intended fix being insufficient also escaped unit testing.

This MR fixes the unit testing around the custom_donation value AS A FIRST MEASURE, and then, with the power of unit testing in hand, implements a more straightforward validation method as a followup measure.

Changes:

  • We only need to test whether custom_donation is an int, as the donation form was designed around handling whole dollar amounts - note roadmap on #68 - so we do
  • It's much safer to just add another value to the minimum_donation object which represents whole dollars rather than convert custom_donation to cents on the fly, so we do
  • The big problem all along is that the unit test was seeding the form with a custom_donation value of 2500 - since that's dollars and not cents, that's $2500 - and comparing it to a minimum-donation value in cents. This caused the unit test to pass without question, as the "insufficient donation" test which sets the donation value to "one fewer than the donation minimum" wound up testing 199 against 2.00 (instead of 199 against 200 or 1.99 against 2.00).

Merge request reports