Skip to content

Commit

Permalink
fix(GiniMerchantSDK): fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
zladzeyka committed Aug 1, 2024
1 parent d682fb7 commit 827b0fd
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import UIKit
import GiniUtilites

public final class PaymentComponentView: UIView {
private let viewModel: PaymentComponentViewModel
let viewModel: PaymentComponentViewModel

private let contentStackView = EmptyStackView(orientation: .vertical)
private let selectYourBankView = EmptyView()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import UIKit

public final class PaymentInfoViewController: UIViewController {
private let viewModel: PaymentInfoViewModel
let viewModel: PaymentInfoViewModel

private lazy var scrollView: UIScrollView = {
let scrollView = UIScrollView()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public final class PaymentInfoViewModel {
}

private func setupQuestions() {
for index in 0 ... strings.questions.count {
for index in 0 ... strings.questions.count-1 {
let answerAttributedString = answerWithAttributes(answer: strings.answers[index])
let questionSection = FAQSection(title: strings.questions[index],
description: textWithLinks(linkFont: configuration.linksFont, attributedString: answerAttributedString),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ public final class PaymentReviewViewController: UIViewController, UIGestureRecog
let model: PaymentReviewModel
private let selectedPaymentProvider: GiniHealthAPILibrary.PaymentProvider

private init(viewModel: PaymentReviewModel,
selectedPaymentProvider: GiniHealthAPILibrary.PaymentProvider) {
init(viewModel: PaymentReviewModel,
selectedPaymentProvider: GiniHealthAPILibrary.PaymentProvider) {
self.model = viewModel
self.selectedPaymentProvider = selectedPaymentProvider
super.init(nibName: nil, bundle: nil)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import UIKit
@testable import GiniMerchantSDK
@testable import GiniPaymentComponents
@testable import GiniHealthAPILibrary

class MockPaymentComponents: PaymentComponentsProtocol {
Expand Down Expand Up @@ -64,24 +65,38 @@ class MockPaymentComponents: PaymentComponentsProtocol {
}

func paymentView(documentId: String) -> UIView {
let viewModel = PaymentComponentViewModel(paymentProvider: selectedPaymentProvider, giniMerchantConfiguration: giniMerchantConfiguration)
let viewModel = PaymentComponentViewModel(paymentProvider: selectedPaymentProvider?.toHealthPaymentProvider(),
primaryButtonConfiguration: giniMerchant.primaryButtonConfiguration,
secondaryButtonConfiguration: giniMerchant.secondaryButtonConfiguration,
configuration: giniMerchant.paymentComponentsConfiguration,
strings: giniMerchant.paymentComponentsStrings,
poweredByGiniConfiguration: giniMerchant.poweredByGiniConfiguration,
poweredByGiniStrings: giniMerchant.poweredByGiniStrings,
moreInformationConfiguration: giniMerchant.moreInformationConfiguration,
moreInformationStrings: giniMerchant.moreInformationStrings,
minimumButtonsHeight: giniMerchant.paymentComponentButtonsHeight)
viewModel.documentId = documentId
let view = PaymentComponentView()
view.viewModel = viewModel
let view = PaymentComponentView(viewModel: viewModel)
return view
}

func bankSelectionBottomSheet() -> UIViewController {
let paymentProvidersBottomViewModel = BanksBottomViewModel(paymentProviders: paymentProviders,
selectedPaymentProvider: selectedPaymentProvider)
let paymentProvidersBottomView = BanksBottomView(viewModel: paymentProvidersBottomViewModel)
let paymentProvidersBottomViewModel = BanksBottomViewModel(paymentProviders: paymentProviders.map { $0.toHealthPaymentProvider() },
selectedPaymentProvider: selectedPaymentProvider?.toHealthPaymentProvider(),
configuration: giniMerchant.banksBottomConfiguration,
strings: giniMerchant.banksBottomStrings,
poweredByGiniConfiguration: giniMerchant.poweredByGiniConfiguration,
poweredByGiniStrings: giniMerchant.poweredByGiniStrings,
moreInformationConfiguration: giniMerchant.moreInformationConfiguration,
moreInformationStrings: giniMerchant.moreInformationStrings)
let paymentProvidersBottomView = BanksBottomView(viewModel: paymentProvidersBottomViewModel, bottomSheetConfiguration: giniMerchant.bottomSheetConfiguration)
return paymentProvidersBottomView
}

func loadPaymentReviewScreenFor(documentID: String, trackingDelegate: (any GiniMerchantTrackingDelegate)?, completion: @escaping (UIViewController?, GiniMerchantError?) -> Void) {
switch documentID {
case MockSessionManager.payableDocumentID:
completion(PaymentReviewViewController(), nil)
completion(UIViewController(), nil)
case MockSessionManager.missingDocumentID:
completion(nil, .apiError(GiniError.decorator(.noResponse)))
default:
Expand All @@ -90,14 +105,18 @@ class MockPaymentComponents: PaymentComponentsProtocol {
}

func paymentInfoViewController() -> UIViewController {
let paymentInfoViewController = PaymentInfoViewController()
let paymentInfoViewModel = PaymentInfoViewModel(paymentProviders: paymentProviders)
paymentInfoViewController.viewModel = paymentInfoViewModel
let paymentInfoViewModel = PaymentInfoViewModel(paymentProviders: paymentProviders.map { $0.toHealthPaymentProvider() },
configuration: giniMerchant.paymentInfoConfiguration,
strings: giniMerchant.paymentInfoStrings,
poweredByGiniConfiguration: giniMerchant.poweredByGiniConfiguration,
poweredByGiniStrings: giniMerchant.poweredByGiniStrings)
let paymentInfoViewController = PaymentInfoViewController(viewModel: paymentInfoViewModel)
return paymentInfoViewController
}

func paymentViewBottomSheet(documentID: String) -> UIViewController {
let paymentComponentBottomView = PaymentComponentBottomView(paymentView: paymentView(documentId: documentID))
let paymentComponentBottomView = PaymentComponentBottomView(paymentView: paymentView(documentId: documentID),
bottomSheetConfiguration: giniMerchant.bottomSheetConfiguration)
return paymentComponentBottomView
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ import XCTest
@testable import GiniUtilites
@testable import GiniMerchantSDK
@testable import GiniHealthAPILibrary
@testable import GiniPaymentComponents

final class PaymentComponentsControllerTests: XCTestCase {
private var giniHealthAPI: GiniHealthAPI!
private var giniMerchant: GiniMerchant!
private var mockPaymentComponentsController: PaymentComponentsProtocol!
private let giniMerchantConfiguration = GiniMerchantConfiguration.shared
private let versionAPI = 4
Expand All @@ -22,12 +24,13 @@ final class PaymentComponentsControllerTests: XCTestCase {
let documentService = DefaultDocumentService(sessionManager: sessionManagerMock, apiVersion: versionAPI)
let paymentService = PaymentService(sessionManager: sessionManagerMock, apiVersion: versionAPI)
giniHealthAPI = GiniHealthAPI(documentService: documentService, paymentService: paymentService)
let giniMerchant = GiniMerchant(giniApiLib: giniHealthAPI)
giniMerchant = GiniMerchant(giniApiLib: giniHealthAPI)
mockPaymentComponentsController = MockPaymentComponents(giniMerchant: giniMerchant)
}

override func tearDown() {
giniHealthAPI = nil
giniMerchant = nil
mockPaymentComponentsController = nil
super.tearDown()
}
Expand Down Expand Up @@ -80,9 +83,18 @@ final class PaymentComponentsControllerTests: XCTestCase {
func testPaymentView_ReturnsView() {
// Given
let documentId = "123456"
let expectedViewModel = PaymentComponentViewModel(paymentProvider: nil, giniMerchantConfiguration: giniMerchantConfiguration)
let expectedView = PaymentComponentView()
expectedView.viewModel = expectedViewModel
let expectedViewModel = PaymentComponentViewModel(paymentProvider: nil,
primaryButtonConfiguration: giniMerchant.primaryButtonConfiguration,
secondaryButtonConfiguration: giniMerchant.secondaryButtonConfiguration,
configuration: giniMerchant.paymentComponentsConfiguration,
strings: giniMerchant.paymentComponentsStrings,
poweredByGiniConfiguration: giniMerchant.poweredByGiniConfiguration,
poweredByGiniStrings: giniMerchant.poweredByGiniStrings,
moreInformationConfiguration: giniMerchant.moreInformationConfiguration,
moreInformationStrings: giniMerchant.moreInformationStrings,
minimumButtonsHeight: giniMerchant.paymentComponentButtonsHeight)

let expectedView = PaymentComponentView(viewModel: expectedViewModel)

// When
let view = mockPaymentComponentsController.paymentView(documentId: documentId)
Expand All @@ -93,7 +105,7 @@ final class PaymentComponentsControllerTests: XCTestCase {
XCTFail("Error finding correct view.")
return
}
XCTAssertEqual(view.viewModel?.documentId, documentId)
XCTAssertEqual(view.viewModel.documentId, documentId)
}

func testBankSelectionBottomSheet_ReturnsViewController() {
Expand Down Expand Up @@ -124,7 +136,6 @@ final class PaymentComponentsControllerTests: XCTestCase {
// Then
XCTAssertNil(receivedError)
XCTAssertNotNil(receivedViewController)
XCTAssertTrue(receivedViewController is PaymentReviewViewController)
}

func testLoadPaymentReviewScreenFor_Failure() {
Expand Down Expand Up @@ -156,10 +167,7 @@ final class PaymentComponentsControllerTests: XCTestCase {
return
}
XCTAssertNotNil(paymentInfoVC.viewModel)
guard let paymentInfoViewModel = paymentInfoVC.viewModel else {
XCTFail("Error finding payment info viewModel.")
return
}
let paymentInfoViewModel = paymentInfoVC.viewModel
XCTAssertEqual(paymentInfoViewModel.paymentProviders, [])
}

Expand All @@ -171,10 +179,19 @@ final class PaymentComponentsControllerTests: XCTestCase {
}

let expectedPaymentProviders = loadProviders(fileName: "sortedBanks")

let bottomViewModel = BanksBottomViewModel(paymentProviders: givenPaymentProviders, selectedPaymentProvider: nil, urlOpener: URLOpener(MockUIApplication(canOpen: false)))


let bottomViewModel = BanksBottomViewModel(paymentProviders: givenPaymentProviders.map { $0.toHealthPaymentProvider() },
selectedPaymentProvider: nil,
configuration: giniMerchant.banksBottomConfiguration,
strings: giniMerchant.banksBottomStrings,
poweredByGiniConfiguration: giniMerchant.poweredByGiniConfiguration,
poweredByGiniStrings: giniMerchant.poweredByGiniStrings,
moreInformationConfiguration: giniMerchant.moreInformationConfiguration,
moreInformationStrings: giniMerchant.moreInformationStrings,
urlOpener: URLOpener(MockUIApplication(canOpen: false)))


XCTAssertEqual(bottomViewModel.paymentProviders.count, 11)
XCTAssertEqual(bottomViewModel.paymentProviders.map { $0.paymentProvider }, expectedPaymentProviders)
XCTAssertEqual(bottomViewModel.paymentProviders.map { PaymentProvider(healthPaymentProvider: $0.paymentProvider) }, expectedPaymentProviders)
}
}

0 comments on commit 827b0fd

Please sign in to comment.