MNTOR-3848: Fix invalid assertions #5521
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
References:
Jira: MNTOR-3848
Figma:
Description
Builds on #5511, but addressing the root cause.
Knex's returning() API is intended for INSERT, UPDATE and DELETE calls, not SELECTs:
https://knexjs.org/guide/query-builder.html#returning
I've updated the .where() queries to replace the returning() calls, i.e. by making them select all columns.
I then also removed the type assertions, so as to not indicate that rows will always be returned even in cases where they might not be available.
Also, the type assertion pretended that the
monthly_monitor_report_free
column could only beboolean | undefined
, even though it can benull
too (seeaddUnsubcribeTokenForSubscriber
, which sets it tonull
).And finally, the actual root cause of the issue, the return type indicated that it would never return
undefined
, even though it's returningres?.[0]
. I've updated that, and then fixed type errors to deal with the potentially undefined value. Question: I assumed that users without stored preferences are defaulted to be opted-in, is that correct?(And actually I think they used to default to opted out, through undefined resolving to
false
. My?? true
makes them default totrue
.)How to test
I'm not sure how to reproduce the original issue, so I don't know how to verify that this fixes it, but I'm fairly sure that the unit tests show what was reported.
But if someone has reproduced the issue and could verify that this fixes it, that'd be great.
Checklist (Definition of Done)