-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: Remove ShippingOptions from tests and Debug App (#1014)
Remove Shippingoptions from tests and Debug App
- Loading branch information
Showing
3 changed files
with
169 additions
and
166 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
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
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 |
---|---|---|
|
@@ -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", | ||
|