Skip to content

Commit

Permalink
Cleanup and adds sanity checks to new unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
csabol-stripe committed Aug 9, 2018
1 parent 70e2b83 commit 9e21431
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 14 deletions.
26 changes: 17 additions & 9 deletions Tests/Tests/STPAddCardViewControllerTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#import "STPCard.h"
#import "STPFixtures.h"
#import "STPPaymentCardTextFieldCell.h"
#import "STPPostalCodeValidator.h"

@interface STPAddCardViewController (Testing)
@property (nonatomic) STPPaymentCardTextFieldCell *paymentCell;
Expand All @@ -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;
Expand All @@ -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
Expand All @@ -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];
Expand Down
18 changes: 13 additions & 5 deletions Tests/Tests/STPShippingAddressViewControllerTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#import <Stripe/Stripe.h>
#import "NSLocale+STPSwizzling.h"
#import "STPFixtures.h"
#import "STPPostalCodeValidator.h"

@interface STPShippingAddressViewControllerTest : XCTestCase

Expand All @@ -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]
Expand All @@ -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];

Expand All @@ -64,8 +72,8 @@ - (void)testPrefilledBillingAddress_addAddress {
selectedShippingMethod:nil
prefilledInformation:nil];

[sut loadView];
[sut viewDidLoad];
XCTAssertNoThrow([sut loadView]);
XCTAssertNoThrow([sut viewDidLoad]);
[NSLocale stp_resetCurrentLocale];
}

Expand Down

0 comments on commit 9e21431

Please sign in to comment.