From 91e40e6ff735bb8f94039c6cabfbf898a4914e16 Mon Sep 17 00:00:00 2001 From: Pham Hai Duong <tanphamhaiduong@gmail.com> Date: Thu, 13 Feb 2020 11:03:56 +0700 Subject: [PATCH] fix(cognito): #231 fix change password flow Replace the string 'coggnitoClientId' with the actual env in saga --- packages/marketplace/src/sagas/__tests__/settings.ts | 11 ++++------- packages/marketplace/src/sagas/settings.ts | 11 ++++------- .../marketplace/src/tests/badges/badge-branches.svg | 2 +- .../marketplace/src/tests/badges/badge-functions.svg | 2 +- packages/marketplace/src/tests/badges/badge-lines.svg | 2 +- .../marketplace/src/tests/badges/badge-statements.svg | 2 +- 6 files changed, 12 insertions(+), 18 deletions(-) diff --git a/packages/marketplace/src/sagas/__tests__/settings.ts b/packages/marketplace/src/sagas/__tests__/settings.ts index 902a664758..26054870a2 100644 --- a/packages/marketplace/src/sagas/__tests__/settings.ts +++ b/packages/marketplace/src/sagas/__tests__/settings.ts @@ -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') @@ -127,7 +125,7 @@ describe('settings', () => { password: '123', newPassword: '456', userName: 'abc@gmail.com', - cognitoClientId: 'cognitoClientId', + cognitoClientId: process.env.COGNITO_CLIENT_ID_MARKETPLACE || '', }), ) expect(clone.next('SUCCESS').value).toEqual( @@ -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) }) @@ -152,7 +149,7 @@ describe('settings', () => { password: '123', newPassword: '456', userName: 'abc@gmail.com', - cognitoClientId: 'cognitoClientId', + cognitoClientId: process.env.COGNITO_CLIENT_ID_MARKETPLACE || '', }), ) expect(clone.next('FAIL').value).toEqual( diff --git a/packages/marketplace/src/sagas/settings.ts b/packages/marketplace/src/sagas/settings.ts index 5fe79db17f..c9cdc3d0ca 100644 --- a/packages/marketplace/src/sagas/settings.ts +++ b/packages/marketplace/src/sagas/settings.ts @@ -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) => { @@ -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) { @@ -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( diff --git a/packages/marketplace/src/tests/badges/badge-branches.svg b/packages/marketplace/src/tests/badges/badge-branches.svg index dec4d9b200..4b904f4cde 100644 --- a/packages/marketplace/src/tests/badges/badge-branches.svg +++ b/packages/marketplace/src/tests/badges/badge-branches.svg @@ -1 +1 @@ -<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="170" height="20"><linearGradient id="b" x2="0" y2="100%"><stop offset="0" stop-color="#bbb" stop-opacity=".1"/><stop offset="1" stop-opacity=".1"/></linearGradient><clipPath id="a"><rect width="170" height="20" rx="3" fill="#fff"/></clipPath><g clip-path="url(#a)"><path fill="#555" d="M0 0h117v20H0z"/><path fill="#e05d44" d="M117 0h53v20H117z"/><path fill="url(#b)" d="M0 0h170v20H0z"/></g><g fill="#fff" text-anchor="middle" font-family="DejaVu Sans,Verdana,Geneva,sans-serif" font-size="110"> <text x="595" y="150" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="1070">Coverage:branches</text><text x="595" y="140" transform="scale(.1)" textLength="1070">Coverage:branches</text><text x="1425" y="150" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="430">70.44%</text><text x="1425" y="140" transform="scale(.1)" textLength="430">70.44%</text></g> </svg> \ No newline at end of file +<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="170" height="20"><linearGradient id="b" x2="0" y2="100%"><stop offset="0" stop-color="#bbb" stop-opacity=".1"/><stop offset="1" stop-opacity=".1"/></linearGradient><clipPath id="a"><rect width="170" height="20" rx="3" fill="#fff"/></clipPath><g clip-path="url(#a)"><path fill="#555" d="M0 0h117v20H0z"/><path fill="#e05d44" d="M117 0h53v20H117z"/><path fill="url(#b)" d="M0 0h170v20H0z"/></g><g fill="#fff" text-anchor="middle" font-family="DejaVu Sans,Verdana,Geneva,sans-serif" font-size="110"> <text x="595" y="150" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="1070">Coverage:branches</text><text x="595" y="140" transform="scale(.1)" textLength="1070">Coverage:branches</text><text x="1425" y="150" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="430">70.33%</text><text x="1425" y="140" transform="scale(.1)" textLength="430">70.33%</text></g> </svg> \ No newline at end of file diff --git a/packages/marketplace/src/tests/badges/badge-functions.svg b/packages/marketplace/src/tests/badges/badge-functions.svg index 3a4a5ae7d6..705469c2f5 100644 --- a/packages/marketplace/src/tests/badges/badge-functions.svg +++ b/packages/marketplace/src/tests/badges/badge-functions.svg @@ -1 +1 @@ -<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="170" height="20"><linearGradient id="b" x2="0" y2="100%"><stop offset="0" stop-color="#bbb" stop-opacity=".1"/><stop offset="1" stop-opacity=".1"/></linearGradient><clipPath id="a"><rect width="170" height="20" rx="3" fill="#fff"/></clipPath><g clip-path="url(#a)"><path fill="#555" d="M0 0h117v20H0z"/><path fill="#e05d44" d="M117 0h53v20H117z"/><path fill="url(#b)" d="M0 0h170v20H0z"/></g><g fill="#fff" text-anchor="middle" font-family="DejaVu Sans,Verdana,Geneva,sans-serif" font-size="110"> <text x="595" y="150" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="1070">Coverage:functions</text><text x="595" y="140" transform="scale(.1)" textLength="1070">Coverage:functions</text><text x="1425" y="150" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="430">73.68%</text><text x="1425" y="140" transform="scale(.1)" textLength="430">73.68%</text></g> </svg> \ No newline at end of file +<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="170" height="20"><linearGradient id="b" x2="0" y2="100%"><stop offset="0" stop-color="#bbb" stop-opacity=".1"/><stop offset="1" stop-opacity=".1"/></linearGradient><clipPath id="a"><rect width="170" height="20" rx="3" fill="#fff"/></clipPath><g clip-path="url(#a)"><path fill="#555" d="M0 0h117v20H0z"/><path fill="#e05d44" d="M117 0h53v20H117z"/><path fill="url(#b)" d="M0 0h170v20H0z"/></g><g fill="#fff" text-anchor="middle" font-family="DejaVu Sans,Verdana,Geneva,sans-serif" font-size="110"> <text x="595" y="150" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="1070">Coverage:functions</text><text x="595" y="140" transform="scale(.1)" textLength="1070">Coverage:functions</text><text x="1425" y="150" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="430">73.99%</text><text x="1425" y="140" transform="scale(.1)" textLength="430">73.99%</text></g> </svg> \ No newline at end of file diff --git a/packages/marketplace/src/tests/badges/badge-lines.svg b/packages/marketplace/src/tests/badges/badge-lines.svg index 408ba25be3..ca5fc4af90 100644 --- a/packages/marketplace/src/tests/badges/badge-lines.svg +++ b/packages/marketplace/src/tests/badges/badge-lines.svg @@ -1 +1 @@ -<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="146" height="20"><linearGradient id="b" x2="0" y2="100%"><stop offset="0" stop-color="#bbb" stop-opacity=".1"/><stop offset="1" stop-opacity=".1"/></linearGradient><clipPath id="a"><rect width="146" height="20" rx="3" fill="#fff"/></clipPath><g clip-path="url(#a)"><path fill="#555" d="M0 0h93v20H0z"/><path fill="#4c1" d="M93 0h53v20H93z"/><path fill="url(#b)" d="M0 0h146v20H0z"/></g><g fill="#fff" text-anchor="middle" font-family="DejaVu Sans,Verdana,Geneva,sans-serif" font-size="110"> <text x="475" y="150" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="830">Coverage:lines</text><text x="475" y="140" transform="scale(.1)" textLength="830">Coverage:lines</text><text x="1185" y="150" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="430">90.34%</text><text x="1185" y="140" transform="scale(.1)" textLength="430">90.34%</text></g> </svg> \ No newline at end of file +<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="146" height="20"><linearGradient id="b" x2="0" y2="100%"><stop offset="0" stop-color="#bbb" stop-opacity=".1"/><stop offset="1" stop-opacity=".1"/></linearGradient><clipPath id="a"><rect width="146" height="20" rx="3" fill="#fff"/></clipPath><g clip-path="url(#a)"><path fill="#555" d="M0 0h93v20H0z"/><path fill="#4c1" d="M93 0h53v20H93z"/><path fill="url(#b)" d="M0 0h146v20H0z"/></g><g fill="#fff" text-anchor="middle" font-family="DejaVu Sans,Verdana,Geneva,sans-serif" font-size="110"> <text x="475" y="150" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="830">Coverage:lines</text><text x="475" y="140" transform="scale(.1)" textLength="830">Coverage:lines</text><text x="1185" y="150" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="430">90.39%</text><text x="1185" y="140" transform="scale(.1)" textLength="430">90.39%</text></g> </svg> \ No newline at end of file diff --git a/packages/marketplace/src/tests/badges/badge-statements.svg b/packages/marketplace/src/tests/badges/badge-statements.svg index c90015f145..80713dab5d 100644 --- a/packages/marketplace/src/tests/badges/badge-statements.svg +++ b/packages/marketplace/src/tests/badges/badge-statements.svg @@ -1 +1 @@ -<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="182" height="20"><linearGradient id="b" x2="0" y2="100%"><stop offset="0" stop-color="#bbb" stop-opacity=".1"/><stop offset="1" stop-opacity=".1"/></linearGradient><clipPath id="a"><rect width="182" height="20" rx="3" fill="#fff"/></clipPath><g clip-path="url(#a)"><path fill="#555" d="M0 0h129v20H0z"/><path fill="#dfb317" d="M129 0h53v20H129z"/><path fill="url(#b)" d="M0 0h182v20H0z"/></g><g fill="#fff" text-anchor="middle" font-family="DejaVu Sans,Verdana,Geneva,sans-serif" font-size="110"> <text x="655" y="150" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="1190">Coverage:statements</text><text x="655" y="140" transform="scale(.1)" textLength="1190">Coverage:statements</text><text x="1545" y="150" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="430">89.51%</text><text x="1545" y="140" transform="scale(.1)" textLength="430">89.51%</text></g> </svg> \ No newline at end of file +<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="182" height="20"><linearGradient id="b" x2="0" y2="100%"><stop offset="0" stop-color="#bbb" stop-opacity=".1"/><stop offset="1" stop-opacity=".1"/></linearGradient><clipPath id="a"><rect width="182" height="20" rx="3" fill="#fff"/></clipPath><g clip-path="url(#a)"><path fill="#555" d="M0 0h129v20H0z"/><path fill="#dfb317" d="M129 0h53v20H129z"/><path fill="url(#b)" d="M0 0h182v20H0z"/></g><g fill="#fff" text-anchor="middle" font-family="DejaVu Sans,Verdana,Geneva,sans-serif" font-size="110"> <text x="655" y="150" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="1190">Coverage:statements</text><text x="655" y="140" transform="scale(.1)" textLength="1190">Coverage:statements</text><text x="1545" y="150" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="430">89.56%</text><text x="1545" y="140" transform="scale(.1)" textLength="430">89.56%</text></g> </svg> \ No newline at end of file