From 9e214319b87c8bc3041462d2253056f86d56a5d5 Mon Sep 17 00:00:00 2001 From: Cameron Sabol Date: Thu, 9 Aug 2018 10:10:06 -0700 Subject: [PATCH] Cleanup and adds sanity checks to new unit tests --- Tests/Tests/STPAddCardViewControllerTest.m | 26 ++++++++++++------- .../STPShippingAddressViewControllerTest.m | 18 +++++++++---- 2 files changed, 30 insertions(+), 14 deletions(-) diff --git a/Tests/Tests/STPAddCardViewControllerTest.m b/Tests/Tests/STPAddCardViewControllerTest.m index 269c2a83c33..bb345cc5a19 100644 --- a/Tests/Tests/STPAddCardViewControllerTest.m +++ b/Tests/Tests/STPAddCardViewControllerTest.m @@ -14,6 +14,7 @@ #import "STPCard.h" #import "STPFixtures.h" #import "STPPaymentCardTextFieldCell.h" +#import "STPPostalCodeValidator.h" @interface STPAddCardViewController (Testing) @property (nonatomic) STPPaymentCardTextFieldCell *paymentCell; @@ -39,9 +40,6 @@ - (STPAddCardViewController *)buildAddCardViewController { return vc; } -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Warc-performSelector-leaks" - - (void)testPrefilledBillingAddress_removeAddress { STPPaymentConfiguration *config = [STPFixtures paymentConfiguration]; config.requiredBillingAddressFields = STPBillingAddressFieldsZip; @@ -54,18 +52,24 @@ - (void)testPrefilledBillingAddress_removeAddress { address.line1 = @"55 John St"; address.city = @"Harare"; address.postalCode = @"10002"; - address.country = @"ZW"; + address.country = @"ZW"; // Zimbabwe does not require zip codes, while the default locale for tests (US) does + // Sanity checks + XCTAssertFalse([STPPostalCodeValidator postalCodeIsRequiredForCountryCode:@"ZW"]); + XCTAssertTrue([STPPostalCodeValidator postalCodeIsRequiredForCountryCode:@"US"]); STPUserInformation *prefilledInfo = [[STPUserInformation alloc] init]; prefilledInfo.billingAddress = address; sut.prefilledInformation = prefilledInfo; - [sut loadView]; - [sut viewDidLoad]; + XCTAssertNoThrow([sut loadView]); + XCTAssertNoThrow([sut viewDidLoad]); } - (void)testPrefilledBillingAddress_addAddress { - [NSLocale stp_setCurrentLocale:[NSLocale localeWithLocaleIdentifier:@"en_ZW"]]; + [NSLocale stp_setCurrentLocale:[NSLocale localeWithLocaleIdentifier:@"en_ZW"]]; // Zimbabwe does not require zip codes, while the default locale for tests (US) does + // Sanity checks + XCTAssertFalse([STPPostalCodeValidator postalCodeIsRequiredForCountryCode:@"ZW"]); + XCTAssertTrue([STPPostalCodeValidator postalCodeIsRequiredForCountryCode:@"US"]); STPPaymentConfiguration *config = [STPFixtures paymentConfiguration]; config.requiredBillingAddressFields = STPBillingAddressFieldsZip; STPAddCardViewController *sut = [[STPAddCardViewController alloc] initWithConfiguration:config @@ -84,11 +88,15 @@ - (void)testPrefilledBillingAddress_addAddress { prefilledInfo.billingAddress = address; sut.prefilledInformation = prefilledInfo; - [sut loadView]; - [sut viewDidLoad]; + XCTAssertNoThrow([sut loadView]); + XCTAssertNoThrow([sut viewDidLoad]); [NSLocale stp_resetCurrentLocale]; } + +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Warc-performSelector-leaks" + - (void)testNextWithCreateTokenError { STPAddCardViewController *sut = [self buildAddCardViewController]; STPCardParams *expectedCardParams = [STPFixtures cardParams]; diff --git a/Tests/Tests/STPShippingAddressViewControllerTest.m b/Tests/Tests/STPShippingAddressViewControllerTest.m index 5b9fdbabf1e..f2fbacb9357 100644 --- a/Tests/Tests/STPShippingAddressViewControllerTest.m +++ b/Tests/Tests/STPShippingAddressViewControllerTest.m @@ -11,6 +11,7 @@ #import #import "NSLocale+STPSwizzling.h" #import "STPFixtures.h" +#import "STPPostalCodeValidator.h" @interface STPShippingAddressViewControllerTest : XCTestCase @@ -29,7 +30,10 @@ - (void)testPrefilledBillingAddress_removeAddress { address.line1 = @"55 John St"; address.city = @"Harare"; address.postalCode = @"10002"; - address.country = @"ZW"; + address.country = @"ZW"; // Zimbabwe does not require zip codes, while the default locale for tests (US) does + // Sanity checks + XCTAssertFalse([STPPostalCodeValidator postalCodeIsRequiredForCountryCode:@"ZW"]); + XCTAssertTrue([STPPostalCodeValidator postalCodeIsRequiredForCountryCode:@"US"]); STPShippingAddressViewController *sut = [[STPShippingAddressViewController alloc] initWithConfiguration:config theme:[STPTheme defaultTheme] @@ -38,12 +42,16 @@ - (void)testPrefilledBillingAddress_removeAddress { selectedShippingMethod:nil prefilledInformation:nil]; - [sut loadView]; - [sut viewDidLoad]; + XCTAssertNoThrow([sut loadView]); + XCTAssertNoThrow([sut viewDidLoad]); } - (void)testPrefilledBillingAddress_addAddress { [NSLocale stp_setCurrentLocale:[NSLocale localeWithLocaleIdentifier:@"en_ZW"]]; + // Zimbabwe does not require zip codes, while the default locale for tests (US) does + // Sanity checks + XCTAssertFalse([STPPostalCodeValidator postalCodeIsRequiredForCountryCode:@"ZW"]); + XCTAssertTrue([STPPostalCodeValidator postalCodeIsRequiredForCountryCode:@"US"]); STPPaymentConfiguration *config = [STPFixtures paymentConfiguration]; config.requiredShippingAddressFields = [NSSet setWithObject:STPContactFieldPostalAddress]; @@ -64,8 +72,8 @@ - (void)testPrefilledBillingAddress_addAddress { selectedShippingMethod:nil prefilledInformation:nil]; - [sut loadView]; - [sut viewDidLoad]; + XCTAssertNoThrow([sut loadView]); + XCTAssertNoThrow([sut viewDidLoad]); [NSLocale stp_resetCurrentLocale]; }