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 f485ef1
Show file tree
Hide file tree
Showing 18 changed files with 92 additions and 57 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 {
}
}
}

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)
}
}

extension AddCardOptions {
static let cardOptions = AddCardOptions(
attachCardData: AdditionalData(data: ["/AttachKey": "/AttachValue"])
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ extension AddCardController {
completion: @escaping Completion
) {
let attachData = AttachCardData(
cardNumber: cardData.pan,
cardNumber: cardData.number,
expDate: cardData.validThru,
cvv: cardData.cvc,
requestKey: requestKey,
Expand Down Expand Up @@ -452,7 +452,7 @@ private extension Check3DSVersionData {
Check3DSVersionData(
paymentId: paymentId,
paymentSource: .cardNumber(
number: cardData.pan,
number: cardData.number,
expDate: cardData.validThru,
cvv: cardData.cvc
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public protocol IAddCardController: AnyObject {

/// Привязывает новую карту с заданными параметрами к пользователю
/// - Parameters:
/// - options: Опции добавления карты
/// - cardData: Данные карты
/// - completion: Замыкание с результатом привязки карты, вызывающееся на главном потоке
func addCard(cardData: CardData, completion: @escaping (AddCardStateResult) -> Void)
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import Foundation
/// Даннные карты
public struct CardData: Equatable {
/// Номер карты
public let pan: String
public let number: String
/// Срок годности карты в формате `MM/YY`
public let validThru: String
/// Трехзначный cvc-код
Expand All @@ -21,8 +21,8 @@ public struct CardData: Equatable {
/// - pan: Номер карты
/// - validThru: Срок годности карты в формате `MM/YY`
/// - cvc: Трехзначный cvc-код
public init(pan: String, validThru: String, cvc: String) {
self.pan = pan
public init(number: String, validThru: String, cvc: String) {
self.number = number
self.validThru = validThru
self.cvc = cvc
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public protocol ICardsController: AnyObject {
///
/// После успешной привязки `ICardController` сделает запрос на полный список карт для определения привязанной карты
/// - Parameters:
/// - options: Параметры привязки карты
/// - cardData: Данные карты
/// - completion: Замыкание с результатом привязки, вызывающееся на главном потоке
func addCard(cardData: CardData, completion: @escaping (AddCardResult) -> Void)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ extension AddNewCardPresenter: IAddNewCardPresenter {
guard cardFieldPresenter.validateWholeForm().isValid else { return }

let cardOptions = CardData(
pan: cardFieldPresenter.cardNumber,
number: cardFieldPresenter.cardNumber,
validThru: cardFieldPresenter.expiration,
cvc: cardFieldPresenter.cvc
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ final class CardFieldPresenter: ICardFieldViewOutput {

// MARK: Properties

var cardData: CardData { CardData(pan: cardNumber, validThru: expiration, cvc: cvc) }
var cardData: CardData { CardData(number: cardNumber, validThru: expiration, cvc: cvc) }

private(set) var validationResult = CardFieldValidationResult()

Expand Down
8 changes: 7 additions & 1 deletion TinkoffASDKUI/TinkoffASDKUITests/Infrastructure/Fakes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ extension CardList.Card {

extension CardData {
static func fake() -> Self {
CardData(pan: "123123123123", validThru: "0928", cvc: "123")
CardData(number: "123123123123", validThru: "0928", cvc: "123")
}
}

Expand Down 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,
number: 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 All @@ -117,7 +128,10 @@ final class AddCardControllerTests: BaseTestCase {

// then
XCTAssertEqual(addCardServiceMock.attachCardCallsCount, 1)
XCTAssertNil(addCardServiceMock.attachCardReceivedArguments?.data.data)
switch addCardServiceMock.attachCardReceivedArguments?.data.data {
case let .dictionary(additionalData): XCTAssertEqual(additionalData, AddCardOptions.fake().attachCardData)
default: XCTFail()
}
}

func test_3DSConfirmationInWebView_cancelled() {
Expand Down Expand Up @@ -214,12 +228,12 @@ final class AddCardControllerTests: BaseTestCase {
// given
var didReturnError = false
sut = createAddCardController(checkType: .check3DS)
let cardOptions = CardData(pan: "123123213", validThru: "0928", cvc: "123")
let cardOptions = CardData(number: "123123213", validThru: "0928", cvc: "123")
addCardServiceMock.addCardReturnValue = CancellableMock()
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 +253,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 +345,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 +366,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 @@ -627,9 +641,12 @@ extension AddCardControllerTests {
XCTAssertEqual(threeDSWebFlowControllerMock.complete3DSMethodCallsCount, 0)
XCTAssertEqual(threeDSDeviceInfoProviderMock.createThreeDsDataBrowserCallsCount, 0)
XCTAssertEqual(addCardServiceMock.attachCardCallsCount, 1)
XCTAssertNil(addCardServiceMock.attachCardReceivedArguments?.data.data)
XCTAssertEqual(addCardServiceMock.getAddCardStateCallsCount, 1)
XCTAssertTrue(addCardStateSucceded)
switch addCardServiceMock.attachCardReceivedArguments?.data.data {
case let .dictionary(additionalData): XCTAssertEqual(additionalData, AddCardOptions.fake().attachCardData)
default: XCTFail()
}
}

private func createAddCardController(checkType: PaymentCardCheckType) -> AddCardController {
Expand All @@ -639,6 +656,7 @@ extension AddCardControllerTests {
webFlowController: threeDSWebFlowControllerMock,
threeDSService: acquiringThreeDsServiceMock,
customerKey: "key",
addCardOptions: .fake(),
checkType: checkType,
tdsController: tdsControllerMock
)
Expand All @@ -652,7 +670,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(number: cardNumber, validThru: expiration, cvc: cvc)

// when
let cardData = sut.cardData
Expand Down
Loading

0 comments on commit f485ef1

Please sign in to comment.