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

set min/max correctly when values are zero [MRXN23-559] #1631

Merged

Conversation

hotzevzl
Copy link
Member

Substitute this line for a meaningful title for your changes

Overview

Fix my own 🤦🏼 bug that broke stuff because of an improper reliance on falseish values.

Designs

N/A

Testing instructions

There's a new unit test file, which I believe captures most of the logic and edge cases, including the sad-trombone bug in my previous implementation.

Feature relevant tickets

https://vizzuality.atlassian.net/browse/MRXN23-559


Checklist before submitting

  • Meaningful commits and code rebased on develop.
  • If this PR adds feature that should be tested for regressions when
    deploying to staging/production, please add brief testing instructions
    to the deploy checklist (docs/deployment-checklist.md)
  • Update CHANGELOG file

Initial implementation would incorrectly trigger the branch of the
ternary operator that ends up setting min or max to `null` for any
falseish value (including numeric `0`).

We should probably treat undefined `feature?.amountMin` or
`feature?.amountMin` as error conditions, but that's something beyond
the scope of the current change.
To avoid SLOC inflation in class, conflation of concerns, and to make it
easier to unit-test logic.
Copy link

vercel bot commented Jan 18, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
marxan ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 18, 2024 2:32pm

@hotzevzl hotzevzl force-pushed the fix/api/MRXN23-559_set-min-max-correctly-when-values-are-zero branch from e164844 to f3e89fb Compare January 18, 2024 14:29
@hotzevzl hotzevzl changed the title set min max correctly when values are zero [MRXN23-559] set min/max correctly when values are zero [MRXN23-559] Jan 18, 2024
@hotzevzl hotzevzl marked this pull request as ready for review January 18, 2024 14:32
@hotzevzl hotzevzl requested a review from KevSanchez January 18, 2024 14:32
@hotzevzl
Copy link
Member Author

hotzevzl commented Jan 18, 2024

@KevSanchez the issue here was a classical PEBKAC on my end:

let minResult = feature?.amountMin ? feature?.amountMin : null;
let maxResult = feature?.amountMax ? feature?.amountMax : null;

This is obviously going to result in a loud sad-trombone fail sound when feature.amountMin === 0 or feature.amountMax === 0.

Since my being a bad person didn't stop at this bug but also at sticking more and more code inside of the already-inflated ProjectsService class, I took this opportunity for atonement, moving the conversion function to its own corner of the source tree, not least to make unit-testing it easier (and I included indeed unit tests that also stress the bug I believe to have fixed).

@KevSanchez
Copy link
Collaborator

To be fair, I would have followed the exact same assumption; another stark reminder of the dangerous subtleties of javascript :\

@hotzevzl hotzevzl merged commit cf0a82b into develop Jan 19, 2024
61 checks passed
@hotzevzl hotzevzl deleted the fix/api/MRXN23-559_set-min-max-correctly-when-values-are-zero branch January 19, 2024 09:35
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.

2 participants