grist-core icon indicating copy to clipboard operation
grist-core copied to clipboard

Add tests for UsersManager

Open fflorent opened this issue 1 year ago • 3 comments

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 updateUserName which seems to me useless (updateUser does the same work)
  • Taking a look at the getUserByLogin methods, it appears that Typescirpt infers it returns a Promise<User|null> while in no case it may resolve a nullish value, therefore I have forced to return a Promise<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

fflorent avatar Aug 05 '24 16:08 fflorent

@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_TYPE is set to postgresql

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).

fflorent avatar Aug 16 '24 14:08 fflorent

  • 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.

berhalak avatar Aug 23 '24 09:08 berhalak

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.

Screenshot from 2024-08-23 12-19-34

paulfitz avatar Aug 23 '24 16:08 paulfitz

Thank you @paulfitz!

fflorent avatar Sep 05 '24 20:09 fflorent