Skip to content

Commit

Permalink
* [EACQAPW-5625] Fixes for Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanglushko committed Aug 8, 2023
1 parent 59676b4 commit 0b03f70
Show file tree
Hide file tree
Showing 12 changed files with 73 additions and 44 deletions.
10 changes: 5 additions & 5 deletions ASDKSample/ASDKSample/BuyProductsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,6 @@ import TinkoffASDKUI
import TinkoffASDKYandexPay
import UIKit

extension AdditionalData {
static let paymentInit = AdditionalData(data: ["/InitKey": "/InitValue"])
static let paymentFinish = AdditionalData(data: ["/FinishKey": "/FinishValue"])
}

class BuyProductsViewController: UIViewController {

enum TableViewCellType {
Expand Down Expand Up @@ -656,3 +651,8 @@ extension PaymentResult {
}
}
}

private extension AdditionalData {
static let paymentInit = AdditionalData(data: ["/InitKey": "/InitValue"])
static let paymentFinish = AdditionalData(data: ["/FinishKey": "/FinishValue"])
}
12 changes: 6 additions & 6 deletions ASDKSample/ASDKSample/RootViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,6 @@ import UIKit
import TinkoffASDKCore
import TinkoffASDKUI

extension AddCardOptions {
static let cardOptions = AddCardOptions(
attachCardData: AdditionalData(data: ["/AttachKey": "/AttachValue"])
)
}

struct Product: Codable {

var price: NSDecimalNumber
Expand Down Expand Up @@ -273,3 +267,9 @@ extension RootViewController {
present(alert, animated: true)
}
}

private extension AddCardOptions {
static let cardOptions = AddCardOptions(
attachCardData: AdditionalData(data: ["/AttachKey": "/AttachValue"])
)
}
6 changes: 6 additions & 0 deletions TinkoffASDKUI/TinkoffASDKUITests/Infrastructure/Fakes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -322,3 +322,9 @@ extension TinkoffPayMethod {
TinkoffPayMethod(version: "1.1.1")
}
}

