mirror of
https://github.com/MichMich/MagicMirror.git
synced 2026-05-09 22:28:33 +00:00
While removing unnecessary conditionals (for `compliments` reported in https://github.com/MagicMirrorOrg/MagicMirror/security/code-scanning/27 and for `weather` reported in https://github.com/MagicMirrorOrg/MagicMirror/security/code-scanning/28), I noticed a bug in the imperial conversion path: falsy property checks like `if (imperialWeatherObject.temperature)` silently skip the conversion when the value is `0`. So at exactly 0 °C, the result would show `0 °F` instead of the correct `32 °F`. I wrote unit tests for `convertWeatherObjectToImperial` first, which confirmed the bug, then fixed it by replacing the falsy checks with the `in` operator. Which I also find more intuitive to read. Weather APIs deliver floating point values, so hitting exactly `0.0` might be rare in practice - more likely `0.1` or `-0.1`, which are truthy and convert fine. That should explain why it went unnoticed by users.