grist-core
grist-core copied to clipboard
Add tests for UsersManager
Context
HomeDBManager lacks of direct tests, which makes hard to make rework or refactorations.
Proposed solution
Specifically here, I introduce tests which call exposed UsersManager methods directly and check their result.
Also:
- I removed
updateUserNamewhich seems to me useless (updateUserdoes the same work) - Taking a look at the
getUserByLoginmethods, it appears that Typescirpt infers it returns aPromise<User|null>while in no case it may resolve a nullish value, therefore I have forced to return aPromise<User>and have changed the call sites to reflect the change.
Related issues
I make this change for then working on #870
Has this been tested?
- [x] 👍 yes, I added tests to the test suite
- [ ] 💭 no, because this PR is a draft and still needs work
- [ ] 🙅 no, because this is not relevant here
- [ ] 🙋 no, because I need help
@berhalak I think of something: my test assume that they run using Sqlite.
Several questions come to my mind:
- Can running these tests with Postgresql be worth?
- If so: I don't see tests running with Postgresql on the CI, I can take a look to see how hard it is to support this database.
- If not: I propose to skip these tests when
TYPEORM_TYPEis set topostgresql
To the first question, my answer would be no, the UsersManager uses a lot of TypeORM methods, and does not seem to make SQL query directly (but I may be a bit biased by my lazyness).
- Can running these tests with Postgresql be worth?
We run some tests with Postgresql in our internal CI, but since it is not part of the grist-core yet, and those tests are rather unit tests, I think it is fine to rely on typeorm abstraction.
I'm seeing failures in tests after UsersManager in a derived version of Grist (the one for our SaaS). Haven't looked into why yet, and may be specific to us.
Thank you @paulfitz!