extension AddCardOptions {
static func fake() -> Self {
Self(attachCardData: AdditionalData(data: ["/FakeKey-Card": "/FakeKey-Value"]))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@ final class AddCardControllerMock: IAddCardController {

// MARK: - addCard

typealias AddCardArguments = (cardData: CardData completion: (AddCardStateResult) -> Void)
typealias AddCardArguments = (cardData: CardData, completion: (AddCardStateResult) -> Void)

var addCardCallsCount = 0
var addCardReceivedArguments: AddCardArguments?
var addCardReceivedInvocations: [AddCardArguments?] = []
var addCardCompletionClosureInput: AddCardStateResult?

func addCard(cardData: CardData completion: @escaping (AddCardStateResult) -> Void) {
func addCard(cardData: CardData, completion: @escaping (AddCardStateResult) -> Void) {
addCardCallsCount += 1
let arguments = (options, completion)
let arguments = (cardData, completion)
addCardReceivedArguments = arguments
addCardReceivedInvocations.append(arguments)
if let addCardCompletionClosureInput = addCardCompletionClosureInput {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,34 +12,44 @@ final class AddNewCardAssemblyMock: IAddNewCardAssembly {

// MARK: - addNewCardView

typealias AddNewCardViewArguments = (customerKey: String, output: IAddNewCardPresenterOutput?, cardScannerDelegate: ICardScannerDelegate?)
typealias AddNewCardViewArguments = (customerKey: String, addCardOptions: AddCardOptions, output: IAddNewCardPresenterOutput?, cardScannerDelegate: ICardScannerDelegate?)

var addNewCardViewCallsCount = 0
var addNewCardViewReceivedArguments: AddNewCardViewArguments?
var addNewCardViewReceivedInvocations: [AddNewCardViewArguments?] = []
var addNewCardViewReturnValue: AddNewCardViewController!

func addNewCardView(customerKey: String, output: IAddNewCardPresenterOutput?, cardScannerDelegate: ICardScannerDelegate?) -> AddNewCardViewController {
func addNewCardView(
customerKey: String,
addCardOptions: AddCardOptions,
output: IAddNewCardPresenterOutput?,
cardScannerDelegate: ICardScannerDelegate?
) -> AddNewCardViewController {
addNewCardViewCallsCount += 1
let arguments = (customerKey, output, cardScannerDelegate)
let arguments = (customerKey, addCardOptions, output, cardScannerDelegate)
addNewCardViewReceivedArguments = arguments
addNewCardViewReceivedInvocations.append(arguments)
return addNewCardViewReturnValue
}

// MARK: - addNewCardNavigationController

typealias AddNewCardNavigationControllerArguments = (customerKey: String, cardScannerDelegate: ICardScannerDelegate?, onViewWasClosed: ((AddCardResult) -> Void)?)
typealias AddNewCardNavigationControllerArguments = (customerKey: String, addCardOptions: AddCardOptions, cardScannerDelegate: ICardScannerDelegate?, onViewWasClosed: ((AddCardResult) -> Void)?)

var addNewCardNavigationControllerCallsCount = 0
var addNewCardNavigationControllerReceivedArguments: AddNewCardNavigationControllerArguments?
var addNewCardNavigationControllerReceivedInvocations: [AddNewCardNavigationControllerArguments?] = []
var addNewCardNavigationControllerOnViewWasClosedClosureInput: AddCardResult?
var addNewCardNavigationControllerReturnValue: UINavigationController!

func addNewCardNavigationController(customerKey: String, cardScannerDelegate: ICardScannerDelegate?, onViewWasClosed: ((AddCardResult) -> Void)?) -> UINavigationController {
func addNewCardNavigationController(
customerKey: String,
addCardOptions: AddCardOptions,
cardScannerDelegate: ICardScannerDelegate?,
onViewWasClosed: ((AddCardResult) -> Void)?
) -> UINavigationController {
addNewCardNavigationControllerCallsCount += 1
let arguments = (customerKey, cardScannerDelegate, onViewWasClosed)
let arguments = (customerKey, addCardOptions, cardScannerDelegate, onViewWasClosed)
addNewCardNavigationControllerReceivedArguments = arguments
addNewCardNavigationControllerReceivedInvocations.append(arguments)
if let addNewCardNavigationControllerOnViewWasClosedClosureInput = addNewCardNavigationControllerOnViewWasClosedClosureInput {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ extension CardFieldInputMock {
underlyingCvc = "111"
underlyingExpiration = "0928"
underlyingCardData = CardData(
cardNumber: underlyingCardNumber,
expiration: underlyingExpiration,
pan: underlyingCardNumber,
validThru: underlyingExpiration,
cvc: underlyingCvc
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@ final class CardsControllerAssemblyMock: ICardsControllerAssembly {

// MARK: - cardsController

typealias CardsControllerArguments = String
typealias CardsControllerArguments = (customerKey: String, addCardOptions: AddCardOptions)

var cardsControllerCallsCount = 0
var cardsControllerReceivedArguments: CardsControllerArguments?
var cardsControllerReceivedInvocations: [CardsControllerArguments?] = []
var cardsControllerReturnValue: ICardsController!

func cardsController(customerKey: String) -> ICardsController {
func cardsController(customerKey: String, addCardOptions: AddCardOptions) -> ICardsController {
cardsControllerCallsCount += 1
let arguments = customerKey
let arguments = (customerKey, addCardOptions)
cardsControllerReceivedArguments = arguments
cardsControllerReceivedInvocations.append(arguments)
return cardsControllerReturnValue
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@ final class CardsControllerMock: ICardsController {

// MARK: - addCard

typealias AddCardArguments = (cardData: CardData completion: (AddCardResult) -> Void)
typealias AddCardArguments = (cardData: CardData, completion: (AddCardResult) -> Void)

var addCardCallsCount = 0
var addCardReceivedArguments: AddCardArguments?
var addCardReceivedInvocations: [AddCardArguments?] = []
var addCardCompletionClosureInput: AddCardResult?

func addCard(cardData: CardData completion: @escaping (AddCardResult) -> Void) {
func addCard(cardData: CardData, completion: @escaping (AddCardResult) -> Void) {
addCardCallsCount += 1
let arguments = (options, completion)
let arguments = (cardData, completion)
addCardReceivedArguments = arguments
addCardReceivedInvocations.append(arguments)
if let addCardCompletionClosureInput = addCardCompletionClosureInput {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,17 @@ final class AddCardControllerTests: BaseTestCase {

// then
XCTAssertEqual(addCardServiceMock.getAddCardStateCallsCount, 1)
guard let dataParameter = addCardServiceMock.attachCardReceivedArguments?.data.data else {
XCTFail()
return
}
switch dataParameter {
case let .threeDsBrowser(finishAuthorizeDataWrapper):
let keysSet = finishAuthorizeDataWrapper.additionalData
let addCardKeys = AddCardOptions.fake().attachCardData
XCTAssertEqual(keysSet, addCardKeys)
default: XCTFail()
}
}

func test_AttachCard_checkType_HoldOrNo() {
Expand Down Expand Up @@ -219,7 +230,7 @@ final class AddCardControllerTests: BaseTestCase {
addCardServiceMock.addCardCompletionClosureInput = .failure(TestsError.basic)

// when
sut.addCard(options: cardOptions, completion: { result in
sut.addCard(cardData: cardOptions, completion: { result in
if case let .failed(error) = result, error is TestsError {
didReturnError = true
}
Expand All @@ -239,7 +250,7 @@ final class AddCardControllerTests: BaseTestCase {
addCardServiceMock.addCardCompletionClosureInput = .failure(TestsError.basic)

// when
sut.addCard(options: CardData.fake(), completion: { result in })
sut.addCard(cardData: CardData.fake(), completion: { result in })

// then
XCTAssertEqual(addCardServiceMock.addCardCallsCount, 1)
Expand Down Expand Up @@ -331,7 +342,7 @@ final class AddCardControllerTests: BaseTestCase {
var receivedExpectedError = false

// when
sut.addCard(options: CardData.fake(), completion: { result in
sut.addCard(cardData: CardData.fake(), completion: { result in
if case let .failed(error) = result, let castedError = error as? AddCardController.Error {
if case .missingPaymentIdFor3DSFlow = castedError {
receivedExpectedError = true
Expand All @@ -352,7 +363,7 @@ final class AddCardControllerTests: BaseTestCase {
var receivedExpectedError = false

// when
sut.addCard(options: CardData.fake(), completion: { result in
sut.addCard(cardData: CardData.fake(), completion: { result in
if case let .failed(error) = result, let castedError = error as? AddCardController.Error {
if case .missingPaymentIdFor3DSFlow = castedError {
receivedExpectedError = true
Expand Down Expand Up @@ -639,6 +650,7 @@ extension AddCardControllerTests {
webFlowController: threeDSWebFlowControllerMock,
threeDSService: acquiringThreeDsServiceMock,
customerKey: "key",
addCardOptions: .fake(),
checkType: checkType,
tdsController: tdsControllerMock
)
Expand All @@ -652,7 +664,7 @@ extension AddCardControllerTests {
)

// when
sut.addCard(options: CardData.fake(), completion: addCardCompletion)
sut.addCard(cardData: CardData.fake(), completion: addCardCompletion)
// then
XCTAssertEqual(addCardServiceMock.addCardCallsCount, 1)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ final class AddNewCardPresenterTests: BaseTestCase {
viewMock = AddNewCardViewMock()

sut = AddNewCardPresenter(
addCardOptions: .fake(),
cardsController: cardsControllerMock,
output: outputMock,
onViewWasClosed: { [weak self] result in
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,7 @@ final class CardFieldPresenterTests: BaseTestCase {
sut.didFillField(type: .expiration, text: expiration, filled: true)
sut.didFillField(type: .cvc, text: cvc, filled: true)

let expectedCardData = CardData(cardNumber: cardNumber, expiration: expiration, cvc: cvc)
let expectedCardData = CardData(pan: cardNumber, validThru: expiration, cvc: cvc)

// when
let cardData = sut.cardData
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ final class CardsControllerTests: BaseTestCase {
addCardControllerMock.addCardCompletionClosureInput = .succeded(.fake(status: .authorized))

// when
sut.addCard(options: CardData.fake(), completion: { _ in })
sut.addCard(cardData: CardData.fake(), completion: { _ in })

// then
XCTAssertEqual(cardServiceMock.getCardListCallsCount, 1)
Expand All @@ -78,7 +78,7 @@ final class CardsControllerTests: BaseTestCase {
DispatchQueueMock.performOnMainBlockShouldExecute = true

// when
sut.addCard(options: CardData.fake(), completion: { result in
sut.addCard(cardData: CardData.fake(), completion: { result in
guard case .cancelled = result else { return }
mappedResultToCancelled = true
})
Expand All @@ -100,7 +100,7 @@ final class CardsControllerTests: BaseTestCase {
DispatchQueueMock.performOnMainBlockShouldExecute = true

// when
sut.addCard(options: CardData.fake(), completion: { result in
sut.addCard(cardData: CardData.fake(), completion: { result in
guard case let .failed(error) = result, error is TestsError else { return }
mappedResultToFailure = true
})
Expand All @@ -125,7 +125,7 @@ final class CardsControllerTests: BaseTestCase {
DispatchQueueMock.performOnMainBlockShouldExecute = true

// when
sut.addCard(options: CardData.fake(), completion: { result in
sut.addCard(cardData: CardData.fake(), completion: { result in
if case let .failed(error) = result, error is TestsError {
didReturnError = true
}
Expand Down Expand Up @@ -332,11 +332,11 @@ final class CardsControllerTests: BaseTestCase {
addCardControllerMock.addCardCompletionClosureInput = .succeded(payload)

// when
sut.addCard(options: cardOptions, completion: completion)
sut.addCard(cardData: cardOptions, completion: completion)

// then
XCTAssertEqual(addCardControllerMock.addCardCallsCount, 1)
XCTAssertEqual(addCardControllerMock.addCardReceivedArguments?.options, cardOptions)
XCTAssertEqual(addCardControllerMock.addCardReceivedArguments?.cardData, cardOptions)
XCTAssertEqual(addCardResult, .failed(error))
XCTAssertEqual(expectedErrorText, error.errorDescription)
XCTAssertEqual(cardServiceMock.getCardListCallsCount, 0)
Expand Down Expand Up @@ -370,11 +370,11 @@ final class CardsControllerTests: BaseTestCase {
cardServiceMock.getCardListCompletionClosureInput = .success(cards)

// when
sut.addCard(options: cardOptions, completion: completion)
sut.addCard(cardData: cardOptions, completion: completion)

// then
XCTAssertEqual(addCardControllerMock.addCardCallsCount, 1)
XCTAssertEqual(addCardControllerMock.addCardReceivedArguments?.options, cardOptions)
XCTAssertEqual(addCardControllerMock.addCardReceivedArguments?.cardData, cardOptions)
XCTAssertEqual(addCardResult, .failed(error))
XCTAssertEqual(expectedErrorText, error.errorDescription)
XCTAssertEqual(cardServiceMock.getCardListCallsCount, 1)
Expand Down Expand Up @@ -407,11 +407,11 @@ final class CardsControllerTests: BaseTestCase {
cardServiceMock.getCardListCompletionClosureInput = .success(cards)

// when
sut.addCard(options: cardOptions, completion: completion)
sut.addCard(cardData: cardOptions, completion: completion)

// then
XCTAssertEqual(addCardControllerMock.addCardCallsCount, 1)
XCTAssertEqual(addCardControllerMock.addCardReceivedArguments?.options, cardOptions)
XCTAssertEqual(addCardControllerMock.addCardReceivedArguments?.cardData, cardOptions)
XCTAssertEqual(addCardResult, .succeded(sberFakeCard))
XCTAssertEqual(cardServiceMock.getCardListCallsCount, 1)
XCTAssertEqual(cardServiceMock.getCardListReceivedArguments?.data, expectedData)
Expand Down

0 comments on commit 0b03f70

Please sign in to comment.