-
Notifications
You must be signed in to change notification settings - Fork 4
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
[DCJ-260][risk=no] Converted User.js -> User.ts #2557
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks reasonable minus tests.
| 'Alumni' | ||
| 'SigningOfficial' | ||
| 'DataSubmitter' | ||
| 'All'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Technically, we don't have a back end role for 'All'
, but it might be helpful in this context if all means
Any role is allowed to access this resource
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good besides tests & two possible changes 👍
// We should not be updating the user's create date, associated institution, or library cards | ||
// This below code does not seem to work at all and | ||
// does not seem appropriate for this request anyway. | ||
// The UpdateDuosUserRequestV2 is not the same shape as a DuosUser | ||
// like this flow suggests. | ||
const filteredUser = flow( | ||
cloneDeep, | ||
unset('updatedUser.createDate'), | ||
unset('updatedUser.institution'), | ||
unset('updatedUser.libraryCards') | ||
)(user); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems to be a relic of an older implementation of this API. I don't think it is within the scope of this ticket to update/remove this logic, however, I did want to check with the team about this before spinning it off into its own ticket
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To be more specific (and I can add this to the comment directly if desired), these unset calls do not in fact unset those properties but the payload being used in the update request does not have those fields anyway.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is an artifact of the older API. The latest version accepts a limited number of fields that can be updated as per the API docs. I think it is appropriate to leave this logic as is and we can address it in a future ticket.
if (res.ok) { | ||
return res.json(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wanted to make a callout here. This previously read return res.json
without the parentheses and Typescript helped me catch that. There is only one place this method is used and it is being used as a truthy value so I don't believe this should change any behavior.
Regardless, I just wanted to make reviewers aware since it is not clear at all from the diff.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is fine, but it might be redundant if fetchOk
fails on a non-OK response. There could be descendant code that also handles the non-OK case in a particular manner, for example, showing a custom error response depending on what res.json()
does or does not contain.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just to clarify - I don't see any issues with moving from res.json
-> res.json()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think ultimately, we should change all these fetchOk
s to use axios instead. I think it would be wise to have a consistent way of making these requests and if we decide to do any handling of errors, they should happen outside of these ajax calls
const url = `${await getApiUrl()}/api/user`; | ||
// We should not be updating the user's create date, associated institution, or library cards |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that this is currently broken in dev: https://broadworkbench.atlassian.net/browse/DCJ-362
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tested this locally, no regressions. Code looks good, test coverage also looks good 👍🏽 Consider inline comments optional.
}); | ||
}); | ||
|
||
//TODO |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this still relevant?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope, missed that one 👍
await User.list('Admin'); | ||
} catch (err) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need anything before the catch to ensure that we actually did hit the assert in the catch block? This pattern does test as expected, so I'm fine with this as is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a good point, I'll put some assert(false)
s after the ajax calls before the catch block to make sure it fails if it does not throw for some reason
fb56b8d
to
1706c68
Compare
d6b0951
to
c4151cf
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approved after tests pass.
9a7be80
to
270a020
Compare
Addresses
https://broadworkbench.atlassian.net/browse/DCJ-260 Typescript Conversion
https://broadworkbench.atlassian.net/browse/DCJ-332 Unit testsMoved to #2610Summary
Adds Tests for User methods.