Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(#8986) add api for getting single user #9016

Merged
merged 79 commits into from
Apr 23, 2024
Merged

Conversation

jkuester
Copy link
Contributor

@jkuester jkuester commented Apr 17, 2024

Description

Closes #8986
Docs PR: medic/cht-docs#1350

Code review checklist

  • Readable: Concise, well named, follows the style guide, documented if necessary.
  • Documented: Configuration and user documentation on cht-docs
  • Tested: Unit and/or e2e where appropriate
  • Backwards compatible: Works with existing data and configuration or includes a migration. Any breaking changes documented in the release notes.

Compose URLs

If Build CI hasn't passed, these may 404:

License

The software is provided under AGPL-3.0. Contributions to this project are accepted under the same license.

m5r and others added 30 commits March 13, 2024 17:53
@jkuester jkuester force-pushed the 8986-lookup-single-user branch from edf6d86 to de5846f Compare April 17, 2024 14:16
@jkuester jkuester changed the base branch from master to 8877-lookup-single-user April 17, 2024 14:17
@@ -3020,14 +3149,27 @@ describe('Users service', () => {
sinon.stub(roles, 'isOffline').returns(false);

const updates = { token_login: true, phone: '+40 755 89-89-89' };
db.medic.get.resolves({
db.medic.get.onFirstCall().resolves({
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This particular test had some very sketchy things happening behind the scenes due to some pass-by-reference effects. Basically, the asserts below were "working" because the arg objects were getting passed around and continued to be updated as the logic flow continued (because of the Object.assign calls in getUpdatedUserDoc and getUpdatedSettingsDoc). When I replaced the Object.assign calls by spreading the data into a new object, that broke this test.

However, I think the updated test code is more explicit and accurate anyway.

shared-libs/user-management/src/users.js Show resolved Hide resolved
api/src/controllers/users.js Outdated Show resolved Hide resolved
Base automatically changed from 8877-lookup-single-user to master April 18, 2024 14:33
# Conflicts:
#	api/tests/mocha/controllers/users.spec.js
#	shared-libs/user-management/src/users.js
#	shared-libs/user-management/test/unit/users.spec.js
@jkuester jkuester requested review from m5r and lorerod April 19, 2024 21:30
Copy link
Contributor

@lorerod lorerod left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, @jkuester and @m5r, for adding all the necessary tests to this implementation. The work looks fantastic.

Copy link
Member

@dianabarsan dianabarsan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work! I left some minor stylistic comments inline.

api/src/controllers/users.js Outdated Show resolved Hide resolved
api/tests/mocha/controllers/users.spec.js Show resolved Hide resolved
tests/integration/api/controllers/users.spec.js Outdated Show resolved Hide resolved
tests/integration/api/controllers/users.spec.js Outdated Show resolved Hide resolved
return;
}

expect.fail('Should have thrown an error');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you move this to the try block, after the await utils.request, you don't have to return in your catch.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, what I don't like about doing it that way is that the error generated by the fail gets caught in the catch block. Then, if request call does succeed and the expected error is not thrown, the test will fail, but it will fail with an error like "Expected: Failed to find user... but got Should have thrown an error". Not a huge thing, but can be a bit confusing when you go to start debugging.

This approach with the return is the most convenient I could think of, but open to other ideas!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's probably going to throw an error for cannot read properties of undefined (reading 'code') since the error being caught is destructured
The early return doesn't throw me off that much 😅

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I logically prefer expect.fail-ing withing the try block. when I read this code, I immediately know: oh, this request is supposed to fail, and I prepare my brain for "why is it supposed to fail" and "how does the error look like".

If I read the code the way it is now, top down, I see: oh, I'm OK with this request request not failing, but if it fails I run some assertions. Oh, I am not fine with this request failing.
If I read bottom up, I see an expect.fail at the end of the test and I think: oh, this is weird, so this test is not supposed to run until the end. Now I have to search for all the returns and throws within the test.

I totally understand that when reading error messages when the test fails, you get a prettier error message. My comment is about actually reading and understanding the test code.

This is pretty minor and I'm not having a super strong opinion about this, it's just a preference about what makes sense and is easiest to follow for me when I read code.

api/src/routing.js Dismissed Show dismissed Hide dismissed
@jkuester jkuester merged commit db531e1 into master Apr 23, 2024
34 checks passed
@jkuester jkuester deleted the 8986-lookup-single-user branch April 23, 2024 19:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

/api/v2/users look up data for single user
4 participants