Skip to content

Commit

Permalink
test: Remove ShippingOptions from tests and Debug App (#1014)
Browse files Browse the repository at this point in the history
Remove Shippingoptions from tests and Debug App
  • Loading branch information
NQuinn27 authored Oct 4, 2024
1 parent dcb6b95 commit 57caeb3
Show file tree
Hide file tree
Showing 3 changed files with 169 additions and 166 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ class MerchantSessionAndSettingsViewController: UIViewController {
//Below are gated by applePayCaptureShippingDetails, default to on when above is true
var applePayCaptureShippingAddress = true
var applePayRequireShippingMethod = true
var applePayAdditionalContactFields: [PrimerApplePayOptions.ShippingOptions.AdditionalShippingContactField]? = [.name, .emailAddress, .phoneNumber]
// var applePayAdditionalContactFields: [PrimerApplePayOptions.ShippingOptions.AdditionalShippingContactField]? = [.name, .emailAddress, .phoneNumber]

func setAccessibilityIds() {
self.view.accessibilityIdentifier = "Background View"
Expand Down Expand Up @@ -429,49 +429,49 @@ class MerchantSessionAndSettingsViewController: UIViewController {
}

@IBAction func applePayShippingContactNameSwitchChanged(_ sender: UISwitch) {
if sender.isOn {
var fields = applePayAdditionalContactFields ?? []
if !fields.contains(.name) {
fields.append(.name)
}
applePayAdditionalContactFields = fields
} else {
applePayAdditionalContactFields?.removeAll(where: { $0 == .name })
if applePayAdditionalContactFields?.isEmpty == true {
applePayAdditionalContactFields = nil
}
}
// if sender.isOn {
// var fields = applePayAdditionalContactFields ?? []
// if !fields.contains(.name) {
// fields.append(.name)
// }
// applePayAdditionalContactFields = fields
// } else {
// applePayAdditionalContactFields?.removeAll(where: { $0 == .name })
// if applePayAdditionalContactFields?.isEmpty == true {
// applePayAdditionalContactFields = nil
// }
// }
}


@IBAction func applePayShippingContactEmailField(_ sender: UISwitch) {
if sender.isOn {
var fields = applePayAdditionalContactFields ?? []
if !fields.contains(.emailAddress) {
fields.append(.emailAddress)
}
applePayAdditionalContactFields = fields
} else {
applePayAdditionalContactFields?.removeAll(where: { $0 == .emailAddress })
if applePayAdditionalContactFields?.isEmpty == true {
applePayAdditionalContactFields = nil
}
}
// if sender.isOn {
// var fields = applePayAdditionalContactFields ?? []
// if !fields.contains(.emailAddress) {
// fields.append(.emailAddress)
// }
// applePayAdditionalContactFields = fields
// } else {
// applePayAdditionalContactFields?.removeAll(where: { $0 == .emailAddress })
// if applePayAdditionalContactFields?.isEmpty == true {
// applePayAdditionalContactFields = nil
// }
// }
}

@IBAction func applePayShippingContactPhoneSwitchChanged(_ sender: UISwitch) {
if sender.isOn {
var fields = applePayAdditionalContactFields ?? []
if !fields.contains(.phoneNumber) {
fields.append(.phoneNumber)
}
applePayAdditionalContactFields = fields
} else {
applePayAdditionalContactFields?.removeAll(where: { $0 == .phoneNumber })
if applePayAdditionalContactFields?.isEmpty == true {
applePayAdditionalContactFields = nil
}
}
// if sender.isOn {
// var fields = applePayAdditionalContactFields ?? []
// if !fields.contains(.phoneNumber) {
// fields.append(.phoneNumber)
// }
// applePayAdditionalContactFields = fields
// } else {
// applePayAdditionalContactFields?.removeAll(where: { $0 == .phoneNumber })
// if applePayAdditionalContactFields?.isEmpty == true {
// applePayAdditionalContactFields = nil
// }
// }
}

@IBAction func applePayCheckProvidedNetworksSwitchValueChanged(_ sender: UISwitch) {
Expand Down
44 changes: 22 additions & 22 deletions Tests/Primer/ApplePay/ApplePayPresentationManagerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,28 +56,28 @@ final class ApplePayPresentationManagerTests: XCTestCase {
XCTAssertTrue(sut.isPresentable)
}

func testShippingContactFields() throws {
let additionalFields: [PrimerApplePayOptions.ShippingOptions.AdditionalShippingContactField] = [.name, .emailAddress, .phoneNumber]

var applePayOptions = PrimerApplePayOptions(merchantIdentifier: "merchant_id",
merchantName: "merchant_name",
checkProvidedNetworks: true,
shippingOptions: .init(isCaptureShippingAddressEnabled: true,
additionalShippingContactFields: additionalFields, requireShippingMethod: true))
var shippingFields = sut.shippingContactFields(applePayOptions: applePayOptions)

XCTAssertEqual(shippingFields, [.name, .postalAddress, .emailAddress, .phoneNumber])

applePayOptions = PrimerApplePayOptions(merchantIdentifier: "merchant_id",
merchantName: "merchant_name",
checkProvidedNetworks: true,
shippingOptions: .init(isCaptureShippingAddressEnabled: true,
additionalShippingContactFields: nil, requireShippingMethod: true))

shippingFields = sut.shippingContactFields(applePayOptions: applePayOptions)

XCTAssertEqual(shippingFields, [.postalAddress])
}
// func testShippingContactFields() throws {
// let additionalFields: [PrimerApplePayOptions.ShippingOptions.AdditionalShippingContactField] = [.name, .emailAddress, .phoneNumber]
//
// var applePayOptions = PrimerApplePayOptions(merchantIdentifier: "merchant_id",
// merchantName: "merchant_name",
// checkProvidedNetworks: true,
// shippingOptions: .init(isCaptureShippingAddressEnabled: true,
// additionalShippingContactFields: additionalFields, requireShippingMethod: true))
// var shippingFields = sut.shippingContactFields(applePayOptions: applePayOptions)
//
// XCTAssertEqual(shippingFields, [.name, .postalAddress, .emailAddress, .phoneNumber])
//
// applePayOptions = PrimerApplePayOptions(merchantIdentifier: "merchant_id",
// merchantName: "merchant_name",
// checkProvidedNetworks: true,
// shippingOptions: .init(isCaptureShippingAddressEnabled: true,
// additionalShippingContactFields: nil, requireShippingMethod: true))
//
// shippingFields = sut.shippingContactFields(applePayOptions: applePayOptions)
//
// XCTAssertEqual(shippingFields, [.postalAddress])
// }

func testErrorForDisplay() {
let error = sut.errorForDisplay
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -418,113 +418,116 @@ final class ApplePayTokenizationViewModelTests: XCTestCase {
}
}

func testProcessShippingContactChange() async throws {
let contact = PKContact()
var nameParts = PersonNameComponents()
nameParts.givenName = "John"
nameParts.familyName = "Doe"
contact.name = nameParts

contact.phoneNumber = CNPhoneNumber(stringValue: "1234567890")

contact.emailAddress = "[email protected]"

let address = CNMutablePostalAddress()
address.street = "123 Apple Street"
address.city = "Cupertino"
address.state = "CA"
address.postalCode = "95014"
address.country = "United States"
contact.postalAddress = address

let apiClient = MockPrimerAPIClient()
PrimerAPIConfigurationModule.apiClient = apiClient


guard var config = PrimerAPIConfiguration.current else {
XCTFail("Unable to generate configuration")
return
}
config.checkoutModules = checkoutModules

config.clientSession = ClientSession.APIResponse(
clientSessionId: nil,
paymentMethod: nil,
order: .init(id: "OrderId",
merchantAmount: nil,
totalOrderAmount: 1200,
totalTaxAmount: nil,
countryCode: .init(rawValue: "GB"),
currencyCode: .init(code: "GBP", decimalDigits: 2),
fees: nil,
lineItems: [
.init(itemId: "123",
quantity: 1,
amount: 1000,
discountAmount: nil,
name: "Fancy Shoes",
description: "Some nice shoes",
taxAmount: nil,
taxCode: nil,
productType: nil)
],
shippingMethod:
ClientSession.Order.ShippingMethod(amount: 200,
methodId: "Shipping",
methodName: "Shipping",
methodDescription: "Description")
),
customer: nil,
testId: nil)


let sut = ApplePayTokenizationViewModel(config: PrimerPaymentMethod(id: "APPLE_PAY",
implementationType: .nativeSdk,
type: "APPLE_PAY",
name: "Apple Pay",
processorConfigId: nil,
surcharge: nil,
options: nil,
displayMetadata: nil))

apiClient.fetchConfigurationWithActionsResult = (config, nil)
PrimerAPIConfigurationModule.apiConfiguration = config

// Test happy path
let update = await sut.processShippingContactChange(contact)

XCTAssertNotNil(update.paymentSummaryItems)
XCTAssertNotNil(update.shippingMethods)

//Test error when no Address
contact.postalAddress = nil
let update2 = await sut.processShippingContactChange(contact)
XCTAssertNotNil(update2.errors)

//Test Error when no shipping methods and Settings requireShippingMethod
let settings = PrimerSettings(paymentMethodOptions:
PrimerPaymentMethodOptions(applePayOptions:
PrimerApplePayOptions(merchantIdentifier: "merchant_id", merchantName: "merchant_name", shippingOptions: .init(isCaptureShippingAddressEnabled: true, requireShippingMethod: true))
)
)
DependencyContainer.register(settings as PrimerSettingsProtocol)

contact.postalAddress = address
config.checkoutModules = nil
apiClient.fetchConfigurationWithActionsResult = (config, nil)
PrimerAPIConfigurationModule.apiConfiguration = config

let update3 = await sut.processShippingContactChange(contact)
XCTAssertNotNil(update3.errors)

//Test error when no ClientSession
config.clientSession = nil
apiClient.fetchConfigurationWithActionsResult = (config, nil)
PrimerAPIConfigurationModule.apiConfiguration = config

let update4 = await sut.processShippingContactChange(contact)
XCTAssertNotNil(update4.errors)
}
// func testProcessShippingContactChange() async throws {
// let contact = PKContact()
// var nameParts = PersonNameComponents()
// nameParts.givenName = "John"
// nameParts.familyName = "Doe"
// contact.name = nameParts
//
// contact.phoneNumber = CNPhoneNumber(stringValue: "1234567890")
//
// contact.emailAddress = "[email protected]"
//
// let address = CNMutablePostalAddress()
// address.street = "123 Apple Street"
// address.city = "Cupertino"
// address.state = "CA"
// address.postalCode = "95014"
// address.country = "United States"
// contact.postalAddress = address
//
// let apiClient = MockPrimerAPIClient()
// PrimerAPIConfigurationModule.apiClient = apiClient
//
//
// guard var config = PrimerAPIConfiguration.current else {
// XCTFail("Unable to generate configuration")
// return
// }
// config.checkoutModules = checkoutModules
//
// config.clientSession = ClientSession.APIResponse(
// clientSessionId: nil,
// paymentMethod: nil,
// order: .init(id: "OrderId",
// merchantAmount: nil,
// totalOrderAmount: 1200,
// totalTaxAmount: nil,
// countryCode: .init(rawValue: "GB"),
// currencyCode: .init(code: "GBP", decimalDigits: 2),
// fees: nil,
// lineItems: [
// .init(itemId: "123",
// quantity: 1,
// amount: 1000,
// discountAmount: nil,
// name: "Fancy Shoes",
// description: "Some nice shoes",
// taxAmount: nil,
// taxCode: nil,
// productType: nil)
// ],
// shippingMethod:
// ClientSession.Order.ShippingMethod(amount: 200,
// methodId: "Shipping",
// methodName: "Shipping",
// methodDescription: "Description")
// ),
// customer: nil,
// testId: nil)
//
//
// let sut = ApplePayTokenizationViewModel(config: PrimerPaymentMethod(id: "APPLE_PAY",
// implementationType: .nativeSdk,
// type: "APPLE_PAY",
// name: "Apple Pay",
// processorConfigId: nil,
// surcharge: nil,
// options: nil,
// displayMetadata: nil))
//
// apiClient.fetchConfigurationWithActionsResult = (config, nil)
// PrimerAPIConfigurationModule.apiConfiguration = config
//
// // Test happy path
// let update = await sut.processShippingContactChange(contact)
//
// XCTAssertNotNil(update.paymentSummaryItems)
// XCTAssertNotNil(update.shippingMethods)
//
// //Test error when no Address
// contact.postalAddress = nil
// let update2 = await sut.processShippingContactChange(contact)
// XCTAssertNotNil(update2.errors)
//
// //Test Error when no shipping methods and Settings requireShippingMethod
// let settings = PrimerSettings(paymentMethodOptions:
// PrimerPaymentMethodOptions(applePayOptions:
// PrimerApplePayOptions(merchantIdentifier: "merchant_id",
// merchantName: "merchant_name",
// shippingOptions: .init(isCaptureShippingAddressEnabled: true,
// requireShippingMethod: true))
// )
// )
// DependencyContainer.register(settings as PrimerSettingsProtocol)
//
// contact.postalAddress = address
// config.checkoutModules = nil
// apiClient.fetchConfigurationWithActionsResult = (config, nil)
// PrimerAPIConfigurationModule.apiConfiguration = config
//
// let update3 = await sut.processShippingContactChange(contact)
// XCTAssertNotNil(update3.errors)
//
// //Test error when no ClientSession
// config.clientSession = nil
// apiClient.fetchConfigurationWithActionsResult = (config, nil)
// PrimerAPIConfigurationModule.apiConfiguration = config
//
// let update4 = await sut.processShippingContactChange(contact)
// XCTAssertNotNil(update4.errors)
// }

func testProcessShippingMethodChange() async throws {
let sut = ApplePayTokenizationViewModel(config: PrimerPaymentMethod(id: "APPLE_PAY",
Expand Down

0 comments on commit 57caeb3

Please sign in to comment.