From 1b488a1dfde436f2f9c3c9e9fec2a5015122d0a9 Mon Sep 17 00:00:00 2001 From: Saltuk Alakus Date: Fri, 23 Oct 2020 13:31:43 +0300 Subject: [PATCH] Respect showTerms option for passworless (#1931) Co-authored-by: Steve Hobbs --- .../__snapshots__/passwordless.test.js.snap | 38 +++++++++++++++++++ .../passwordless/passwordless.test.js | 17 ++++++++- src/connection/passwordless/index.js | 7 +++- .../social_or_email_login_screen.jsx | 4 +- .../social_or_phone_number_login_screen.jsx | 4 +- 5 files changed, 64 insertions(+), 6 deletions(-) diff --git a/src/__tests__/connection/passwordless/__snapshots__/passwordless.test.js.snap b/src/__tests__/connection/passwordless/__snapshots__/passwordless.test.js.snap index cff2d0813..0ef0d4b1a 100644 --- a/src/__tests__/connection/passwordless/__snapshots__/passwordless.test.js.snap +++ b/src/__tests__/connection/passwordless/__snapshots__/passwordless.test.js.snap @@ -6,6 +6,7 @@ Array [ Immutable.Map { "send": "code", "mustAcceptTerms": false, + "showTerms": true, }, ] `; @@ -16,6 +17,7 @@ Array [ Immutable.Map { "send": "code", "mustAcceptTerms": true, + "showTerms": true, }, ] `; @@ -26,6 +28,7 @@ Array [ Immutable.Map { "send": "code", "mustAcceptTerms": false, + "showTerms": true, }, ] `; @@ -36,6 +39,7 @@ Array [ Immutable.Map { "send": "code", "mustAcceptTerms": false, + "showTerms": true, }, ] `; @@ -46,6 +50,40 @@ Array [ Immutable.Map { "send": "link", "mustAcceptTerms": false, + "showTerms": true, + }, +] +`; + +exports[`passwordless connection initPasswordless() calls initNS with showTerms:false when opts.showTerms is false 1`] = ` +Array [ + null, + Immutable.Map { + "send": "code", + "mustAcceptTerms": false, + "showTerms": false, + }, +] +`; + +exports[`passwordless connection initPasswordless() calls initNS with showTerms:true when opts.showTerms is true 1`] = ` +Array [ + null, + Immutable.Map { + "send": "code", + "mustAcceptTerms": false, + "showTerms": true, + }, +] +`; + +exports[`passwordless connection initPasswordless() calls initNS with showTerms:true when opts.showTerms is undefined 1`] = ` +Array [ + null, + Immutable.Map { + "send": "code", + "mustAcceptTerms": false, + "showTerms": true, }, ] `; diff --git a/src/__tests__/connection/passwordless/passwordless.test.js b/src/__tests__/connection/passwordless/passwordless.test.js index c41ca283d..a8cdd6d39 100644 --- a/src/__tests__/connection/passwordless/passwordless.test.js +++ b/src/__tests__/connection/passwordless/passwordless.test.js @@ -63,6 +63,22 @@ describe('passwordless connection', () => { }); expectMockToMatch(mockFns.initNS, 1); }); + it('with showTerms:true when opts.showTerms is undefined', () => { + initPasswordless(null, {}); + expectMockToMatch(mockFns.initNS, 1); + }); + it('with showTerms:true when opts.showTerms is true', () => { + initPasswordless(null, { + showTerms: true + }); + expectMockToMatch(mockFns.initNS, 1); + }); + it('with showTerms:false when opts.showTerms is false', () => { + initPasswordless(null, { + showTerms: false + }); + expectMockToMatch(mockFns.initNS, 1); + }); }); it('should load default location via options.defaultLocation', () => { initPasswordless(null, { @@ -89,7 +105,6 @@ describe('passwordless connection', () => { expectMockToMatch(mockFns.get, 1); }); }); - describe('toggleTermsAcceptance()', () => { it('should tset `termsAccepted` to false when `termsAccepted` is true', () => { mockFns.get.mockReturnValue(true); diff --git a/src/connection/passwordless/index.js b/src/connection/passwordless/index.js index f063c428d..86f923f55 100644 --- a/src/connection/passwordless/index.js +++ b/src/connection/passwordless/index.js @@ -11,8 +11,9 @@ export function initPasswordless(m, opts) { // TODO: validate opts const send = opts.passwordlessMethod === 'link' ? 'link' : 'code'; const mustAcceptTerms = !!opts.mustAcceptTerms; + const showTerms = opts.showTerms === undefined ? true : !!opts.showTerms; - m = initNS(m, Map({ send, mustAcceptTerms })); + m = initNS(m, Map({ send, mustAcceptTerms, showTerms })); if (opts.defaultLocation && typeof opts.defaultLocation === 'string') { m = initLocation(m, opts.defaultLocation.toUpperCase()); } else { @@ -104,6 +105,10 @@ export function isEmail(m) { return c.isEmpty() ? undefined : c.get('strategy') === 'email'; } +export function showTerms(m) { + return get(m, 'showTerms', true); +} + export function mustAcceptTerms(m) { return get(m, 'mustAcceptTerms', false); } diff --git a/src/engine/passwordless/social_or_email_login_screen.jsx b/src/engine/passwordless/social_or_email_login_screen.jsx index 30d586b10..fd1e3c458 100644 --- a/src/engine/passwordless/social_or_email_login_screen.jsx +++ b/src/engine/passwordless/social_or_email_login_screen.jsx @@ -3,7 +3,7 @@ import Screen from '../../core/screen'; import EmailPane from '../../field/email/email_pane'; import SocialButtonsPane from '../../field/social/social_buttons_pane'; import PaneSeparator from '../../core/pane_separator'; -import { mustAcceptTerms, termsAccepted } from '../../connection/passwordless/index'; +import { mustAcceptTerms, termsAccepted, showTerms } from '../../connection/passwordless/index'; import { toggleTermsAcceptance } from '../../connection/passwordless/actions'; import { requestPasswordlessEmail } from '../../connection/passwordless/actions'; import { renderEmailSentConfirmation } from '../../connection/passwordless/email_sent_confirmation'; @@ -77,7 +77,7 @@ export default class SocialOrEmailLoginScreen extends Screen { renderTerms(m, terms) { const checkHandler = mustAcceptTerms(m) ? () => toggleTermsAcceptance(l.id(m)) : undefined; - return terms || mustAcceptTerms(m) ? ( + return terms && showTerms(m) ? ( toggleTermsAcceptance(l.id(m)) : undefined; - return terms || mustAcceptTerms(m) ? ( + return terms && showTerms(m) ? (