-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Chore: Migrate redux module login to typescript #3647
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
Merged
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
22feb7b
chore: migrate redux module login to typescript
dnlsilva f1f5a92
Merge branch 'develop' into chore/migrate-ts-redux-login
dnlsilva 17ebeb7
update workers
dnlsilva a529e8b
wip
dnlsilva c5c9765
Merge branch 'develop' into chore/migrate-ts-redux-login
dnlsilva ee9a57f
fix type
dnlsilva b1605a0
remove partial
dnlsilva 0249d1d
add more status
dnlsilva 839f406
migrate the rest of the stuff to typescript
dnlsilva 7b69a7b
Merge branch 'develop' into chore/migrate-ts-redux-login
dnlsilva e1e1312
Merge branch 'develop' into chore/migrate-ts-redux-login
dnlsilva 3588caf
fix tests and types
dnlsilva df69c3a
Merge branch 'develop' into chore/migrate-ts-redux-login
dnlsilva 4dec86d
Merge branch 'develop' into chore/migrate-ts-redux-login
dnlsilva 3cf12fe
Merge branch 'develop' into chore/migrate-ts-redux-login
dnlsilva d931685
fix types and tests
dnlsilva e297ae2
Merge branch 'develop' into chore/migrate-ts-redux-login
dnlsilva cc8f684
Merge branch 'develop' into chore/migrate-ts-redux-login
dnlsilva File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,115 @@ | ||
| import { Action } from 'redux'; | ||
|
|
||
| import { IUser } from '../definitions'; | ||
| import * as types from './actionsTypes'; | ||
|
|
||
| interface ICredentials { | ||
| resume: string; | ||
| user: string; | ||
| password: string; | ||
| } | ||
|
|
||
| interface ILoginRequest extends Action { | ||
| credentials: any; | ||
| logoutOnError?: boolean; | ||
| isFromWebView?: boolean; | ||
| } | ||
|
|
||
| interface ILoginSuccess extends Action { | ||
| user: Partial<IUser>; | ||
| } | ||
|
|
||
| interface ILoginFailure extends Action { | ||
| err: Partial<IUser>; | ||
| } | ||
|
|
||
| interface ILogout extends Action { | ||
| forcedByServer: boolean; | ||
| } | ||
|
|
||
| interface ISetUser extends Action { | ||
| user: Partial<IUser>; | ||
| } | ||
|
|
||
| interface ISetServices extends Action { | ||
| data: Record<string, string>; | ||
| } | ||
|
|
||
| interface ISetPreference extends Action { | ||
| preference: Record<string, any>; | ||
| } | ||
|
|
||
| interface ISetLocalAuthenticated extends Action { | ||
| isLocalAuthenticated: boolean; | ||
| } | ||
|
|
||
| export type TActionsLogin = ILoginRequest & | ||
| ILoginSuccess & | ||
| ILoginFailure & | ||
| ILogout & | ||
| ISetUser & | ||
| ISetServices & | ||
| ISetPreference & | ||
| ISetLocalAuthenticated; | ||
|
|
||
| export function loginRequest( | ||
| credentials: Partial<ICredentials>, | ||
| logoutOnError?: boolean, | ||
| isFromWebView?: boolean | ||
| ): ILoginRequest { | ||
| return { | ||
| type: types.LOGIN.REQUEST, | ||
| credentials, | ||
| logoutOnError, | ||
| isFromWebView | ||
| }; | ||
| } | ||
|
|
||
| export function loginSuccess(user: Partial<IUser>): ILoginSuccess { | ||
| return { | ||
| type: types.LOGIN.SUCCESS, | ||
| user | ||
| }; | ||
| } | ||
|
|
||
| export function loginFailure(err: Record<string, any>): ILoginFailure { | ||
| return { | ||
| type: types.LOGIN.FAILURE, | ||
| err | ||
| }; | ||
| } | ||
|
|
||
| export function logout(forcedByServer = false): ILogout { | ||
| return { | ||
| type: types.LOGOUT, | ||
| forcedByServer | ||
| }; | ||
| } | ||
|
|
||
| export function setUser(user: Partial<IUser>): ISetUser { | ||
| return { | ||
| type: types.USER.SET, | ||
| user | ||
| }; | ||
| } | ||
|
|
||
| export function setLoginServices(data: Record<string, any>): ISetServices { | ||
| return { | ||
| type: types.LOGIN.SET_SERVICES, | ||
| data | ||
| }; | ||
| } | ||
|
|
||
| export function setPreference(preference: Record<string, any>): ISetPreference { | ||
| return { | ||
| type: types.LOGIN.SET_PREFERENCE, | ||
| preference | ||
| }; | ||
| } | ||
|
|
||
| export function setLocalAuthenticated(isLocalAuthenticated: boolean): ISetLocalAuthenticated { | ||
| return { | ||
| type: types.LOGIN.SET_LOCAL_AUTHENTICATED, | ||
| isLocalAuthenticated | ||
| }; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,109 @@ | ||
| import { | ||
| loginFailure, | ||
| loginRequest, | ||
| loginSuccess, | ||
| logout, | ||
| setLocalAuthenticated, | ||
| setLoginServices, | ||
| setUser | ||
| } from '../actions/login'; | ||
| import { UserStatus } from '../definitions/UserStatus'; | ||
| import { initialState } from './login'; | ||
| import { mockedStore } from './mockedStore'; | ||
|
|
||
| describe('test selectedUsers reducer', () => { | ||
| it('should return initial state', () => { | ||
| const state = mockedStore.getState().login; | ||
| expect(state).toEqual(initialState); | ||
| }); | ||
|
|
||
| it('should return modified store after loginRequest', () => { | ||
| mockedStore.dispatch(loginRequest({ user: 'carlitos@email.com', password: '123456' })); | ||
| const state = mockedStore.getState().login; | ||
| expect(state).toEqual({ ...initialState, isFetching: true, isAuthenticated: false, failure: false, error: {} }); | ||
| }); | ||
|
|
||
| it('should return modified store after loginFailure', () => { | ||
| mockedStore.dispatch(loginFailure({ error: 'error' })); | ||
| const state = mockedStore.getState().login.error.error; | ||
| expect(state).toEqual('error'); | ||
| }); | ||
|
|
||
| it('should return modified store after loginSuccess', () => { | ||
| const user = { | ||
| id: 'ajhsiahsa', | ||
| token: 'asdasdasdas', | ||
| username: 'carlitos', | ||
| name: 'Carlitos', | ||
| customFields: { | ||
| phonenumber: '' | ||
| }, | ||
| emails: [ | ||
| { | ||
| address: 'carlitos@email.com', | ||
| verified: true | ||
| } | ||
| ], | ||
| roles: ['user'], | ||
| isFromWebView: false, | ||
| showMessageInMainThread: false, | ||
| enableMessageParserEarlyAdoption: false, | ||
| status: UserStatus.ONLINE, | ||
| statusText: 'online' | ||
| }; | ||
| mockedStore.dispatch(loginSuccess(user)); | ||
| const state = mockedStore.getState().login.user; | ||
| expect(state).toEqual(user); | ||
| }); | ||
|
|
||
| it('should return modified store after setUser', () => { | ||
| const user = { | ||
| id: 'ajhsiahsa', | ||
| token: 'asdasdasdas', | ||
| username: 'carlito', | ||
| name: 'Carlitos', | ||
| customFields: { | ||
| phonenumber: '' | ||
| }, | ||
| emails: [ | ||
| { | ||
| address: 'carlitos@email.com', | ||
| verified: true | ||
| } | ||
| ], | ||
| roles: ['user'], | ||
| isFromWebView: false, | ||
| showMessageInMainThread: false, | ||
| enableMessageParserEarlyAdoption: false | ||
| }; | ||
| mockedStore.dispatch(setUser(user)); | ||
| const state = mockedStore.getState().login.user.username; | ||
| expect(state).toEqual(user.username); | ||
| }); | ||
|
|
||
| // TODO PREFERENCE REDUCER WITH EMPTY PREFERENCE - NON USED? | ||
| // it('should return modified store after setPreference', () => { | ||
| // mockedStore.dispatch(setPreference({ showAvatar: true })); | ||
| // const state = mockedStore.getState().login; | ||
| // console.log(state); | ||
| // expect(state).toEqual('error'); | ||
| // }); | ||
|
|
||
| it('should return modified store after setLocalAuthenticated', () => { | ||
| mockedStore.dispatch(setLocalAuthenticated(true)); | ||
| const state = mockedStore.getState().login.isLocalAuthenticated; | ||
| expect(state).toEqual(true); | ||
| }); | ||
|
|
||
| it('should return modified store after setLoginServices', () => { | ||
| mockedStore.dispatch(setLoginServices({ facebook: { clientId: 'xxx' } })); | ||
| const state = mockedStore.getState().login.services.facebook.clientId; | ||
| expect(state).toEqual('xxx'); | ||
| }); | ||
|
|
||
| it('should return modified store after logout', () => { | ||
| mockedStore.dispatch(logout()); | ||
| const state = mockedStore.getState().login; | ||
| expect(state).toEqual(initialState); | ||
| }); | ||
| }); | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
whats wrong here? Is missing something or we can remove this block of code?
If I can help with anything, just let me know
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 action doesn't work, but I'm not sure if it's because at login this object is set or if it doesn't work at all.