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

refactor(auth.client.service): refactor to Typescript #2132

Merged
merged 33 commits into from Jun 10, 2021

Conversation

karrui
Copy link
Contributor

@karrui karrui commented Jun 10, 2021

Problem

This PR is the base of the feature to prevent merge/rebase hell.

Original chain: sendOtp <--- verifyOtp <-- fetchUser <- logout <-- getUserFromLocalStorage

Closes #2057

Solution

Breaking Changes

  • Yes - this PR contains breaking changes
  • No - this PR is backwards compatible

Features:

  • feat(AuthService): add verifyLoginOtp fn
  • ref(AuthService): move User related fns to UserService
  • ref: rename Admin prefix to User prefix to better fit the backend API
  • feat(UserService): add fetchUser function
  • use new fetchUser function
  • remove old unused refreshUser function
  • feat(AuthService): add and use logout function
  • feat(UserService): add clearUserFromLocalStorage fn
  • feat(UserService): add getUserFromLocalStorage function
  • ref: replace all instances of Auth.getUser with UserService equivalent
  • feat: delete (now) unused auth.client.service.js

Tests

All unit tests for refactored functions have been added as per their individual PRs.

Manual Tests

  • Reach verify OTP flow. Invalid OTP should be rejected. Valid OTP should succeed
  • On successful log in, the user object should be stored in localStorage
  • Chrome network tab. Open dropdown avatar. The call should succeed and return the current user. Localstorage should also be replaced (or unchanged)
  • Logout from the app. The user item from localStorage should be cleared and you should be kicked out to the login page.
  • Open avatar dropdown. Should load current user successfully.
  • Open edit contact number modal. Should load current user successfully.
  • Look at Google Analytics when you have downloaded a storage mode form responses. The label should be ${params.formTitle} (${params.formId}), ${<your email>}
  • In your admin form, go to the share form page. There should be a "use go link" lightbulb tooltip thingy
  • Should be able to successfully view admin form page (of your form) when logged in
  • Should be able to successfully view the edit form field modal successfully when logged in
  • Should be able to view form dashboard successfully when logged in
  • Should be able to view form settings successfully when logged in
  • Should be able to view examples page successfully when logged in
  • Should be able to view billing page successfully when logged in
  • In an admin form page, delete the user object from localStorage.
    • Should be logged out and redirected to the login page
    • After login, should be redirected back to the admin form page where you deleted the localStorage user.

Deploy Notes

New dependencies:

  • moved date-fns from devDependencies to dependencies

New dev dependencies:

  • jest-localstorage-mock: mock localstorage in frontend jest tests

karrui added 30 commits June 9, 2021 14:52
better fit API prefix
for mocking localstorage in the frontend jest tests
in preparation for extending from to close #2066
test(UserService): add tests for clearUserFromLocalStorage
…ervice-ts

refactor(auth.client): (2) extract verify otp flow to Typescript
refactor(auth.client): (3) extract fetch user service function to Typescript
refactor(auth.client): (4) extract admin logout service function to Typescript
i didn't even touch this part of the code...
refactor(auth.client): (5, final) extract get current logged in user service function to Typescript
# Conflicts:
#	package.json
#	src/public/modules/core/components/avatar-dropdown.client.component.js
@karrui karrui requested a review from mantariksh June 10, 2021 06:21
Copy link
Contributor

@mantariksh mantariksh left a comment

Choose a reason for hiding this comment

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

noted the use of truser in the commits

@karrui karrui merged commit 27180ff into develop Jun 10, 2021
@karrui karrui deleted the feat/authsvc-ts-base branch June 10, 2021 07:14
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.

Migrate auth.client.service.js to TypeScript
2 participants