oneuptime icon indicating copy to clipboard operation
oneuptime copied to clipboard

Adds tests for Common/Types/Database

Open koox00 opened this issue 2 years ago • 1 comments

Adds tests for Common/Types/Database.

Adds new tests for some of the files in Common/Types/Database directory. Refactored one test (ColumnLength) to increase test coverage and simplicity.

Upon writing the tests I noticed a couple of issues.

  1. IsPermissionsIf decorator didn't seem to set the property due to the initial property value in the BaseModel, at least upon testing. Moved the initialization to the constructor and to set only if there isn't a value, to fix this.
  2. Classes that extend CompareBase, AKA classes that take either a number or a Date as value, "fail" serialization and de-serialization. The value in the end object ends up a string. This commit attempts to fix that as well.

PS: I used Date.toJSON() as it is the method that JSON.stringify would call on a date.

Pull Request Checklist:

  • [x] Please make sure all jobs pass before requesting a review.
  • [ ] Put closes #XXXX in your comment to auto-close the issue that your PR fixes (if such).
  • [x] Have you lint your code locally before submission?
  • [x] Did you write tests where appropriate?

Related Issue

#210

koox00 avatar Nov 15 '23 16:11 koox00

@simlarsen it might be a better handling for parsing values that are number | Date. Instead of handling this individually we could use the "reviver" function of JSON.parse and parse date strings to dates once, wdyt?

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse#the_reviver_parameter

koox00 avatar Nov 15 '23 17:11 koox00