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.
Related issue
Closes #1068
Context / Background
A user can import a database which has an array of empty values, and the overall balance incorrectly updates. When importing a database, I expected that the app would check for an array of empty values before validating, and fail if there is no values in the database file. And even if the app should accept empty values, the overall time balance shouldn't be affected since there is no times entered.
What change is being introduced by this PR?
I thought about what has to be changed in the logic of the
validEntry
function in theimport-export.js
file so that users can't upload an empty database file which automatically would fix the issue of seeing an incorrect balance update.I have added a check for an array of empty values before validating. The user can now only import a database which actually has values.
The function's update ensures data validation by rejecting entries with empty value arrays, maintaining data integrity. This change also indirectly prevents errors in other application parts relying on entries with at least one time value, thus avoiding potential inaccuracies or failures in calculations.
How will this be tested?
After running the Time To Leave App, a user will not be able to import an empty database. To test this, create a
testdb.ttldb
file with the contents:[ { "type": "flexible", "date": "2023-05-21", "values": [] } ]
After attempting to import the file, the app should say: