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

Extract authentication logic to redux state #517

Merged
merged 10 commits into from
Aug 28, 2018

Conversation

migmartri
Copy link
Contributor

@migmartri migmartri commented Aug 22, 2018

First step wrt to the 401 error shown here #294

This patch sets the stage by extracting the authentication information to the Redux state instead of the local state of the login component. This will allow us to:

  • Monitor/ensure that authentications are being ran in sequential mode and there is trace for transient states.
  • Test the authentication steps at the action level instead of doing local try/catches. So this logic can be shared.
  • Future (next patch) will have a wrapper component that will "connect" to this global state.

This patch also adds some tests for the modified/added files as well as some related libraries for such tests.

NOTE: This patch removes the ability of closing the error message shown during login. I decided to do so for simplicity since now the state comes from the props and we will need to make local and external state to interact to make it work. Things that is possible but I do not think it's worth it more taking into account that with this change we will be able to use external libraries like https://tomchentw.github.io/react-toastr/ which handle all this for free.

TODO

  • Add reducer tests
  • Figure out mismatch with test snapshots

@@ -1,2401 +1,156 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
Copy link
Contributor

@andresmgot andresmgot Aug 22, 2018

Choose a reason for hiding this comment

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

I think I don't fully understand the purpose of snapshots. It seems that it's something that you just replace with the current state when it fails. Apparently it's not a very useful test. Am I missing something?

Copy link
Contributor

@andresmgot andresmgot left a comment

Choose a reason for hiding this comment

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

So far it looks good to me (apart from the CI error due to the snapshot)

Copy link
Contributor

@andresmgot andresmgot left a comment

Choose a reason for hiding this comment

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

For mi this looks good to be landed. We can send a different PR for the reducers (that none of them are covered right now)

@migmartri migmartri force-pushed the 294-authorization-errors branch from 0b5cd22 to d19ecbe Compare August 27, 2018 20:57
@migmartri migmartri changed the title WIP Extract authentication logic to redux state Extract authentication logic to redux state Aug 28, 2018
const token = "abcd";
const validationErrorMsg = "Validation error";

let store: any;
Copy link
Contributor

Choose a reason for hiding this comment

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

We should see if Partial<IStoreState> works here, if not we can try casting the mockStore thing to IStoreState


describe("LoginFormContainer props", () => {
it("maps authentication redux states to props", () => {
const store = makeStore(true, true, "It's a trap");
Copy link
Contributor

Choose a reason for hiding this comment

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

why not just pass the IAuthState object directly? not sure why this helper is valuable, it's also not easy to read what the first two parameters relate to

Copy link
Contributor

Choose a reason for hiding this comment

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

also, shouldn't we test different variations?

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 do not see much value on passing variations since the mapStateToProps just takes the values, there are not defaults or anything.

declare namespace JSX {
interface IntrinsicAttributes {
// Add store option for testing with mocked-store
store?: any;
Copy link
Contributor

Choose a reason for hiding this comment

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

again check if this can be IStoreState or Partial

expect(
authReducer(undefined, {
authenticated: e,
type: actionTypes.setAuthenticated as any,
Copy link
Contributor

Choose a reason for hiding this comment

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

add a TODO comment to figure out why we need any here

@migmartri migmartri merged commit c8b71c4 into vmware-tanzu:master Aug 28, 2018
@migmartri migmartri deleted the 294-authorization-errors branch August 28, 2018 17:36
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.

3 participants