Skip to content

Commit

Permalink
Fix social auth banner after whats new screen (#106)
Browse files Browse the repository at this point in the history
* chore: transfer post login data through WhatNew screen

* chore: fixes after merge

* chore: refactor after merge

* chore: fixed tests and regenerate mocks

* chore: added default post login data

* chore: little refactor

---------

Co-authored-by: Anton Yarmolenko <[email protected]>
  • Loading branch information
rnr and rnr authored Dec 26, 2024
1 parent 5eb8197 commit 9a379c1
Show file tree
Hide file tree
Showing 19 changed files with 194 additions and 211 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public class SignInViewModel: ObservableObject {
let user = try await interactor.login(username: username, password: password)
analytics.identify(id: "\(user.id)", username: user.username, email: user.email)
analytics.userLogin(method: .password)
router.showMainOrWhatsNewScreen(sourceScreen: sourceScreen, authMethod: nil)
router.showMainOrWhatsNewScreen(sourceScreen: sourceScreen, postLoginData: nil)
NotificationCenter.default.post(name: .userAuthorized, object: nil)
} catch let error {
failure(error)
Expand Down Expand Up @@ -116,14 +116,11 @@ public class SignInViewModel: ObservableObject {
let user = try await interactor.login(externalToken: externalToken, backend: backend)
analytics.identify(id: "\(user.id)", username: user.username, email: user.email)
analytics.userLogin(method: authMethod)
var socialAuthMethod: String?
if case AuthMethod.socailAuth(let method) = authMethod {
socialAuthMethod = method.rawValue
var postLoginData: PostLoginData?
if case .socailAuth(let socialMethod) = authMethod {
postLoginData = PostLoginData(authMethod: socialMethod.rawValue, showSocialRegisterBanner: false)
}
router.showMainOrWhatsNewScreen(
sourceScreen: sourceScreen,
authMethod: socialAuthMethod
)
router.showMainOrWhatsNewScreen(sourceScreen: sourceScreen, postLoginData: postLoginData)
NotificationCenter.default.post(name: .userAuthorized, object: nil)
} catch let error {
failure(error, authMethod: authMethod)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,14 +138,11 @@ public class SignUpViewModel: ObservableObject {
analytics.identify(id: "\(user.id)", username: user.username, email: user.email)
analytics.registrationSuccess(method: authMetod.analyticsValue)
isShowProgress = false
var socialAuthMethod: String?
if case AuthMethod.socailAuth(let method) = authMethod {
socialAuthMethod = method.rawValue
var postLoginData: PostLoginData?
if case .socailAuth(let socialMethod) = authMethod {
postLoginData = PostLoginData(authMethod: socialMethod.rawValue, showSocialRegisterBanner: false)
}
router.showMainOrWhatsNewScreen(
sourceScreen: sourceScreen,
authMethod: socialAuthMethod
)
router.showMainOrWhatsNewScreen(sourceScreen: sourceScreen, postLoginData: postLoginData)
NotificationCenter.default.post(name: .userAuthorized, object: nil)
} catch let error {
isShowProgress = false
Expand Down Expand Up @@ -202,21 +199,12 @@ public class SignUpViewModel: ObservableObject {
analytics.identify(id: "\(user.id)", username: user.username, email: user.email)
analytics.userLogin(method: authMethod)
isShowProgress = false
var socialAuthMethod: String? = nil
if case AuthMethod.socailAuth(let method) = authMethod {
socialAuthMethod = method.rawValue
var postLoginData: PostLoginData?
if case .socailAuth(let socialMethod) = authMethod {
postLoginData = PostLoginData(authMethod: socialMethod.rawValue, showSocialRegisterBanner: true)
}
router.showMainOrWhatsNewScreen(
sourceScreen: sourceScreen,
authMethod: socialAuthMethod
)
NotificationCenter.default.post(
name: .userAuthorized,
object: [
"authMethod": authMethod,
"showSocialRegisterBanner": true
]
)
router.showMainOrWhatsNewScreen(sourceScreen: sourceScreen, postLoginData: postLoginData)
NotificationCenter.default.post(name: .userAuthorized, object: nil)
} catch {
update(fullName: response.name, email: response.email)
self.externalToken = response.token
Expand Down
48 changes: 24 additions & 24 deletions Authorization/AuthorizationTests/AuthorizationMock.generated.swift

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ final class SignInViewModelTests: XCTestCase {
await viewModel.login(username: "", password: "")

Verify(interactor, 0, .login(username: .any, password: .any))
Verify(router, 0, .showMainOrWhatsNewScreen(sourceScreen: .any, authMethod: .any))
Verify(router, 0, .showMainOrWhatsNewScreen(sourceScreen: .any, postLoginData: .any))

XCTAssertEqual(viewModel.errorMessage, AuthLocalization.Error.invalidEmailAddressOrUsername)
XCTAssertEqual(viewModel.isShowProgress, false)
Expand All @@ -63,7 +63,7 @@ final class SignInViewModelTests: XCTestCase {
await viewModel.login(username: "[email protected]", password: "")

Verify(interactor, 0, .login(username: .any, password: .any))
Verify(router, 0, .showMainOrWhatsNewScreen(sourceScreen: .any, authMethod: .any))
Verify(router, 0, .showMainOrWhatsNewScreen(sourceScreen: .any, postLoginData: .any))

XCTAssertEqual(viewModel.errorMessage, AuthLocalization.Error.invalidPasswordLenght)
XCTAssertEqual(viewModel.isShowProgress, false)
Expand Down Expand Up @@ -91,7 +91,7 @@ final class SignInViewModelTests: XCTestCase {

Verify(interactor, 1, .login(username: .any, password: .any))
Verify(analytics, .userLogin(method: .any))
Verify(router, 1, .showMainOrWhatsNewScreen(sourceScreen: .any, authMethod: .any))
Verify(router, 1, .showMainOrWhatsNewScreen(sourceScreen: .any, postLoginData: .any))

XCTAssertEqual(viewModel.errorMessage, nil)
XCTAssertEqual(viewModel.isShowProgress, true)
Expand Down Expand Up @@ -123,7 +123,7 @@ final class SignInViewModelTests: XCTestCase {

Verify(interactor, 1, .login(externalToken: .any, backend: .any))
Verify(analytics, .userLogin(method: .any))
Verify(router, 1, .showMainOrWhatsNewScreen(sourceScreen: .any, authMethod: .any))
Verify(router, 1, .showMainOrWhatsNewScreen(sourceScreen: .any, postLoginData: .any))

XCTAssertEqual(viewModel.errorMessage, nil)
XCTAssertEqual(viewModel.isShowProgress, true)
Expand Down Expand Up @@ -159,7 +159,7 @@ final class SignInViewModelTests: XCTestCase {
await viewModel.login(with: result)

Verify(interactor, 1, .login(externalToken: .any, backend: .any))
Verify(router, 0, .showMainOrWhatsNewScreen(sourceScreen: .any, authMethod: .any))
Verify(router, 0, .showMainOrWhatsNewScreen(sourceScreen: .any, postLoginData: .any))

XCTAssertEqual(viewModel.errorMessage, validationErrorMessage)
XCTAssertEqual(viewModel.isShowProgress, false)
Expand Down Expand Up @@ -189,7 +189,7 @@ final class SignInViewModelTests: XCTestCase {
await viewModel.login(username: "[email protected]", password: "password123")

Verify(interactor, 1, .login(username: .any, password: .any))
Verify(router, 0, .showMainOrWhatsNewScreen(sourceScreen: .any, authMethod: .any))
Verify(router, 0, .showMainOrWhatsNewScreen(sourceScreen: .any, postLoginData: .any))

XCTAssertEqual(viewModel.errorMessage, validationErrorMessage)
XCTAssertEqual(viewModel.isShowProgress, false)
Expand All @@ -215,7 +215,7 @@ final class SignInViewModelTests: XCTestCase {
await viewModel.login(username: "[email protected]", password: "password123")

Verify(interactor, 1, .login(username: .any, password: .any))
Verify(router, 0, .showMainOrWhatsNewScreen(sourceScreen: .any, authMethod: .any))
Verify(router, 0, .showMainOrWhatsNewScreen(sourceScreen: .any, postLoginData: .any))

XCTAssertEqual(viewModel.errorMessage, CoreLocalization.Error.invalidCredentials)
XCTAssertEqual(viewModel.isShowProgress, false)
Expand All @@ -241,7 +241,7 @@ final class SignInViewModelTests: XCTestCase {
await viewModel.login(username: "[email protected]", password: "password123")

Verify(interactor, 1, .login(username: .any, password: .any))
Verify(router, 0, .showMainOrWhatsNewScreen(sourceScreen: .any, authMethod: .any))
Verify(router, 0, .showMainOrWhatsNewScreen(sourceScreen: .any, postLoginData: .any))

XCTAssertEqual(viewModel.errorMessage, CoreLocalization.Error.unknownError)
XCTAssertEqual(viewModel.isShowProgress, false)
Expand Down Expand Up @@ -269,7 +269,7 @@ final class SignInViewModelTests: XCTestCase {
await viewModel.login(username: "[email protected]", password: "password123")

Verify(interactor, 1, .login(username: .any, password: .any))
Verify(router, 0, .showMainOrWhatsNewScreen(sourceScreen: .any, authMethod: .any))
Verify(router, 0, .showMainOrWhatsNewScreen(sourceScreen: .any, postLoginData: .any))

XCTAssertEqual(viewModel.errorMessage, CoreLocalization.Error.slowOrNoInternetConnection)
XCTAssertEqual(viewModel.isShowProgress, false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ final class SignUpViewModelTests: XCTestCase {

Verify(interactor, 1, .validateRegistrationFields(fields: .any))
Verify(interactor, 1, .registerUser(fields: .any, isSocial: .any))
Verify(router, 1, .showMainOrWhatsNewScreen(sourceScreen: .any, authMethod: .any))
Verify(router, 1, .showMainOrWhatsNewScreen(sourceScreen: .any, postLoginData: .any))

XCTAssertEqual(viewModel.isShowProgress, false)
XCTAssertEqual(viewModel.showError, false)
Expand Down Expand Up @@ -174,7 +174,7 @@ final class SignUpViewModelTests: XCTestCase {

Verify(interactor, 1, .validateRegistrationFields(fields: .any))
Verify(interactor, 0, .registerUser(fields: .any, isSocial: .any))
Verify(router, 0, .showMainOrWhatsNewScreen(sourceScreen: .any, authMethod: .any))
Verify(router, 0, .showMainOrWhatsNewScreen(sourceScreen: .any, postLoginData: .any))

XCTAssertEqual(viewModel.isShowProgress, false)
XCTAssertEqual(viewModel.showError, false)
Expand Down Expand Up @@ -204,7 +204,7 @@ final class SignUpViewModelTests: XCTestCase {

Verify(interactor, 1, .validateRegistrationFields(fields: .any))
Verify(interactor, 1, .registerUser(fields: .any, isSocial: .any))
Verify(router, 0, .showMainOrWhatsNewScreen(sourceScreen: .any, authMethod: .any))
Verify(router, 0, .showMainOrWhatsNewScreen(sourceScreen: .any, postLoginData: .any))

XCTAssertEqual(viewModel.isShowProgress, false)
XCTAssertEqual(viewModel.showError, true)
Expand Down Expand Up @@ -234,7 +234,7 @@ final class SignUpViewModelTests: XCTestCase {

Verify(interactor, 1, .validateRegistrationFields(fields: .any))
Verify(interactor, 1, .registerUser(fields: .any, isSocial: .any))
Verify(router, 0, .showMainOrWhatsNewScreen(sourceScreen: .any, authMethod: .any))
Verify(router, 0, .showMainOrWhatsNewScreen(sourceScreen: .any, postLoginData: .any))

XCTAssertEqual(viewModel.isShowProgress, false)
XCTAssertEqual(viewModel.showError, true)
Expand Down Expand Up @@ -266,7 +266,7 @@ final class SignUpViewModelTests: XCTestCase {

Verify(interactor, 1, .validateRegistrationFields(fields: .any))
Verify(interactor, 1, .registerUser(fields: .any, isSocial: .any))
Verify(router, 0, .showMainOrWhatsNewScreen(sourceScreen: .any, authMethod: .any))
Verify(router, 0, .showMainOrWhatsNewScreen(sourceScreen: .any, postLoginData: .any))

XCTAssertEqual(viewModel.isShowProgress, false)
XCTAssertEqual(viewModel.showError, true)
Expand Down
10 changes: 2 additions & 8 deletions Core/Core/Configuration/BaseRouter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,7 @@ public protocol BaseRouter {

func removeLastView(controllers: Int)

func showMainOrWhatsNewScreen(
sourceScreen: LogistrationSourceScreen,
authMethod: String?
)
func showMainOrWhatsNewScreen(sourceScreen: LogistrationSourceScreen, postLoginData: PostLoginData?)

func showStartupScreen()

Expand Down Expand Up @@ -109,10 +106,7 @@ open class BaseRouterMock: BaseRouter {

public func dismiss(animated: Bool) {}

public func showMainOrWhatsNewScreen(
sourceScreen: LogistrationSourceScreen,
authMethod: String?
) {}
public func showMainOrWhatsNewScreen(sourceScreen: LogistrationSourceScreen, postLoginData: PostLoginData?) {}

public func showStartupScreen() {}

Expand Down
12 changes: 12 additions & 0 deletions Core/Core/View/Base/LogistrationBottomView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,18 @@ public enum LogistrationAction {
case register
}

public struct PostLoginData: Sendable {
public var authMethod: String = ""
public var showSocialRegisterBanner: Bool = false

public init(authMethod: String, showSocialRegisterBanner: Bool) {
self.authMethod = authMethod
self.showSocialRegisterBanner = showSocialRegisterBanner
}

public init() {}
}

public struct LogistrationBottomView: View {
private let action: (LogistrationAction) -> Void

Expand Down
Loading

0 comments on commit 9a379c1

Please sign in to comment.