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

[DCJ-260][risk=no] Converted User.js -> User.ts #2557

Merged
merged 12 commits into from
Jul 1, 2024

Conversation

sjkobori
Copy link
Contributor

@sjkobori sjkobori commented Apr 29, 2024

Addresses

https://broadworkbench.atlassian.net/browse/DCJ-260 Typescript Conversion
https://broadworkbench.atlassian.net/browse/DCJ-332 Unit tests Moved to #2610

Summary

  • Converts User.js to TypeScript as well as their corresponding types.
  • Adds Tests for User methods.

@sjkobori sjkobori requested a review from a team as a code owner April 29, 2024 18:10
@sjkobori sjkobori requested review from fboulnois and aarohinadkarni and removed request for a team April 29, 2024 18:10
Copy link
Contributor

@fboulnois fboulnois left a 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';
Copy link
Contributor

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

Copy link
Contributor

@aarohinadkarni aarohinadkarni left a 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 👍

@sjkobori sjkobori changed the title [DCJ-260] Converted User.js -> User.ts [DCJ-260][DCJ-332][risk=no] Converted User.js -> User.ts May 14, 2024
Comment on lines +70 to +80
// 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);
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 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

Copy link
Contributor Author

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.

Copy link
Contributor

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.

Comment on lines +40 to +42
if (res.ok) {
return res.json();
}
Copy link
Contributor Author

@sjkobori sjkobori May 14, 2024

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.

Copy link
Contributor

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.

Copy link
Contributor

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

Copy link
Contributor Author

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 fetchOks 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

Comment on lines +49 to +50
const url = `${await getApiUrl()}/api/user`;
// We should not be updating the user's create date, associated institution, or library cards
Copy link
Contributor

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

Copy link
Contributor

@rushtong rushtong left a 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
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this still relevant?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nope, missed that one 👍

Comment on lines 188 to 192
await User.list('Admin');
} catch (err) {
Copy link
Contributor

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.

Copy link
Contributor Author

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

@sjkobori sjkobori force-pushed the DCJ-260-duos-ui-User-module-to-typescript branch 2 times, most recently from fb56b8d to 1706c68 Compare May 14, 2024 22:26
@sjkobori sjkobori force-pushed the DCJ-260-duos-ui-User-module-to-typescript branch from d6b0951 to c4151cf Compare May 15, 2024 01:49
Copy link
Contributor

@fboulnois fboulnois left a 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.

@sjkobori sjkobori changed the title [DCJ-260][DCJ-332][risk=no] Converted User.js -> User.ts [DCJ-260][risk=no] Converted User.js -> User.ts Jun 25, 2024
@sjkobori sjkobori marked this pull request as draft June 27, 2024 20:00
@sjkobori sjkobori marked this pull request as ready for review June 27, 2024 20:00
Revert "Synced package-lock.json"

This reverts commit c4059ec.

Added unedited package-lock.json

Revert "Added unedited package-lock.json"

This reverts commit 8aef944.

Manual sync of package-lock.json

Fixed some typos from manual correction
@sjkobori sjkobori force-pushed the DCJ-260-duos-ui-User-module-to-typescript branch from 9a7be80 to 270a020 Compare July 1, 2024 02:42
@sjkobori sjkobori merged commit 2159399 into develop Jul 1, 2024
9 checks passed
@sjkobori sjkobori deleted the DCJ-260-duos-ui-User-module-to-typescript branch July 1, 2024 02:51
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.

4 participants