-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add filter discussion posts * courseBannder, certificate from Get course outline by course_id * dashboard pagination * fix search courses * minor fix
- Loading branch information
1 parent
c3ce770
commit b3c3d09
Showing
60 changed files
with
1,078 additions
and
788 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 40 additions & 10 deletions
50
Authorization/AuthorizationTests/AuthorizationMock.generated.swift
Large diffs are not rendered by default.
Oops, something went wrong.
167 changes: 167 additions & 0 deletions
167
Authorization/AuthorizationTests/Presentation/Login/ResetPasswordViewModelTests.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,167 @@ | ||
// | ||
// ResetPasswordViewModelTests.swift | ||
// AuthorizationTests | ||
// | ||
// Created by Stepanok Ivan on 04.04.2023. | ||
// | ||
|
||
import SwiftyMocky | ||
import XCTest | ||
@testable import Core | ||
@testable import Authorization | ||
import Alamofire | ||
import SwiftUI | ||
|
||
final class ResetPasswordViewModelTests: XCTestCase { | ||
|
||
func testResetPasswordValidationEmailError() async throws { | ||
let interactor = AuthInteractorProtocolMock() | ||
let router = AuthorizationRouterMock() | ||
let validator = Validator() | ||
let viewModel = ResetPasswordViewModel(interactor: interactor, router: router, validator: validator) | ||
|
||
var isRecoveryPassword = true | ||
let binding = Binding(get: { | ||
return isRecoveryPassword | ||
}, set: { value in | ||
isRecoveryPassword = value | ||
}) | ||
|
||
await viewModel.resetPassword(email: "e", isRecovered: binding) | ||
|
||
Verify(interactor, 0, .resetPassword(email: .any)) | ||
|
||
XCTAssertEqual(viewModel.errorMessage, AuthLocalization.Error.invalidEmailAddress) | ||
XCTAssertEqual(viewModel.isShowProgress, false) | ||
XCTAssertEqual(isRecoveryPassword, true) | ||
} | ||
|
||
func testResetPasswordSuccess() async throws { | ||
let interactor = AuthInteractorProtocolMock() | ||
let router = AuthorizationRouterMock() | ||
let validator = Validator() | ||
let viewModel = ResetPasswordViewModel(interactor: interactor, router: router, validator: validator) | ||
|
||
var isRecoveryPassword = true | ||
let binding = Binding(get: { | ||
return isRecoveryPassword | ||
}, set: { value in | ||
isRecoveryPassword = value | ||
}) | ||
|
||
let data = ResetPassword(success: true, responseText: "Success") | ||
Given(interactor, .resetPassword(email: .any, willReturn: data)) | ||
|
||
await viewModel.resetPassword(email: "[email protected]", isRecovered: binding) | ||
|
||
Verify(interactor, 1, .resetPassword(email: .any)) | ||
|
||
XCTAssertFalse(isRecoveryPassword) | ||
XCTAssertEqual(viewModel.errorMessage, nil) | ||
XCTAssertEqual(viewModel.isShowProgress, false) | ||
XCTAssertEqual(isRecoveryPassword, false) | ||
} | ||
|
||
func testResetPasswordErrorValidation() async throws { | ||
let interactor = AuthInteractorProtocolMock() | ||
let router = AuthorizationRouterMock() | ||
let validator = Validator() | ||
let viewModel = ResetPasswordViewModel(interactor: interactor, router: router, validator: validator) | ||
|
||
let validationErrorMessage = "Some error" | ||
let validationError = CustomValidationError(statusCode: 400, data: ["value": validationErrorMessage]) | ||
let error = AFError.responseValidationFailed(reason: AFError.ResponseValidationFailureReason.customValidationFailed(error: validationError)) | ||
|
||
Given(interactor, .resetPassword(email: .any, willThrow: error)) | ||
|
||
var isRecoveryPassword = true | ||
let binding = Binding(get: { | ||
return isRecoveryPassword | ||
}, set: { value in | ||
isRecoveryPassword = value | ||
}) | ||
|
||
await viewModel.resetPassword(email: "[email protected]", isRecovered: binding) | ||
|
||
Verify(interactor, 1, .resetPassword(email: .any)) | ||
|
||
XCTAssertEqual(viewModel.errorMessage, validationErrorMessage) | ||
XCTAssertEqual(viewModel.isShowProgress, false) | ||
XCTAssertEqual(isRecoveryPassword, true) | ||
} | ||
|
||
func testResetPasswordErrorInvalidGrant() async throws { | ||
let interactor = AuthInteractorProtocolMock() | ||
let router = AuthorizationRouterMock() | ||
let validator = Validator() | ||
let viewModel = ResetPasswordViewModel(interactor: interactor, router: router, validator: validator) | ||
|
||
Given(interactor, .resetPassword(email: .any, willThrow: APIError.invalidGrant)) | ||
|
||
var isRecoveryPassword = true | ||
let binding = Binding(get: { | ||
return isRecoveryPassword | ||
}, set: { value in | ||
isRecoveryPassword = value | ||
}) | ||
|
||
await viewModel.resetPassword(email: "[email protected]", isRecovered: binding) | ||
|
||
Verify(interactor, 1, .resetPassword(email: .any)) | ||
|
||
XCTAssertEqual(viewModel.errorMessage, CoreLocalization.Error.invalidCredentials) | ||
XCTAssertEqual(viewModel.isShowProgress, false) | ||
XCTAssertEqual(isRecoveryPassword, true) | ||
} | ||
|
||
func testResetPasswordErrorUnknown() async throws { | ||
let interactor = AuthInteractorProtocolMock() | ||
let router = AuthorizationRouterMock() | ||
let validator = Validator() | ||
let viewModel = ResetPasswordViewModel(interactor: interactor, router: router, validator: validator) | ||
|
||
Given(interactor, .resetPassword(email: .any, willThrow: NSError())) | ||
|
||
var isRecoveryPassword = true | ||
let binding = Binding(get: { | ||
return isRecoveryPassword | ||
}, set: { value in | ||
isRecoveryPassword = value | ||
}) | ||
|
||
await viewModel.resetPassword(email: "[email protected]", isRecovered: binding) | ||
|
||
Verify(interactor, 1, .resetPassword(email: .any)) | ||
|
||
XCTAssertEqual(viewModel.errorMessage, CoreLocalization.Error.unknownError) | ||
XCTAssertEqual(viewModel.isShowProgress, false) | ||
XCTAssertEqual(isRecoveryPassword, true) | ||
} | ||
|
||
func testResetPasswordNoInternetError() async throws { | ||
let interactor = AuthInteractorProtocolMock() | ||
let router = AuthorizationRouterMock() | ||
let validator = Validator() | ||
let viewModel = ResetPasswordViewModel(interactor: interactor, router: router, validator: validator) | ||
|
||
let noInternetError = AFError.sessionInvalidated(error: URLError(.notConnectedToInternet)) | ||
|
||
Given(interactor, .resetPassword(email: .any, willThrow: noInternetError)) | ||
|
||
var isRecoveryPassword = true | ||
let binding = Binding(get: { | ||
return isRecoveryPassword | ||
}, set: { value in | ||
isRecoveryPassword = value | ||
}) | ||
|
||
await viewModel.resetPassword(email: "[email protected]", isRecovered: binding) | ||
|
||
Verify(interactor, 1, .resetPassword(email: .any)) | ||
|
||
XCTAssertEqual(viewModel.errorMessage, CoreLocalization.Error.slowOrNoInternetConnection) | ||
XCTAssertEqual(viewModel.isShowProgress, false) | ||
XCTAssertEqual(isRecoveryPassword, true) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -143,155 +143,5 @@ final class SignInViewModelTests: XCTestCase { | |
XCTAssertEqual(viewModel.errorMessage, CoreLocalization.Error.slowOrNoInternetConnection) | ||
XCTAssertEqual(viewModel.isShowProgress, false) | ||
} | ||
|
||
func testResetPasswordValidationEmailError() async throws { | ||
let interactor = AuthInteractorProtocolMock() | ||
let router = AuthorizationRouterMock() | ||
let validator = Validator() | ||
let viewModel = SignInViewModel(interactor: interactor, router: router, validator: validator) | ||
|
||
var isRecoveryPassword = true | ||
let binding = Binding(get: { | ||
return isRecoveryPassword | ||
}, set: { value in | ||
isRecoveryPassword = value | ||
}) | ||
|
||
await viewModel.resetPassword(email: "e", isRecoveryPassord: binding) | ||
|
||
Verify(interactor, 0, .resetPassword(email: .any)) | ||
|
||
XCTAssertEqual(viewModel.errorMessage, AuthLocalization.Error.invalidEmailAddress) | ||
XCTAssertEqual(viewModel.isShowProgress, false) | ||
XCTAssertEqual(isRecoveryPassword, true) | ||
} | ||
|
||
func testResetPasswordSuccess() async throws { | ||
let interactor = AuthInteractorProtocolMock() | ||
let router = AuthorizationRouterMock() | ||
let validator = Validator() | ||
let viewModel = SignInViewModel(interactor: interactor, router: router, validator: validator) | ||
|
||
var isRecoveryPassword = true | ||
let binding = Binding(get: { | ||
return isRecoveryPassword | ||
}, set: { value in | ||
isRecoveryPassword = value | ||
}) | ||
|
||
let data = ResetPassword(success: true, responseText: "Success") | ||
Given(interactor, .resetPassword(email: .any, willReturn: data)) | ||
|
||
await viewModel.resetPassword(email: "[email protected]", isRecoveryPassord: binding) | ||
|
||
Verify(interactor, 1, .resetPassword(email: .any)) | ||
|
||
XCTAssertEqual(viewModel.alertMessage, data.responseText) | ||
XCTAssertEqual(viewModel.errorMessage, nil) | ||
XCTAssertEqual(viewModel.isShowProgress, false) | ||
XCTAssertEqual(isRecoveryPassword, false) | ||
} | ||
|
||
func testResetPasswordErrorValidation() async throws { | ||
let interactor = AuthInteractorProtocolMock() | ||
let router = AuthorizationRouterMock() | ||
let validator = Validator() | ||
let viewModel = SignInViewModel(interactor: interactor, router: router, validator: validator) | ||
|
||
let validationErrorMessage = "Some error" | ||
let validationError = CustomValidationError(statusCode: 400, data: ["value": validationErrorMessage]) | ||
let error = AFError.responseValidationFailed(reason: AFError.ResponseValidationFailureReason.customValidationFailed(error: validationError)) | ||
|
||
Given(interactor, .resetPassword(email: .any, willThrow: error)) | ||
|
||
var isRecoveryPassword = true | ||
let binding = Binding(get: { | ||
return isRecoveryPassword | ||
}, set: { value in | ||
isRecoveryPassword = value | ||
}) | ||
|
||
await viewModel.resetPassword(email: "[email protected]", isRecoveryPassord: binding) | ||
|
||
Verify(interactor, 1, .resetPassword(email: .any)) | ||
|
||
XCTAssertEqual(viewModel.errorMessage, validationErrorMessage) | ||
XCTAssertEqual(viewModel.isShowProgress, false) | ||
XCTAssertEqual(isRecoveryPassword, true) | ||
} | ||
|
||
func testResetPasswordErrorInvalidGrant() async throws { | ||
let interactor = AuthInteractorProtocolMock() | ||
let router = AuthorizationRouterMock() | ||
let validator = Validator() | ||
let viewModel = SignInViewModel(interactor: interactor, router: router, validator: validator) | ||
|
||
Given(interactor, .resetPassword(email: .any, willThrow: APIError.invalidGrant)) | ||
|
||
var isRecoveryPassword = true | ||
let binding = Binding(get: { | ||
return isRecoveryPassword | ||
}, set: { value in | ||
isRecoveryPassword = value | ||
}) | ||
|
||
await viewModel.resetPassword(email: "[email protected]", isRecoveryPassord: binding) | ||
|
||
Verify(interactor, 1, .resetPassword(email: .any)) | ||
|
||
XCTAssertEqual(viewModel.errorMessage, CoreLocalization.Error.invalidCredentials) | ||
XCTAssertEqual(viewModel.isShowProgress, false) | ||
XCTAssertEqual(isRecoveryPassword, true) | ||
} | ||
|
||
func testResetPasswordErrorUnknown() async throws { | ||
let interactor = AuthInteractorProtocolMock() | ||
let router = AuthorizationRouterMock() | ||
let validator = Validator() | ||
let viewModel = SignInViewModel(interactor: interactor, router: router, validator: validator) | ||
|
||
Given(interactor, .resetPassword(email: .any, willThrow: NSError())) | ||
|
||
var isRecoveryPassword = true | ||
let binding = Binding(get: { | ||
return isRecoveryPassword | ||
}, set: { value in | ||
isRecoveryPassword = value | ||
}) | ||
|
||
await viewModel.resetPassword(email: "[email protected]", isRecoveryPassord: binding) | ||
|
||
Verify(interactor, 1, .resetPassword(email: .any)) | ||
|
||
XCTAssertEqual(viewModel.errorMessage, CoreLocalization.Error.unknownError) | ||
XCTAssertEqual(viewModel.isShowProgress, false) | ||
XCTAssertEqual(isRecoveryPassword, true) | ||
} | ||
|
||
func testResetPasswordNoInternetError() async throws { | ||
let interactor = AuthInteractorProtocolMock() | ||
let router = AuthorizationRouterMock() | ||
let validator = Validator() | ||
let viewModel = SignInViewModel(interactor: interactor, router: router, validator: validator) | ||
|
||
let noInternetError = AFError.sessionInvalidated(error: URLError(.notConnectedToInternet)) | ||
|
||
Given(interactor, .resetPassword(email: .any, willThrow: noInternetError)) | ||
|
||
var isRecoveryPassword = true | ||
let binding = Binding(get: { | ||
return isRecoveryPassword | ||
}, set: { value in | ||
isRecoveryPassword = value | ||
}) | ||
|
||
await viewModel.resetPassword(email: "[email protected]", isRecoveryPassord: binding) | ||
|
||
Verify(interactor, 1, .resetPassword(email: .any)) | ||
|
||
XCTAssertEqual(viewModel.errorMessage, CoreLocalization.Error.slowOrNoInternetConnection) | ||
XCTAssertEqual(viewModel.isShowProgress, false) | ||
XCTAssertEqual(isRecoveryPassword, true) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.