-
Notifications
You must be signed in to change notification settings - Fork 997
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixes crash in STPAddCardViewController with some prefilled billing addresses #1004
Changes from 2 commits
134a414
fe5b1aa
70e2b83
9e21431
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
// | ||
// STPShippingAddressViewControllerTest.m | ||
// StripeiOS Tests | ||
// | ||
// Created by Cameron Sabol on 8/7/18. | ||
// Copyright © 2018 Stripe, Inc. All rights reserved. | ||
// | ||
|
||
#import <XCTest/XCTest.h> | ||
|
||
#import <Stripe/Stripe.h> | ||
#import "NSLocale+STPSwizzling.h" | ||
#import "STPFixtures.h" | ||
|
||
@interface STPShippingAddressViewControllerTest : XCTestCase | ||
|
||
@end | ||
|
||
@implementation STPShippingAddressViewControllerTest | ||
|
||
- (void)testPrefilledBillingAddress_removeAddress { | ||
STPPaymentConfiguration *config = [STPFixtures paymentConfiguration]; | ||
config.requiredShippingAddressFields = [NSSet setWithObject:STPContactFieldPostalAddress]; | ||
|
||
STPAddress *address = [STPAddress new]; | ||
address.name = @"John Smith Doe"; | ||
address.phone = @"8885551212"; | ||
address.email = @"[email protected]"; | ||
address.line1 = @"55 John St"; | ||
address.city = @"Harare"; | ||
address.postalCode = @"10002"; | ||
address.country = @"ZW"; | ||
|
||
STPShippingAddressViewController *sut = [[STPShippingAddressViewController alloc] initWithConfiguration:config | ||
theme:[STPTheme defaultTheme] | ||
currency:nil | ||
shippingAddress:address | ||
selectedShippingMethod:nil | ||
prefilledInformation:nil]; | ||
|
||
[sut loadView]; | ||
[sut viewDidLoad]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. WDYT about adding I think that'd catch the Same for the matching tests of the other class. |
||
} | ||
|
||
- (void)testPrefilledBillingAddress_addAddress { | ||
[NSLocale stp_setCurrentLocale:[NSLocale localeWithLocaleIdentifier:@"en_ZW"]]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. WDYT about adding assertions (or a separate test?) that If ZW starts requiring a postal code, or we stop requiring it for US, we start testing a different code path, and the code could break silently. It also helps document what's being tested, and why those countries were chosen. |
||
STPPaymentConfiguration *config = [STPFixtures paymentConfiguration]; | ||
config.requiredShippingAddressFields = [NSSet setWithObject:STPContactFieldPostalAddress]; | ||
|
||
STPAddress *address = [STPAddress new]; | ||
address.name = @"John Smith Doe"; | ||
address.phone = @"8885551212"; | ||
address.email = @"[email protected]"; | ||
address.line1 = @"55 John St"; | ||
address.city = @"New York"; | ||
address.state = @"NY"; | ||
address.postalCode = @"10002"; | ||
address.country = @"US"; | ||
|
||
STPShippingAddressViewController *sut = [[STPShippingAddressViewController alloc] initWithConfiguration:config | ||
theme:[STPTheme defaultTheme] | ||
currency:nil | ||
shippingAddress:address | ||
selectedShippingMethod:nil | ||
prefilledInformation:nil]; | ||
|
||
[sut loadView]; | ||
[sut viewDidLoad]; | ||
[NSLocale stp_resetCurrentLocale]; | ||
} | ||
|
||
|
||
@end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a way to (cleanly) push this down into the
STPAddressViewModel
? It looks like it's already trying to trackshowingPostalCodeCell
, and has logic for whether it's being added or removed based on updates to the address.Or maybe we should move the
_addressViewModel.delegate = self
line to after we set the pre-filled info, because we don't care about updates to the ViewModel until after we've finished creating the views? That might allow us to avoid this complexity completely?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I actually prefer the logic to live in the view controller because this situation is a result of layout passes/table view caching/etc. that I think the view controller is closer too than the view model (correct me if I'm wrong in my view model understanding :) ).
I thought about this. I believe that change would also fix the crash, but this solution is more robust