From b6f9a3a3f397ded2acaa70f8ac6ef3d621bdb054 Mon Sep 17 00:00:00 2001 From: Luis Deschamps Rudge Date: Tue, 19 Jun 2018 14:39:11 -0300 Subject: [PATCH 1/2] Fix SSO screen not appearing in reset password screen --- src/__tests__/connection/database/index.test.js | 8 +++++++- src/__tests__/connection/database/reset_password.test.jsx | 5 ++++- src/connection/database/index.js | 6 ++++-- src/connection/database/reset_password.jsx | 2 +- 4 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/__tests__/connection/database/index.test.js b/src/__tests__/connection/database/index.test.js index cf5ed31fb..d609d659e 100644 --- a/src/__tests__/connection/database/index.test.js +++ b/src/__tests__/connection/database/index.test.js @@ -40,9 +40,15 @@ describe('databaseUsernameValue', () => { describe('for database connection with username required', () => { const model = getModel('user@contoso.com', 'user', true); - it('should get the username', () => { + it('should get the username when `emailFirst` is not set', () => { expect(databaseUsernameValue(model)).toEqual('user'); }); + it('should get the username when `emailFirst` is false', () => { + expect(databaseUsernameValue(model, { emailFirst: false })).toEqual('user'); + }); + it('should get the email when `emailFirst` is true', () => { + expect(databaseUsernameValue(model, { emailFirst: true })).toEqual('user@contoso.com'); + }); describe('and only email address is filled in', () => { const model = getModel('user@contoso.com', null, true); diff --git a/src/__tests__/connection/database/reset_password.test.jsx b/src/__tests__/connection/database/reset_password.test.jsx index 2aa732c87..16e4e8c8d 100644 --- a/src/__tests__/connection/database/reset_password.test.jsx +++ b/src/__tests__/connection/database/reset_password.test.jsx @@ -11,7 +11,10 @@ describe('ResetPasswordScreen', () => { jest.resetModules(); jest.mock('connection/database/index', () => ({ - databaseUsernameValue: () => 'foo@test.com' + databaseUsernameValue: (model, options) => { + expect(options.emailFirst).toBe(true); + return 'foo@test.com'; + } })); jest.mock('connection/enterprise', () => ({ diff --git a/src/connection/database/index.js b/src/connection/database/index.js index c9d3ea5c6..f161a2466 100644 --- a/src/connection/database/index.js +++ b/src/connection/database/index.js @@ -353,12 +353,14 @@ export function databaseLogInWithEmail(m) { return databaseUsernameStyle(m) === 'email'; } -export function databaseUsernameValue(m) { +export function databaseUsernameValue(m, options = {}) { const isEmailOnly = databaseLogInWithEmail(m); if (isEmailOnly) { return getFieldValue(m, 'email'); } - + if (options.emailFirst) { + return getFieldValue(m, 'email') || getFieldValue(m, 'username'); + } return getFieldValue(m, 'username') || getFieldValue(m, 'email'); } diff --git a/src/connection/database/reset_password.jsx b/src/connection/database/reset_password.jsx index fab502db5..bd81e3f56 100644 --- a/src/connection/database/reset_password.jsx +++ b/src/connection/database/reset_password.jsx @@ -43,7 +43,7 @@ export default class ResetPassword extends Screen { isSubmitDisabled(m) { const tryingToResetPasswordWithEnterpriseEmail = isEnterpriseDomain( m, - databaseUsernameValue(m) + databaseUsernameValue(m, { emailFirst: true }) ); if (tryingToResetPasswordWithEnterpriseEmail) { swap( From bacff428f59d3cb07c01326b45cacac23b3da34a Mon Sep 17 00:00:00 2001 From: Luis Deschamps Rudge Date: Tue, 19 Jun 2018 14:39:34 -0300 Subject: [PATCH 2/2] Fix SSO screen not showing when trying to signup --- .../engine/classic/sign_up_screen.test.jsx | 30 ++++++++++++++++--- src/engine/classic.js | 4 +-- src/engine/classic/sign_up_screen.jsx | 9 +++--- 3 files changed, 33 insertions(+), 10 deletions(-) diff --git a/src/__tests__/engine/classic/sign_up_screen.test.jsx b/src/__tests__/engine/classic/sign_up_screen.test.jsx index 8c9f28a25..fd3ea1f49 100644 --- a/src/__tests__/engine/classic/sign_up_screen.test.jsx +++ b/src/__tests__/engine/classic/sign_up_screen.test.jsx @@ -12,10 +12,13 @@ jest.mock('connection/enterprise/single_sign_on_notice', () => mockComponent('single_sign_on_notice') ); -const getComponent = () => { +const getScreen = () => { const SignUpScreen = require('engine/classic/sign_up_screen').default; - const screen = new SignUpScreen(); - return screen.render(); + return new SignUpScreen(); +}; + +const getComponent = () => { + return getScreen().render(); }; describe('SignUpScreen', () => { @@ -23,6 +26,10 @@ describe('SignUpScreen', () => { jest.resetModules(); jest.mock('connection/database/index', () => ({ + databaseUsernameValue: (model, options) => { + expect(options.emailFirst).toBe(true); + return 'foo@bar.com'; + }, termsAccepted: () => true, hasScreen: () => false, mustAcceptTerms: () => false @@ -34,7 +41,10 @@ describe('SignUpScreen', () => { })); jest.mock('engine/classic', () => ({ hasOnlyClassicConnections: () => false, - isSSOEnabled: () => false, + isSSOEnabled: (model, options) => { + expect(options.emailFirst).toBe(true); + return false; + }, useBigSocialButtons: () => false })); jest.mock('core/signed_in_confirmation', () => ({ @@ -48,6 +58,10 @@ describe('SignUpScreen', () => { renderOptionSelection: () => false })); + jest.mock('connection/enterprise', () => ({ + isHRDDomain: () => false + })); + jest.mock('connection/enterprise/actions', () => ({ logIn: jest.fn() })); @@ -113,4 +127,12 @@ describe('SignUpScreen', () => { expectComponent().toMatchSnapshot(); }); }); + describe('on Submit, uses `options.emailFirst=true` and', () => { + it('calls signup', () => { + const screen = getScreen(); + screen.submitHandler()(); + const { mock } = require('connection/database/actions').signUp; + expect(mock.calls.length).toBe(1); + }); + }); }); diff --git a/src/engine/classic.js b/src/engine/classic.js index fac8e162d..7bdb35eb0 100644 --- a/src/engine/classic.js +++ b/src/engine/classic.js @@ -42,8 +42,8 @@ import { hasError, isDone, isSuccess } from '../sync'; import { getFieldValue } from '../field/index'; import { swap, updateEntity } from '../store/index'; -export function isSSOEnabled(m) { - return matchesEnterpriseConnection(m, databaseUsernameValue(m)); +export function isSSOEnabled(m, options) { + return matchesEnterpriseConnection(m, databaseUsernameValue(m, options)); } export function matchesEnterpriseConnection(m, usernameValue) { diff --git a/src/engine/classic/sign_up_screen.jsx b/src/engine/classic/sign_up_screen.jsx index e93417500..b15a53f1f 100644 --- a/src/engine/classic/sign_up_screen.jsx +++ b/src/engine/classic/sign_up_screen.jsx @@ -21,7 +21,7 @@ import LoginSignUpTabs from '../../connection/database/login_sign_up_tabs'; import SingleSignOnNotice from '../../connection/enterprise/single_sign_on_notice'; const Component = ({ i18n, model }) => { - const sso = isSSOEnabled(model) && hasScreen(model, 'login'); + const sso = isSSOEnabled(model, { emailFirst: true }) && hasScreen(model, 'login'); const ssoNotice = sso && {i18n.str('ssoEnabled')}; const tabs = !sso && @@ -87,10 +87,11 @@ export default class SignUp extends Screen { submitHandler(m) { if (hasOnlyClassicConnections(m, 'social')) return null; - if (isHRDDomain(m, databaseUsernameValue(m))) { - return id => startHRD(id, databaseUsernameValue(m)); + const username = databaseUsernameValue(m, { emailFirst: true }); + if (isHRDDomain(m, username)) { + return id => startHRD(id, username); } - if (isSSOEnabled(m)) return enterpriseLogIn; + if (isSSOEnabled(m, { emailFirst: true })) return enterpriseLogIn; return signUp; }