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

Test fix - assertion fails when run with other tests (sometimes) #20250

Merged
merged 1 commit into from
May 8, 2021

Conversation

eileenmcnaughton
Copy link
Contributor

@eileenmcnaughton eileenmcnaughton commented May 8, 2021

Overview

Test fix - assertion fails when run with other tests (sometimes)

Before

Test only passes when the next autoincrement for civicrm_contribution.id is 1

After

Test passes regardless

Technical Details

The assertion that invoice_number = INV_ + contribution_id is wrong. In fact
it is calculated as INV_ + (MAX(contribution_id)+1) prior to the contribution
being saved. This means that if the table has not been truncated the contribution
id might be 3 but the invoice_number would still be 0+1 - ie INV_1

  • we could argue about whether the calculation method is flawed but this at least
    makes the test more reliable and no-one has complained in practice about the
    code behaviour

Comments

The assertion that invoice_number = INV_ + contribution_id is wrong. In fact
it is calculated as INV_ + (MAX(contribution_id)+1) prior to the contribution
being saved. This means that if the table has not been truncated the contribution
id might be 3 but the invoice_number would still be 0+1 - ie INV_1

- we could argue about whether the calculation method is flawed but this at least
makes the test more reliable and no-one has complained in practice about the
code behaviour
@civibot
Copy link

civibot bot commented May 8, 2021

(Standard links)

@civibot civibot bot added the master label May 8, 2021
@demeritcowboy
Copy link
Contributor

  • General standards
    • [r-explain] Soft Pass
      • It would have been a quicker review but I had to hunt for it:
        $nextContributionID = CRM_Core_DAO::singleValueQuery("SELECT COALESCE(MAX(id) + 1, 1) FROM civicrm_contribution");
      • It took me a bit to think through the scenario - "not truncated" but ALSO all the records have been deleted (via DELETE as opposed to truncate), so then the max calculation be null, but the autoincrement counter would still be at whatever it was before the DELETE for when the contribution is inserted.
      • The other changes are fixing the order of arguments to assert(), which were backwards.
    • [r-user] PASS
    • [r-doc] PASS
    • [r-run] PASS
  • Developer standards
    • [r-tech] PASS
      • I suppose it's ok to do the invoice assert as you've done with the regex to leave it more open rather than enforce the possibly weird calculation.
    • [r-code] PASS
    • [r-maint] PASS
    • [r-test] PASS

@demeritcowboy demeritcowboy merged commit f332e6b into civicrm:master May 8, 2021
@eileenmcnaughton eileenmcnaughton deleted the in branch May 8, 2021 21:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants