Skip to content

Commit

Permalink
Added showTerms feature flag (#520)
Browse files Browse the repository at this point in the history
Updated README
Added Tests
Fixed Xcode 10 Test Warnings
  • Loading branch information
cocojoe authored Oct 3, 2018
1 parent acd62f6 commit 558ba50
Show file tree
Hide file tree
Showing 16 changed files with 94 additions and 55 deletions.
4 changes: 2 additions & 2 deletions Lock/DatabaseOnlyView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ class DatabaseOnlyView: UIView, DatabaseView {
}

// swiftlint:disable:next function_parameter_count
func showSignUp(withUsername showUsername: Bool, username: String?, email: String?, authCollectionView: AuthCollectionView? = nil, additionalFields: [CustomTextField], passwordPolicyValidator: PasswordPolicyValidator? = nil, showPassswordManager: Bool, showPassword: Bool) {
func showSignUp(withUsername showUsername: Bool, username: String?, email: String?, authCollectionView: AuthCollectionView? = nil, additionalFields: [CustomTextField], passwordPolicyValidator: PasswordPolicyValidator? = nil, showPassswordManager: Bool, showPassword: Bool, showTerms: Bool) {
let form = SignUpView(additionalFields: additionalFields)
form.showUsername = showUsername
form.emailField.text = email
Expand All @@ -139,7 +139,7 @@ class DatabaseOnlyView: UIView, DatabaseView {

primaryButton?.title = "SIGN UP".i18n(key: "com.auth0.lock.submit.signup.title", comment: "Signup Button title")
layoutInStack(form, authCollectionView: authCollectionView)
self.layoutSecondaryButton(true)
self.layoutSecondaryButton(showTerms)
self.form = form

self.identityField = showUsername ? form.usernameField : form.emailField
Expand Down
2 changes: 1 addition & 1 deletion Lock/DatabasePresenter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ class DatabasePresenter: Presentable, Loggable {
let passwordPolicyValidator = interactor?.passwordValidator as? PasswordPolicyValidator
self.currentScreen = .signup
interactor?.user.reset()
view.showSignUp(withUsername: self.database.requiresUsername, username: username, email: email, authCollectionView: authCollectionView, additionalFields: self.options.customSignupFields, passwordPolicyValidator: passwordPolicyValidator, showPassswordManager: self.passwordManager.available, showPassword: self.options.allowShowPassword)
view.showSignUp(withUsername: self.database.requiresUsername, username: username, email: email, authCollectionView: authCollectionView, additionalFields: self.options.customSignupFields, passwordPolicyValidator: passwordPolicyValidator, showPassswordManager: self.passwordManager.available, showPassword: self.options.allowShowPassword, showTerms: options.showTerms || options.mustAcceptTerms)
let form = view.form
view.form?.onValueChange = self.handleInput

Expand Down
2 changes: 1 addition & 1 deletion Lock/DatabaseView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,5 @@ protocol DatabaseView: class, View {

func showLogin(withIdentifierStyle style: DatabaseIdentifierStyle, identifier: String?, authCollectionView: AuthCollectionView?, showPassswordManager: Bool, showPassword: Bool)
// swiftlint:disable:next function_parameter_count
func showSignUp(withUsername showUsername: Bool, username: String?, email: String?, authCollectionView: AuthCollectionView?, additionalFields: [CustomTextField], passwordPolicyValidator: PasswordPolicyValidator?, showPassswordManager: Bool, showPassword: Bool)
func showSignUp(withUsername showUsername: Bool, username: String?, email: String?, authCollectionView: AuthCollectionView?, additionalFields: [CustomTextField], passwordPolicyValidator: PasswordPolicyValidator?, showPassswordManager: Bool, showPassword: Bool, showTerms: Bool)
}
1 change: 1 addition & 0 deletions Lock/LockOptions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ struct LockOptions: OptionBuildable {
var privacyPolicyURL: URL = URL(string: "https://auth0.com/privacy")!
var supportURL: URL?
var mustAcceptTerms: Bool = false
var showTerms: Bool = true
var logLevel: LoggerLevel = .off
var loggerOutput: LoggerOutput?
var logHttpRequest: Bool = false
Expand Down
5 changes: 4 additions & 1 deletion Lock/OptionBuildable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,12 @@ public protocol OptionBuildable: Options {
/// Support page url that will be displayed (Inside Safari) when an unrecoverable error occurs and the user taps the "Contact Support" button in the error screen.
var supportURL: URL? { get set }

/// Whether the user needs to accept the terms before sign up or not.
/// Whether the user needs to accept the terms before sign up or not. By default is false.
var mustAcceptTerms: Bool { get set }

/// Whether the terms should be shown on the signup screen. By default is true.
var showTerms: Bool { get set }

/// Log level for Lock. By default is `Off`.
var logLevel: LoggerLevel { get set }

Expand Down
1 change: 1 addition & 0 deletions Lock/Options.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public protocol Options {
var privacyPolicyURL: URL { get }
var supportURL: URL? { get }
var mustAcceptTerms: Bool { get }
var showTerms: Bool { get }

var logLevel: LoggerLevel { get }
var loggerOutput: LoggerOutput? { get }
Expand Down
6 changes: 5 additions & 1 deletion LockTests/OptionsSpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,10 @@ class OptionsSpec: QuickSpec {
it("should have configurationBaseURL as nil") {
expect(options.configurationBaseURL).to(beNil())
}

it("should have showTerms as enabled") {
expect(options.showTerms) == true
}
}

describe("validation") {
Expand Down Expand Up @@ -181,7 +185,7 @@ class OptionsSpec: QuickSpec {
options.audience = "https://myapi.com"
expect(options.validate()).to(beNil())
}

context("passwordless") {

it("should fail setting audience in passwordless mode") {
Expand Down
2 changes: 1 addition & 1 deletion LockTests/Presenters/AuthPresenterSpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class AuthPresenterSpec: QuickSpec {
var view: AuthCollectionView!

beforeEach {
view = presenter.view as! AuthCollectionView
view = presenter.view as? AuthCollectionView

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class DatabaseForgotPasswordPresenterSpec: QuickSpec {
connections.database(name: connection, requiresUsername: true)
presenter = DatabaseForgotPasswordPresenter(interactor: interactor, connections: connections, navigator: navigator, options: options)
presenter.messagePresenter = messagePresenter
view = presenter.view as! DatabaseForgotPasswordView
view = presenter.view as? DatabaseForgotPasswordView
}

it("should use valid email") {
Expand Down Expand Up @@ -200,7 +200,7 @@ class DatabaseForgotPasswordPresenterSpec: QuickSpec {
options.allow = .ResetPassword
presenter = DatabaseForgotPasswordPresenter(interactor: interactor, connections: connections, navigator: navigator, options: options)
presenter.messagePresenter = messagePresenter
view = presenter.view as! DatabaseForgotPasswordView
view = presenter.view as? DatabaseForgotPasswordView
}

it("should not show global success message") {
Expand All @@ -216,7 +216,7 @@ class DatabaseForgotPasswordPresenterSpec: QuickSpec {
options.autoClose = false
presenter = DatabaseForgotPasswordPresenter(interactor: interactor, connections: connections, navigator: navigator, options: options)
presenter.messagePresenter = messagePresenter
view = presenter.view as! DatabaseForgotPasswordView
view = presenter.view as? DatabaseForgotPasswordView

interactor.onRequest = {
return nil
Expand Down Expand Up @@ -246,7 +246,7 @@ class DatabaseForgotPasswordPresenterSpec: QuickSpec {
navigator.route = .forgotPassword

presenter = DatabaseForgotPasswordPresenter(interactor: interactor, connections: connections, navigator: navigator, options: options)
view = presenter.view as! DatabaseForgotPasswordView
view = presenter.view as? DatabaseForgotPasswordView

let button = view.primaryButton!
interactor.onRequest = {
Expand Down
59 changes: 39 additions & 20 deletions LockTests/Presenters/DatabasePresenterSpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class DatabasePresenterSpec: QuickSpec {
navigator = MockNavigator()
presenter = DatabasePresenter(authenticator: interactor, creator: interactor, connection: DatabaseConnection(name: connection, requiresUsername: true), navigator: navigator, options: options)
presenter.messagePresenter = messagePresenter
view = presenter.view as! DatabaseOnlyView
view = presenter.view as? DatabaseOnlyView
}

describe("auth buttons") {
Expand Down Expand Up @@ -151,23 +151,23 @@ class DatabasePresenterSpec: QuickSpec {
var options = LockOptions()
options.allow = [.Login, .Signup]
presenter = DatabasePresenter(authenticator: interactor, creator: interactor, connection: DatabaseConnection(name: connection, requiresUsername: true), navigator: navigator, options: options)
view = presenter.view as! DatabaseOnlyView
view = presenter.view as? DatabaseOnlyView
expect(view.switcher).toNot(beNil())
}

it("should remove switcher when login or signup are not allowed") {
var options = LockOptions()
options.allow = [.Login]
presenter = DatabasePresenter(authenticator: interactor, creator: interactor, connection: DatabaseConnection(name: connection, requiresUsername: true), navigator: navigator, options: options)
view = presenter.view as! DatabaseOnlyView
view = presenter.view as? DatabaseOnlyView
expect(view.switcher).to(beNil())
}

it("should remove forgot button if it's not allowed") {
var options = LockOptions()
options.allow = [.Login]
presenter = DatabasePresenter(authenticator: interactor, creator: interactor, connection: DatabaseConnection(name: connection, requiresUsername: true), navigator: navigator, options: options)
view = presenter.view as! DatabaseOnlyView
view = presenter.view as? DatabaseOnlyView
expect(view.secondaryButton).to(beNil())
}

Expand All @@ -176,15 +176,15 @@ class DatabasePresenterSpec: QuickSpec {
options.allow = [.Login]
options.initialScreen = .login
presenter = DatabasePresenter(authenticator: interactor, creator: interactor, connection: DatabaseConnection(name: connection, requiresUsername: true), navigator: navigator, options: options)
view = presenter.view as! DatabaseOnlyView
view = presenter.view as? DatabaseOnlyView
expect(view.form as? CredentialView).toNot(beNil())
}

it("should show signup if login is not allowed") {
var options = LockOptions()
options.allow = [.Signup]
presenter = DatabasePresenter(authenticator: interactor, creator: interactor, connection: DatabaseConnection(name: connection, requiresUsername: true), navigator: navigator, options: options)
view = presenter.view as! DatabaseOnlyView
view = presenter.view as? DatabaseOnlyView
expect(view.form as? SignUpView).toNot(beNil())
}

Expand All @@ -193,15 +193,34 @@ class DatabasePresenterSpec: QuickSpec {
options.allow = [.Signup, .Login]
options.initialScreen = .signup
presenter = DatabasePresenter(authenticator: interactor, creator: interactor, connection: DatabaseConnection(name: connection, requiresUsername: true), navigator: navigator, options: options)
view = presenter.view as! DatabaseOnlyView
view = presenter.view as? DatabaseOnlyView
expect(view.form as? SignUpView).toNot(beNil())
}

it("should always show terms button in signup") {
var options = LockOptions()
options.allow = [.Signup]
presenter = DatabasePresenter(authenticator: interactor, creator: interactor, connection: DatabaseConnection(name: connection, requiresUsername: true), navigator: navigator, options: options)
view = presenter.view as! DatabaseOnlyView
view = presenter.view as? DatabaseOnlyView
expect(view.secondaryButton).toNot(beNil())
}

it("should hide terms button in signup") {
var options = LockOptions()
options.allow = [.Signup]
options.showTerms = false
presenter = DatabasePresenter(authenticator: interactor, creator: interactor, connection: DatabaseConnection(name: connection, requiresUsername: true), navigator: navigator, options: options)
view = presenter.view as? DatabaseOnlyView
expect(view.secondaryButton).to(beNil())
}

it("should show terms button in signup when terms disabled but must accept terms is enabled") {
var options = LockOptions()
options.allow = [.Signup]
options.showTerms = false
options.mustAcceptTerms = true
presenter = DatabasePresenter(authenticator: interactor, creator: interactor, connection: DatabaseConnection(name: connection, requiresUsername: true), navigator: navigator, options: options)
view = presenter.view as? DatabaseOnlyView
expect(view.secondaryButton).toNot(beNil())
}

Expand Down Expand Up @@ -238,7 +257,7 @@ class DatabasePresenterSpec: QuickSpec {

beforeEach {
presenter.passwordManager = passwordManager
view = presenter.view as! DatabaseOnlyView
view = presenter.view as? DatabaseOnlyView
}

it("should show password manager button") {
Expand All @@ -247,7 +266,7 @@ class DatabasePresenterSpec: QuickSpec {

it("should not show password manager when disabled") {
presenter.passwordManager.enabled = false
view = presenter.view as! DatabaseOnlyView
view = presenter.view as? DatabaseOnlyView
expect(view.passwordManagerButton).to(beNil())
}

Expand Down Expand Up @@ -418,7 +437,7 @@ class DatabasePresenterSpec: QuickSpec {
options.autoClose = false
presenter = DatabasePresenter(authenticator: interactor, creator: interactor, connection: DatabaseConnection(name: connection, requiresUsername: true), navigator: navigator, options: options)
presenter.messagePresenter = messagePresenter
view = presenter.view as! DatabaseOnlyView
view = presenter.view as? DatabaseOnlyView
interactor.onLogin = {
return nil
}
Expand All @@ -437,7 +456,7 @@ class DatabasePresenterSpec: QuickSpec {
username = nil
password = nil
presenter.passwordManager = passwordManager
view = presenter.view as! DatabaseOnlyView
view = presenter.view as? DatabaseOnlyView
view.switcher?.selected = .signup
view.switcher?.onSelectionChange(view.switcher!)
presenter.passwordManager.onUpdate = { username = $0; password = $1 }
Expand Down Expand Up @@ -539,7 +558,7 @@ class DatabasePresenterSpec: QuickSpec {

beforeEach {
presenter.passwordManager = passwordManager
view = presenter.view as! DatabaseOnlyView
view = presenter.view as? DatabaseOnlyView
view.switcher?.selected = .signup
view.switcher?.onSelectionChange(view.switcher!)
}
Expand Down Expand Up @@ -673,7 +692,7 @@ class DatabasePresenterSpec: QuickSpec {
beforeEach {
options.mustAcceptTerms = true
presenter = DatabasePresenter(authenticator: interactor, creator: interactor, connection: DatabaseConnection(name: connection, requiresUsername: false), navigator: navigator, options: options)
view = presenter.view as! DatabaseOnlyView
view = presenter.view as? DatabaseOnlyView
view.switcher?.selected = .signup
view.switcher?.onSelectionChange(view.switcher!)
}
Expand Down Expand Up @@ -709,7 +728,7 @@ class DatabasePresenterSpec: QuickSpec {

it("should switch to login on success") {
presenter = DatabasePresenter(authenticator: interactor, creator: interactor, connection: DatabaseConnection(name: connection, requiresUsername: true), navigator: navigator, options: options)
view = presenter.view as! DatabaseOnlyView
view = presenter.view as? DatabaseOnlyView

let button = view.primaryButton!
interactor.onSignUp = {
Expand All @@ -722,7 +741,7 @@ class DatabasePresenterSpec: QuickSpec {
it("should remain on signup on success") {
options.allow = .Signup
presenter = DatabasePresenter(authenticator: interactor, creator: interactor, connection: DatabaseConnection(name: connection, requiresUsername: true), navigator: navigator, options: options)
view = presenter.view as! DatabaseOnlyView
view = presenter.view as? DatabaseOnlyView

let button = view.primaryButton!
interactor.onSignUp = {
Expand All @@ -740,7 +759,7 @@ class DatabasePresenterSpec: QuickSpec {
options.autoClose = false
presenter = DatabasePresenter(authenticator: interactor, creator: interactor, connection: DatabaseConnection(name: connection, requiresUsername: true), navigator: navigator, options: options)
presenter.messagePresenter = messagePresenter
view = presenter.view as! DatabaseOnlyView
view = presenter.view as? DatabaseOnlyView
}

it("should show no success message") {
Expand All @@ -763,7 +782,7 @@ class DatabasePresenterSpec: QuickSpec {
username = nil
password = nil
presenter.passwordManager = passwordManager
view = presenter.view as! DatabaseOnlyView
view = presenter.view as? DatabaseOnlyView
view.switcher?.selected = .signup
view.switcher?.onSelectionChange(view.switcher!)
presenter.passwordManager.onUpdate = { username = $0; password = $1 }
Expand Down Expand Up @@ -808,7 +827,7 @@ class DatabasePresenterSpec: QuickSpec {
enterpriseInteractor = EnterpriseDomainInteractor(connections: connections, user: user, authentication: oauth2)
presenter.enterpriseInteractor = enterpriseInteractor

view = presenter.view as! DatabaseOnlyView
view = presenter.view as? DatabaseOnlyView
}

it("should modify display with enterprise changes") {
Expand Down Expand Up @@ -898,7 +917,7 @@ class DatabasePresenterSpec: QuickSpec {
enterpriseInteractor = EnterpriseDomainInteractor(connections: connections, user: user, authentication: oauth2)
presenter.enterpriseInteractor = enterpriseInteractor

view = presenter.view as! DatabaseOnlyView
view = presenter.view as? DatabaseOnlyView

let input = mockInput(.email, value: "[email protected]")
view.form?.onValueChange(input)
Expand Down
Loading

0 comments on commit 558ba50

Please sign in to comment.