forked from carbon-design-system/carbon-for-ibm-dotcom
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(profile): update profile requx actions, types, and reducers namin…
…g and unit tests (carbon-design-system#4926) ### Related Ticket(s) Change profile endpoint on Carbon Masthead for signed in state carbon-design-system#4701 ### Description Update naming and unit tests from feedback: carbon-design-system#4909 ### Changelog **Changed** - update `getUserStatus` action to `loadUserStatus` in accordance to naming strategy - create `Unauthenticated` const in ProfileAPI type - use `request` instead of `status` for the `setRequestUserStatusInProgress` and `setUserStatus` actions <!-- React and Web Component deploy previews are enabled by default. --> <!-- To enable additional available deploy previews, apply the following --> <!-- labels for the corresponding package: --> <!-- *** "package: services": Services --> <!-- *** "package: utilities": Utilities --> <!-- *** "package: styles": Carbon Expressive --> <!-- *** "RTL": React / Web Components (RTL) --> <!-- *** "feature flag": React / Web Components (experimental) -->
- Loading branch information
1 parent
439df67
commit 2545a46
Showing
9 changed files
with
79 additions
and
64 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
|
@@ -10,10 +10,10 @@ | |
import configureMockStore from 'redux-mock-store'; | ||
import { AnyAction } from 'redux'; | ||
import thunk, { ThunkDispatch } from 'redux-thunk'; | ||
// import ProfileAPI from '@carbon/ibmdotcom-services/es/services/Profile/Profile.js'; | ||
import { PROFILE_API_ACTION, ProfileAPIState } from '../../types/profileAPI'; | ||
// import convertValue from '../../../tests/utils/convert-value'; | ||
import { setUserStatus } from '../profileAPI'; | ||
import ProfileAPI from '@carbon/ibmdotcom-services/es/services/Profile/Profile.js'; | ||
import { UNAUTHENTICATED_STATUS, PROFILE_API_ACTION, ProfileAPIState } from '../../types/profileAPI'; | ||
import convertValue from '../../../tests/utils/convert-value'; | ||
import { loadUserStatus, setUserStatus } from '../profileAPI'; | ||
|
||
jest.mock('@carbon/ibmdotcom-services/es/services/Profile/Profile'); | ||
|
||
|
@@ -29,38 +29,46 @@ describe('Redux actions for `ProfileAPI`', () => { | |
expect(store.getActions()).toEqual([ | ||
{ | ||
type: PROFILE_API_ACTION.SET_USER_STATUS, | ||
status: { user: '[email protected]' }, | ||
request: { user: '[email protected]' }, | ||
}, | ||
]); | ||
}); | ||
|
||
// it('dispatches the action to get user authentication status', async () => { | ||
// ProfileAPI.getUserStatus.mockResolvedValue({ user: 'Unauthenticated' }); | ||
// const store = mockStore(); | ||
// await store.dispatch(ProfileAPI.getUserStatus()); | ||
// expect(convertValue(store.getActions())).toEqual([ | ||
// { | ||
// type: PROFILE_API_ACTION.SET_REQUEST_USER_STATUS_IN_PROGRESS, | ||
// request: 'PROMISE', | ||
// }, | ||
// { | ||
// type: PROFILE_API_ACTION.SET_USER_STATUS, | ||
// status: { user: 'Unauthenticated' }, | ||
// }, | ||
// ]); | ||
// }); | ||
it('dispatches the action to get user authentication status', async () => { | ||
ProfileAPI.getUserStatus.mockResolvedValue({ user: UNAUTHENTICATED_STATUS }); | ||
const store = mockStore(); | ||
await store.dispatch(loadUserStatus()); | ||
expect(convertValue(store.getActions())).toEqual([ | ||
{ | ||
type: PROFILE_API_ACTION.SET_REQUEST_USER_STATUS_IN_PROGRESS, | ||
request: 'PROMISE', | ||
}, | ||
{ | ||
type: PROFILE_API_ACTION.SET_USER_STATUS, | ||
request: { user: UNAUTHENTICATED_STATUS }, | ||
}, | ||
]); | ||
}); | ||
|
||
// it('dispatches the action of error in monitoring user authentication status', () => { | ||
// ProfileAPI.getUserStatus.mockImplementation(callback => { | ||
// callback(new Error('error-getuserstatus')); | ||
// }); | ||
// const store = mockStore(); | ||
// store.dispatch(getUserStatus()); | ||
// expect(convertValue(store.getActions())).toEqual([ | ||
// { | ||
// type: PROFILE_API_ACTION.SET_ERROR_REQUEST_USER_STATUS, | ||
// error: 'error-getuserstatus', | ||
// }, | ||
// ]); | ||
// }); | ||
it('dispatches the action of error in monitoring user authentication status', async () => { | ||
ProfileAPI.getUserStatus.mockRejectedValue(new Error('error-getuserstatus')); | ||
const store = mockStore(); | ||
let caught; | ||
try { | ||
await store.dispatch(loadUserStatus()); | ||
} catch (error) { | ||
caught = error; | ||
} | ||
expect(caught?.message).toBe('error-getuserstatus'); | ||
expect(convertValue(store.getActions())).toEqual([ | ||
{ | ||
type: PROFILE_API_ACTION.SET_REQUEST_USER_STATUS_IN_PROGRESS, | ||
request: 'PROMISE', | ||
}, | ||
{ | ||
type: PROFILE_API_ACTION.SET_ERROR_REQUEST_USER_STATUS, | ||
error: 'error-getuserstatus', | ||
}, | ||
]); | ||
}); | ||
}); |
This file contains 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 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 |
---|---|---|
|
@@ -14,7 +14,7 @@ import reducer from '../profileAPI'; | |
|
||
describe('Redux reducers for `ProfileAPI`', () => { | ||
it('should return the state unmodified for unknown action', () => { | ||
const state = { status: { user: '[email protected]' } }; | ||
const state = { request: { user: '[email protected]' } }; | ||
expect(reducer(state, {} as ProfileAPIActions)).toEqual(state); | ||
}); | ||
|
||
|
@@ -36,11 +36,11 @@ describe('Redux reducers for `ProfileAPI`', () => { | |
convertValue( | ||
reducer({} as ProfileAPIState, { | ||
type: PROFILE_API_ACTION.SET_USER_STATUS, | ||
status: { user: '[email protected]' }, | ||
request: { user: '[email protected]' }, | ||
}) | ||
) | ||
).toEqual({ | ||
status: { user: '[email protected]' }, | ||
request: { user: '[email protected]' }, | ||
}); | ||
}); | ||
}); |
This file contains 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 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 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 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 |
---|---|---|
|
@@ -18,12 +18,13 @@ import DDSLeftNav from '../left-nav'; | |
import '../masthead-container'; | ||
import styles from './masthead.stories.scss'; | ||
import { mastheadLinks as links, l1Data, logoData } from './links'; | ||
import { UNAUTHENTICATED_STATUS } from '../../../internal/vendor/@carbon/ibmdotcom-services-store/types/profileAPI'; | ||
import { authenticatedProfileItems, unauthenticatedProfileItems } from './profile-items'; | ||
import readme from './README.stories.mdx'; | ||
|
||
const userStatuses = { | ||
[`Authenticated`]: '[email protected]', | ||
[`Unauthenticated`]: 'Unauthenticated', | ||
[`Unauthenticated`]: UNAUTHENTICATED_STATUS, | ||
}; | ||
|
||
const StoryContent = () => html` | ||
|
This file contains 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 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