-
Notifications
You must be signed in to change notification settings - Fork 996
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
Adding STPAddress containsContentFor...Fields:
methods to check for any useful data
#834
Merged
Merged
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
c5cd4fb
Adding STPAddress `containsContent...ForFields:` methods to check for…
danj-stripe 2b0014f
Rename containsContentForFields: -> containsContentForBillingAddressF…
danj-stripe bccc42f
Put parens around bitwise AND used in a boolean condition
danj-stripe 4f08fcc
Add (unfortunately repetitive) tests for containsContentFor...Address…
danj-stripe 1852613
Cast composed PKAddressField values to fix compiler warning.
danj-stripe af11375
Fix (dumb) test failures.
danj-stripe File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 |
---|---|---|
|
@@ -428,6 +428,51 @@ - (void)testContainsRequiredFieldsFull { | |
XCTAssertTrue([address containsRequiredFields:STPBillingAddressFieldsFull]); | ||
} | ||
|
||
- (void)testContainsContentForBillingAddressFields { | ||
STPAddress *address = [STPAddress new]; | ||
|
||
// Empty address should return false for everything | ||
XCTAssertFalse([address containsContentForBillingAddressFields:STPBillingAddressFieldsNone]); | ||
XCTAssertFalse([address containsContentForBillingAddressFields:STPBillingAddressFieldsZip]); | ||
XCTAssertFalse([address containsContentForBillingAddressFields:STPBillingAddressFieldsFull]); | ||
|
||
// 1+ characters in postalCode will return true for .Zip && .Full | ||
address.postalCode = @"0"; | ||
XCTAssertFalse([address containsContentForBillingAddressFields:STPBillingAddressFieldsNone]); | ||
XCTAssertTrue([address containsContentForBillingAddressFields:STPBillingAddressFieldsZip]); | ||
XCTAssertTrue([address containsContentForBillingAddressFields:STPBillingAddressFieldsFull]); | ||
// empty string returns false | ||
address.postalCode = @""; | ||
XCTAssertFalse([address containsContentForBillingAddressFields:STPBillingAddressFieldsNone]); | ||
XCTAssertFalse([address containsContentForBillingAddressFields:STPBillingAddressFieldsZip]); | ||
XCTAssertFalse([address containsContentForBillingAddressFields:STPBillingAddressFieldsFull]); | ||
address.postalCode = nil; | ||
|
||
// Test every other property that contributes to the full address, ensuring it returns True for .Full only | ||
// This is *not* refactoring-safe, but I think it's better than a bunch of duplicated code | ||
for (NSString *propertyName in @[@"line1", @"line2", @"city", @"state", @"country"]) { | ||
for (NSString *testValue in @[@"a", @"0", @"Foo Bar"]) { | ||
[address setValue:testValue forKey:propertyName]; | ||
XCTAssertFalse([address containsContentForBillingAddressFields:STPBillingAddressFieldsNone]); | ||
XCTAssertFalse([address containsContentForBillingAddressFields:STPBillingAddressFieldsZip]); | ||
XCTAssertTrue([address containsContentForBillingAddressFields:STPBillingAddressFieldsFull]); | ||
[address setValue:nil forKey:propertyName]; | ||
} | ||
|
||
// Make sure that empty string is treated like nil, and returns false for these properties | ||
[address setValue:@"" forKey:propertyName]; | ||
XCTAssertFalse([address containsContentForBillingAddressFields:STPBillingAddressFieldsNone]); | ||
XCTAssertFalse([address containsContentForBillingAddressFields:STPBillingAddressFieldsZip]); | ||
XCTAssertFalse([address containsContentForBillingAddressFields:STPBillingAddressFieldsFull]); | ||
[address setValue:nil forKey:propertyName]; | ||
} | ||
|
||
// ensure it still returns false for everything since it has been cleared | ||
XCTAssertFalse([address containsContentForBillingAddressFields:STPBillingAddressFieldsNone]); | ||
XCTAssertFalse([address containsContentForBillingAddressFields:STPBillingAddressFieldsZip]); | ||
XCTAssertFalse([address containsContentForBillingAddressFields:STPBillingAddressFieldsFull]); | ||
} | ||
|
||
- (void)testContainsRequiredShippingAddressFields { | ||
STPAddress *address = [STPAddress new]; | ||
XCTAssertTrue([address containsRequiredShippingAddressFields:PKAddressFieldNone]); | ||
|
@@ -458,6 +503,81 @@ - (void)testContainsRequiredShippingAddressFields { | |
XCTAssertTrue([address containsRequiredShippingAddressFields:PKAddressFieldAll]); | ||
} | ||
|
||
- (void)testContainsContentForShippingAddressFields { | ||
STPAddress *address = [STPAddress new]; | ||
|
||
// Empty address should return false for everything | ||
XCTAssertFalse([address containsContentForShippingAddressFields:PKAddressFieldNone]); | ||
XCTAssertFalse([address containsContentForShippingAddressFields:PKAddressFieldName]); | ||
XCTAssertFalse([address containsContentForShippingAddressFields:PKAddressFieldPhone]); | ||
XCTAssertFalse([address containsContentForShippingAddressFields:PKAddressFieldEmail]); | ||
XCTAssertFalse([address containsContentForShippingAddressFields:PKAddressFieldPostalAddress]); | ||
|
||
// Name | ||
address.name = @"Smith"; | ||
XCTAssertFalse([address containsContentForShippingAddressFields:PKAddressFieldNone]); | ||
XCTAssertTrue([address containsContentForShippingAddressFields:PKAddressFieldName]); | ||
XCTAssertFalse([address containsContentForShippingAddressFields:PKAddressFieldPhone]); | ||
XCTAssertFalse([address containsContentForShippingAddressFields:PKAddressFieldEmail]); | ||
XCTAssertFalse([address containsContentForShippingAddressFields:PKAddressFieldPostalAddress]); | ||
address.name = @""; | ||
|
||
// Phone | ||
address.phone = @"1"; | ||
XCTAssertFalse([address containsContentForShippingAddressFields:PKAddressFieldNone]); | ||
XCTAssertFalse([address containsContentForShippingAddressFields:PKAddressFieldName]); | ||
XCTAssertTrue([address containsContentForShippingAddressFields:PKAddressFieldPhone]); | ||
XCTAssertFalse([address containsContentForShippingAddressFields:PKAddressFieldEmail]); | ||
XCTAssertFalse([address containsContentForShippingAddressFields:PKAddressFieldPostalAddress]); | ||
address.phone = @""; | ||
|
||
address.email = @"f"; | ||
XCTAssertFalse([address containsContentForShippingAddressFields:PKAddressFieldNone]); | ||
XCTAssertFalse([address containsContentForShippingAddressFields:PKAddressFieldName]); | ||
XCTAssertFalse([address containsContentForShippingAddressFields:PKAddressFieldPhone]); | ||
XCTAssertTrue([address containsContentForShippingAddressFields:PKAddressFieldEmail]); | ||
XCTAssertFalse([address containsContentForShippingAddressFields:PKAddressFieldPostalAddress]); | ||
address.email = @""; | ||
|
||
// Test every property that contributes to the full address | ||
// This is *not* refactoring-safe, but I think it's better than a bunch more duplicated code | ||
for (NSString *propertyName in @[@"line1", @"line2", @"city", @"state", @"postalCode", @"country"]) { | ||
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. Maybe do something like |
||
for (NSString *testValue in @[@"a", @"0", @"Foo Bar"]) { | ||
[address setValue:testValue forKey:propertyName]; | ||
XCTAssertFalse([address containsContentForShippingAddressFields:PKAddressFieldNone]); | ||
XCTAssertFalse([address containsContentForShippingAddressFields:PKAddressFieldName]); | ||
XCTAssertFalse([address containsContentForShippingAddressFields:PKAddressFieldPhone]); | ||
XCTAssertFalse([address containsContentForShippingAddressFields:PKAddressFieldEmail]); | ||
XCTAssertTrue([address containsContentForShippingAddressFields:PKAddressFieldPostalAddress]); | ||
[address setValue:@"" forKey:propertyName]; | ||
} | ||
} | ||
|
||
// ensure it still returns false for everything with empty strings | ||
XCTAssertFalse([address containsContentForShippingAddressFields:PKAddressFieldNone]); | ||
XCTAssertFalse([address containsContentForShippingAddressFields:PKAddressFieldName]); | ||
XCTAssertFalse([address containsContentForShippingAddressFields:PKAddressFieldPhone]); | ||
XCTAssertFalse([address containsContentForShippingAddressFields:PKAddressFieldEmail]); | ||
XCTAssertFalse([address containsContentForShippingAddressFields:PKAddressFieldPostalAddress]); | ||
|
||
// Try a hybrid address, and make sure some bitwise combinations work | ||
address.name = @"a"; | ||
address.phone = @"1"; | ||
address.line1 = @"_"; | ||
XCTAssertFalse([address containsContentForShippingAddressFields:PKAddressFieldNone]); | ||
XCTAssertTrue([address containsContentForShippingAddressFields:PKAddressFieldName]); | ||
XCTAssertTrue([address containsContentForShippingAddressFields:PKAddressFieldPhone]); | ||
XCTAssertFalse([address containsContentForShippingAddressFields:PKAddressFieldEmail]); | ||
XCTAssertTrue([address containsContentForShippingAddressFields:PKAddressFieldPostalAddress]); | ||
|
||
XCTAssertTrue([address containsContentForShippingAddressFields:PKAddressFieldName | PKAddressFieldEmail]); | ||
XCTAssertTrue([address containsContentForShippingAddressFields:PKAddressFieldPhone | PKAddressFieldEmail]); | ||
XCTAssertTrue([address containsContentForShippingAddressFields:PKAddressFieldAll]); | ||
|
||
} | ||
|
||
|
||
- (void)testShippingInfoForCharge { | ||
STPAddress *address = [STPFixtures address]; | ||
PKShippingMethod *method = [[PKShippingMethod alloc] init]; | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
There wasn't actually a bug here (shippingAddress was still nil), but I chose to make a parallel change to keep things consistent and guard against future changes.