Skip to content

Commit

Permalink
fix(cognito): #231 fix change password flow (#265)
Browse files Browse the repository at this point in the history
Replace the string 'coggnitoClientId' with the actual env in saga
  • Loading branch information
duong-se authored and phmngocnghia committed Feb 14, 2020
1 parent 27f278a commit ac5c78b
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 18 deletions.
11 changes: 4 additions & 7 deletions packages/marketplace/src/sagas/__tests__/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ import errorMessages from '@/constants/error-messages'
import messages from '@/constants/messages'
import { developerStub } from '../__stubs__/developer'
import { removeSession, changePassword } from '@reapit/cognito-auth'
import { history } from '../../core/router'
import Routes from '@/constants/routes'
import { authLogoutSuccess } from '@/actions/auth'
import { authLogout } from '@/actions/auth'
import { showNotificationMessage } from '@/actions/notification-message'

jest.mock('@reapit/elements')
Expand Down Expand Up @@ -127,7 +125,7 @@ describe('settings', () => {
password: '123',
newPassword: '456',
userName: '[email protected]',
cognitoClientId: 'cognitoClientId',
cognitoClientId: process.env.COGNITO_CLIENT_ID_MARKETPLACE || '',
}),
)
expect(clone.next('SUCCESS').value).toEqual(
Expand All @@ -139,8 +137,7 @@ describe('settings', () => {
),
)
expect(clone.next().value).toEqual(call(removeSession))
expect(clone.next().value).toEqual(put(authLogoutSuccess()))
expect(clone.next().value).toEqual(history.replace(`${Routes.DEVELOPER_LOGIN}?isChangePasswordSuccess=1`))
expect(clone.next().value).toEqual(put(authLogout()))
expect(clone.next().value).toEqual(put(settingShowLoading(false)))
expect(clone.next().done).toEqual(true)
})
Expand All @@ -152,7 +149,7 @@ describe('settings', () => {
password: '123',
newPassword: '456',
userName: '[email protected]',
cognitoClientId: 'cognitoClientId',
cognitoClientId: process.env.COGNITO_CLIENT_ID_MARKETPLACE || '',
}),
)
expect(clone.next('FAIL').value).toEqual(
Expand Down
11 changes: 4 additions & 7 deletions packages/marketplace/src/sagas/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ import { errorThrownServer } from '@/actions/error'
import { showNotificationMessage } from '@/actions/notification-message'
import { DeveloperModel } from '@reapit/foundations-ts-definitions'
import { selectDeveloperId, selectDeveloperEmail } from '@/selector/developer'
import { authLogoutSuccess } from '@/actions/auth'
import Routes from '@/constants/routes'
import { history } from '../core/router'
import { authLogout } from '@/actions/auth'
import { logger } from 'logger'

export const fetchDeveloperInfo = async (developerId: string | null | undefined) => {
Expand Down Expand Up @@ -108,11 +106,12 @@ export const developerPasswordChange = function*({ data }: Action<ChangePassword
const email = yield select(selectDeveloperEmail)
/* rename for compatible reason */
const { currentPassword: password, password: newPassword } = data
const cognitoClientId = process.env.COGNITO_CLIENT_ID_MARKETPLACE || ''
const response = yield call(changePassword, {
userName: email,
password,
newPassword,
cognitoClientId: 'cognitoClientId',
cognitoClientId,
})
const isCallAPISuccess = response === 'SUCCESS'
if (!isCallAPISuccess) {
Expand All @@ -124,10 +123,8 @@ export const developerPasswordChange = function*({ data }: Action<ChangePassword
message: messages.CHANGE_SAVE_SUCCESSFULLY,
}),
)
const SUCCESS_ALERT_LOGIN_PAGE = `${Routes.DEVELOPER_LOGIN}?isChangePasswordSuccess=1`
yield call(removeSession)
yield put(authLogoutSuccess())
yield history.replace(SUCCESS_ALERT_LOGIN_PAGE)
yield put(authLogout())
} catch (error) {
logger(error)
yield put(
Expand Down
2 changes: 1 addition & 1 deletion packages/marketplace/src/tests/badges/badge-branches.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion packages/marketplace/src/tests/badges/badge-functions.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion packages/marketplace/src/tests/badges/badge-lines.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion packages/marketplace/src/tests/badges/badge-statements.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit ac5c78b

Please sign in to comment.