From 056cac10306a4c26abf6a343362cf54d6e4b4973 Mon Sep 17 00:00:00 2001 From: Mike Silvis Date: Wed, 14 Oct 2020 07:27:48 -0400 Subject: [PATCH 1/3] Deprecate legacy methods, and remove previously deprecated functions --- Podfile.lock | 2 +- Sources/SCCAPIRequest.h | 28 ++++++-------- Sources/SCCAPIRequest.m | 82 +++++++++++++++++------------------------ 3 files changed, 47 insertions(+), 65 deletions(-) diff --git a/Podfile.lock b/Podfile.lock index 0a17dd7..671c31f 100644 --- a/Podfile.lock +++ b/Podfile.lock @@ -24,4 +24,4 @@ SPEC CHECKSUMS: PODFILE CHECKSUM: a679ea1c4a7a65af08221a21783dd323549bd283 -COCOAPODS: 1.8.4 +COCOAPODS: 1.9.3 diff --git a/Sources/SCCAPIRequest.h b/Sources/SCCAPIRequest.h index 650f1f1..1a67480 100644 --- a/Sources/SCCAPIRequest.h +++ b/Sources/SCCAPIRequest.h @@ -57,6 +57,13 @@ typedef NS_OPTIONS(NSUInteger, SCCAPIRequestTenderTypes) { */ + (void)setClientID:(nullable NSString *)clientID; +/** + Sets application client ID to associate with all subsequent API requests. + The application ID must be set to something other than nil before the first API request object is created. + @param applicationID The applicationID ID to associate with all subsequent API requests. + */ ++ (void)setApplicationID:(nullable NSString *)applicationID; + /** Designated initializer for the Point of Sale API request. @param callbackURL The URL that Square Point of Sale sends responses to. @@ -85,22 +92,14 @@ typedef NS_OPTIONS(NSUInteger, SCCAPIRequestTenderTypes) { customerID:(nullable NSString*)customerID supportedTenderTypes:(SCCAPIRequestTenderTypes)supportedTenderTypes clearsDefaultFees:(BOOL)clearsDefaultFees - returnAutomaticallyAfterPayment:(BOOL)autoreturn + returnsAutomaticallyAfterPayment:(BOOL)autoreturn error:(out NSError *__nullable *__nullable)error; -+ (nullable instancetype)requestWithCallbackURL:(nonnull NSURL *)callbackURL - amount:(nonnull SCCMoney *)amount - userInfoString:(nullable NSString *)userInfoString - merchantID:(nullable NSString *)merchantID - notes:(nullable NSString *)notes - customerID:(nullable NSString*)customerID - supportedTenderTypes:(SCCAPIRequestTenderTypes)supportedTenderTypes - clearsDefaultFees:(BOOL)clearsDefaultFees - returnAutomaticallyAfterPayment:(BOOL)autoreturn - error:(out NSError *__nullable *__nullable)error __deprecated_msg("Use requestWithCallbackURL:amount:userInfoString:locationID:notes:customerID:supportedTenderTypes:clearsDefaultFees:returnAutomaticallyAfterPayment:error: instead."); +/// Application Client ID bound to the request at the time of creation. Same as applicationID +@property (nonatomic, copy, readonly, nonnull) NSString *clientID __deprecated_msg("Use applicationID instead"); -/// Application Client ID bound to the request at the time of creation. -@property (nonatomic, copy, readonly, nonnull) NSString *clientID; +/// Application ID bound to the request at the time of creation. +@property (nonatomic, copy, readonly, nonnull) NSString *applicationID; /// The URL that Square Point of Sale sends responses to. @property (nonatomic, copy, readonly, nonnull) NSURL *callbackURL; @@ -111,9 +110,6 @@ typedef NS_OPTIONS(NSUInteger, SCCAPIRequestTenderTypes) { /// Free-form string passed along to your application's callbackURL after the payment completes. @property (nonatomic, copy, readonly, nullable) NSString *userInfoString; -/// The business location's Square-issued ID. -@property (nonatomic, copy, readonly, nullable) NSString *merchantID __deprecated_msg("Use locationID instead"); - /// The business location's Square-issued ID. @property (nonatomic, copy, readonly, nullable) NSString *locationID; diff --git a/Sources/SCCAPIRequest.m b/Sources/SCCAPIRequest.m index 4ce6567..3bf1ddd 100644 --- a/Sources/SCCAPIRequest.m +++ b/Sources/SCCAPIRequest.m @@ -61,12 +61,17 @@ @implementation SCCAPIRequest + (void)setClientID:(nullable NSString *)clientID; { - APIClientID = clientID; + [self setApplicationID:clientID]; +} + ++ (void)setApplicationID:(NSString *)applicationID; +{ + APIClientID = applicationID; } #pragma mark - Class Methods - Private -+ (nullable NSString *)_clientID; ++ (nullable NSString *)_applicationID; { return APIClientID; } @@ -78,20 +83,6 @@ + (nonnull NSString *)_URLScheme; #pragma mark - Initialization -+ (nullable instancetype)requestWithCallbackURL:(nonnull NSURL *)callbackURL - amount:(nonnull SCCMoney *)amount - userInfoString:(nullable NSString *)userInfoString - merchantID:(nullable NSString *)merchantID - notes:(nullable NSString *)notes - customerID:(nullable NSString *)customerID - supportedTenderTypes:(SCCAPIRequestTenderTypes)supportedTenderTypes - clearsDefaultFees:(BOOL)clearsDefaultFees - returnAutomaticallyAfterPayment:(BOOL)autoreturn - error:(out NSError *__nullable *__nullable)error __deprecated; -{ - return [self requestWithCallbackURL:callbackURL amount:amount userInfoString:userInfoString locationID:merchantID notes:notes customerID:customerID supportedTenderTypes:supportedTenderTypes clearsDefaultFees:clearsDefaultFees returnAutomaticallyAfterPayment:autoreturn error:error]; -} - + (nullable instancetype)requestWithCallbackURL:(nonnull NSURL *)callbackURL amount:(nonnull SCCMoney *)amount userInfoString:(nullable NSString *)userInfoString @@ -100,10 +91,10 @@ + (nullable instancetype)requestWithCallbackURL:(nonnull NSURL *)callbackURL customerID:(nullable NSString *)customerID supportedTenderTypes:(SCCAPIRequestTenderTypes)supportedTenderTypes clearsDefaultFees:(BOOL)clearsDefaultFees - returnAutomaticallyAfterPayment:(BOOL)autoreturn + returnsAutomaticallyAfterPayment:(BOOL)autoreturn error:(out NSError *__nullable *__nullable)error; { - if (![self.class _clientID].length) { + if (![self.class _applicationID].length) { if (error) { *error = [NSError SCC_missingRequestClientIDError]; } @@ -124,28 +115,28 @@ + (nullable instancetype)requestWithCallbackURL:(nonnull NSURL *)callbackURL return nil; } - return [[self alloc] initWithClientID:(NSString *__nonnull)[self.class _clientID] - callbackURL:callbackURL - amount:amount - userInfoString:userInfoString - locationID:locationID - notes:notes - customerID:customerID - supportedTenderTypes:supportedTenderTypes - clearsDefaultFees:clearsDefaultFees - returnAutomaticallyAfterPayment:autoreturn]; + return [[self alloc] initWithApplicationID:(NSString *__nonnull)[self.class _applicationID] + callbackURL:callbackURL + amount:amount + userInfoString:userInfoString + locationID:locationID + notes:notes + customerID:customerID + supportedTenderTypes:supportedTenderTypes + clearsDefaultFees:clearsDefaultFees + returnAutomaticallyAfterPayment:autoreturn]; } -- (instancetype)initWithClientID:(nonnull NSString *)clientID - callbackURL:(nonnull NSURL *)callbackURL - amount:(nonnull SCCMoney *)amount - userInfoString:(nullable NSString *)userInfoString - locationID:(nullable NSString *)locationID - notes:(nullable NSString *)notes - customerID:(nullable NSString *)customerID - supportedTenderTypes:(SCCAPIRequestTenderTypes)supportedTenderTypes - clearsDefaultFees:(BOOL)clearsDefaultFees - returnAutomaticallyAfterPayment:(BOOL)autoreturn; +- (instancetype)initWithApplicationID:(nonnull NSString *)applicationID + callbackURL:(nonnull NSURL *)callbackURL + amount:(nonnull SCCMoney *)amount + userInfoString:(nullable NSString *)userInfoString + locationID:(nullable NSString *)locationID + notes:(nullable NSString *)notes + customerID:(nullable NSString *)customerID + supportedTenderTypes:(SCCAPIRequestTenderTypes)supportedTenderTypes + clearsDefaultFees:(BOOL)clearsDefaultFees + returnAutomaticallyAfterPayment:(BOOL)autoreturn; { NSAssert(callbackURL.scheme.length, @"Callback URL must be specified and have a scheme."); NSAssert(amount && amount.amountCents >= 0, @"SCCMoney amount must be specified."); @@ -155,7 +146,7 @@ - (instancetype)initWithClientID:(nonnull NSString *)clientID return nil; } - _clientID = [clientID copy]; + _applicationID = [applicationID copy]; _callbackURL = [callbackURL copy]; _amount = [amount copy]; _userInfoString = [userInfoString copy]; @@ -186,7 +177,7 @@ - (BOOL)isEqual:(nullable id)object; - (NSUInteger)hash; { - NSUInteger const hashOfRequiredFields = self.clientID.hash ^ self.callbackURL.hash ^ self.amount.hash; + NSUInteger const hashOfRequiredFields = self.applicationID.hash ^ self.callbackURL.hash ^ self.amount.hash; NSUInteger const hashOfOptionalFields = self.userInfoString.hash ^ self.locationID.hash ^ self.notes.hash ^ self.customerID.hash; NSUInteger const hashOfScalarFields = (NSUInteger)self.supportedTenderTypes ^ (NSUInteger)self.clearsDefaultFees ^ (NSUInteger)self.returnsAutomaticallyAfterPayment ^ (NSUInteger)self.disablesKeyedInCardEntry ^ (NSUInteger)self.skipsReceipt; @@ -199,16 +190,11 @@ - (nonnull NSString *)description; return [NSString stringWithFormat:@"<%@: %p> { clientID: %@, callbackURL: %@, amount: %@ }", NSStringFromClass(self.class), self, - self.clientID, + self.applicationID, self.callbackURL, self.amount]; } -- (NSString*)merchantID; -{ - return self.locationID; -} - #pragma mark - NSCopying - (nonnull id)copyWithZone:(nullable NSZone *)zone; @@ -226,7 +212,7 @@ - (BOOL)isEqualToAPIRequest:(nullable SCCAPIRequest *)request; } // The following properties are required and cannot be nil. - if (![self.clientID isEqualToString:(NSString *__nonnull)request.clientID] || + if (![self.applicationID isEqualToString:(NSString *__nonnull)request.applicationID] || ![self.callbackURL isEqual:request.callbackURL] || ![self.amount isEqualToSCCMoney:request.amount]) { return NO; @@ -264,7 +250,7 @@ - (nullable NSURL *)APIRequestURLWithError:(out NSError *__nullable *__nullable) NSMutableDictionary *const data = [NSMutableDictionary dictionary]; [data setObject:SCCSDKVersion forKey:SCCAPIRequestSDKVersionKey]; [data setObject:SCCAPIVersion forKey:SCCAPIRequestAPIVersionKey]; - [data setObject:self.clientID forKey:SCCAPIRequestClientIDKey]; + [data setObject:self.applicationID forKey:SCCAPIRequestClientIDKey]; [data SCC_setSafeObject:self.amount.requestDictionaryRepresentation forKey:SCCAPIRequestAmountMoneyKey]; [data SCC_setSafeObject:[SCAPIURLConversion encode:self.callbackURL].absoluteString forKey:SCCAPIRequestCallbackURLKey]; From 6d7fad081642c93655defa72f9cd290476b401b6 Mon Sep 17 00:00:00 2001 From: Mike Silvis Date: Wed, 14 Oct 2020 07:41:10 -0400 Subject: [PATCH 2/3] Improve API consistency across Square Products --- README.md | 22 +++++----- SampleApp/Sources/ViewController.swift | 4 +- Sources/SCCAPIRequest.h | 14 ++++-- Sources/SCCAPIRequest.m | 27 +++++++++--- Tests/SCAPIRequestTests.m | 59 ++++++++++++++++++++++++++ Tests/SCCAPIConnectionTests.m | 13 ++++-- 6 files changed, 114 insertions(+), 25 deletions(-) create mode 100644 Tests/SCAPIRequestTests.m diff --git a/README.md b/README.md index 5a53bde..c6bf339 100644 --- a/README.md +++ b/README.md @@ -87,7 +87,7 @@ let callbackURL = URL(string: "<#T##Your URL Scheme##String#>://")! // Your client ID is the same as your Square Application ID. // Note: You only need to set your client ID once, before creating your first request. -SCCAPIRequest.setClientID(<#T##Client ID##String#>) +SCCAPIRequest.setApplicationID(<#T##Application ID##String#>) do { // Specify the amount of money to charge. @@ -96,15 +96,17 @@ do { // Create the request. let apiRequest = try SCCAPIRequest( - callbackURL: callbackURL, - amount: money, - userInfoString: nil, - locationID: nil, - notes: "Coffee", - customerID: nil, - supportedTenderTypes: .all, - clearsDefaultFees: false, - returnAutomaticallyAfterPayment: false + callbackURL: callbackURL, + amount: money, + userInfoString: nil, + locationID: nil, + notes: "Coffee", + customerID: nil, + supportedTenderTypes: .all, + clearsDefaultFees: false, + returnsAutomaticallyAfterPayment: false, + disablesKeyedInCardEntry: false, + skipsReceipt: false ) // Open Point of Sale to complete the payment. diff --git a/SampleApp/Sources/ViewController.swift b/SampleApp/Sources/ViewController.swift index d4dbbbd..3100725 100644 --- a/SampleApp/Sources/ViewController.swift +++ b/SampleApp/Sources/ViewController.swift @@ -53,7 +53,9 @@ class ViewController: UIViewController { customerID: nil, supportedTenderTypes: .all, clearsDefaultFees: false, - returnAutomaticallyAfterPayment: false + returnsAutomaticallyAfterPayment: false, + disablesKeyedInCardEntry: false, + skipsReceipt: false ) // Open Point of Sale to complete the payment. diff --git a/Sources/SCCAPIRequest.h b/Sources/SCCAPIRequest.h index 1a67480..89afc9b 100644 --- a/Sources/SCCAPIRequest.h +++ b/Sources/SCCAPIRequest.h @@ -55,7 +55,7 @@ typedef NS_OPTIONS(NSUInteger, SCCAPIRequestTenderTypes) { The client ID must be set to something other than nil before the first API request object is created. @param clientID The client ID to associate with all subsequent API requests. */ -+ (void)setClientID:(nullable NSString *)clientID; ++ (void)setClientID:(nullable NSString *)clientID __deprecated_msg("Use the favored `setApplicationID` instead."); /** Sets application client ID to associate with all subsequent API requests. @@ -93,6 +93,8 @@ typedef NS_OPTIONS(NSUInteger, SCCAPIRequestTenderTypes) { supportedTenderTypes:(SCCAPIRequestTenderTypes)supportedTenderTypes clearsDefaultFees:(BOOL)clearsDefaultFees returnsAutomaticallyAfterPayment:(BOOL)autoreturn + disablesKeyedInCardEntry:(BOOL)disablesKeyedInCardEntry + skipsReceipt:(BOOL)skipsReceipt error:(out NSError *__nullable *__nullable)error; /// Application Client ID bound to the request at the time of creation. Same as applicationID @@ -119,6 +121,12 @@ typedef NS_OPTIONS(NSUInteger, SCCAPIRequestTenderTypes) { /// A custom note to associate with the resulting payment. @property (nonatomic, copy, readonly, nullable) NSString *notes; +/// Square Point of Sale API Version +@property (nonatomic, copy, readonly, nonnull) NSString *apiVersion; + +/// SquarePointOfSaleSDK Version +@property (nonatomic, copy, readonly, nonnull) NSString *sdkVersion; + /// The types of tender that Square Point of Sale is allowed to accept for the payment. @property (nonatomic, assign, readonly) SCCAPIRequestTenderTypes supportedTenderTypes; @@ -134,11 +142,11 @@ typedef NS_OPTIONS(NSUInteger, SCCAPIRequestTenderTypes) { /// If YES, Point of Sale will not display the option to manually key-in a credit card number. /// Defaults to NO. -@property (nonatomic, assign) BOOL disablesKeyedInCardEntry; +@property (nonatomic, assign, readonly) BOOL disablesKeyedInCardEntry; /// If YES, Point of Sale will skip the receipt screen of the payment flow for non-cash payments. /// Defaults to NO. -@property (nonatomic, assign) BOOL skipsReceipt; +@property (nonatomic, assign, readonly) BOOL skipsReceipt; /** @param request The request to compare the receiver to. diff --git a/Sources/SCCAPIRequest.m b/Sources/SCCAPIRequest.m index 3bf1ddd..881b9c0 100644 --- a/Sources/SCCAPIRequest.m +++ b/Sources/SCCAPIRequest.m @@ -28,8 +28,7 @@ #import "SCCMoney.h" #import "SCCMoney+Serialization.h" - -NSString *__nonnull const SCCSDKVersion = @"3.1"; +NSString *__nonnull const SCCSDKVersion = @"3.4.1"; NSString *__nonnull const SCCAPIVersion = @"1.3"; NSString *__nonnull const SCCAPIRequestSDKVersionKey = @"sdk_version"; @@ -81,6 +80,11 @@ + (nonnull NSString *)_URLScheme; return @"square-commerce-v1"; } +- (nonnull NSString *)sdkVersion; +{ + return SCCSDKVersion; +} + #pragma mark - Initialization + (nullable instancetype)requestWithCallbackURL:(nonnull NSURL *)callbackURL @@ -92,6 +96,8 @@ + (nullable instancetype)requestWithCallbackURL:(nonnull NSURL *)callbackURL supportedTenderTypes:(SCCAPIRequestTenderTypes)supportedTenderTypes clearsDefaultFees:(BOOL)clearsDefaultFees returnsAutomaticallyAfterPayment:(BOOL)autoreturn + disablesKeyedInCardEntry:(BOOL)disablesKeyedInCardEntry + skipsReceipt:(BOOL)skipsReceipt error:(out NSError *__nullable *__nullable)error; { if (![self.class _applicationID].length) { @@ -124,7 +130,9 @@ + (nullable instancetype)requestWithCallbackURL:(nonnull NSURL *)callbackURL customerID:customerID supportedTenderTypes:supportedTenderTypes clearsDefaultFees:clearsDefaultFees - returnAutomaticallyAfterPayment:autoreturn]; + returnAutomaticallyAfterPayment:autoreturn + disablesKeyedInCardEntry:disablesKeyedInCardEntry + skipsReceipt:skipsReceipt]; } - (instancetype)initWithApplicationID:(nonnull NSString *)applicationID @@ -136,7 +144,9 @@ - (instancetype)initWithApplicationID:(nonnull NSString *)applicationID customerID:(nullable NSString *)customerID supportedTenderTypes:(SCCAPIRequestTenderTypes)supportedTenderTypes clearsDefaultFees:(BOOL)clearsDefaultFees - returnAutomaticallyAfterPayment:(BOOL)autoreturn; + returnAutomaticallyAfterPayment:(BOOL)autoreturn + disablesKeyedInCardEntry:(BOOL)disablesKeyedInCardEntry + skipsReceipt:(BOOL)skipsReceipt { NSAssert(callbackURL.scheme.length, @"Callback URL must be specified and have a scheme."); NSAssert(amount && amount.amountCents >= 0, @"SCCMoney amount must be specified."); @@ -152,10 +162,13 @@ - (instancetype)initWithApplicationID:(nonnull NSString *)applicationID _userInfoString = [userInfoString copy]; _locationID = [locationID copy]; _notes = [notes copy]; + _customerID = [customerID copy]; _supportedTenderTypes = supportedTenderTypes; _clearsDefaultFees = clearsDefaultFees; _returnsAutomaticallyAfterPayment = autoreturn; - _customerID = [customerID copy]; + _disablesKeyedInCardEntry = disablesKeyedInCardEntry; + _skipsReceipt = skipsReceipt; + _apiVersion = SCCAPIVersion; return self; } @@ -248,8 +261,8 @@ @implementation SCCAPIRequest (Serialization) - (nullable NSURL *)APIRequestURLWithError:(out NSError *__nullable *__nullable)error; { NSMutableDictionary *const data = [NSMutableDictionary dictionary]; - [data setObject:SCCSDKVersion forKey:SCCAPIRequestSDKVersionKey]; - [data setObject:SCCAPIVersion forKey:SCCAPIRequestAPIVersionKey]; + [data setObject:[self sdkVersion] forKey:SCCAPIRequestSDKVersionKey]; + [data setObject:self.apiVersion forKey:SCCAPIRequestAPIVersionKey]; [data setObject:self.applicationID forKey:SCCAPIRequestClientIDKey]; [data SCC_setSafeObject:self.amount.requestDictionaryRepresentation forKey:SCCAPIRequestAmountMoneyKey]; diff --git a/Tests/SCAPIRequestTests.m b/Tests/SCAPIRequestTests.m new file mode 100644 index 0000000..ea024eb --- /dev/null +++ b/Tests/SCAPIRequestTests.m @@ -0,0 +1,59 @@ +// +// XCTestCase+SCAPIRequestTests.m +// SquarePointOfSaleSDK-Unit-Tests +// +// Created by Mike Silvis on 10/14/20. +// + +@import SquarePointOfSaleSDK; + +#import + +@interface SCAPIRequestTests : XCTestCase +@end + +@implementation SCAPIRequestTests + +- (void)test_initializerSetsAllProperties; +{ + + NSURL *const callbackURL = [NSURL URLWithString:@"my-app://perform-callback"]; + SCCMoney *const amount = [SCCMoney moneyWithAmountCents:100 currencyCode:@"USD" error:NULL]; + + XCTAssertNotNil(callbackURL); + XCTAssertNotNil(amount); + + [SCCAPIRequest setApplicationID:@"my-app-client-id"]; + + SCCAPIRequest *const request = [SCCAPIRequest requestWithCallbackURL:callbackURL + amount:amount + userInfoString:@"user-info-string" + locationID:@"location-id" + notes:@"notes" + customerID:@"customer-id" + supportedTenderTypes:SCCAPIRequestTenderTypeCard + clearsDefaultFees:YES + returnsAutomaticallyAfterPayment:YES + disablesKeyedInCardEntry:YES + skipsReceipt:YES + error:NULL]; + + XCTAssertEqual(request.amount, amount); + XCTAssertEqual(request.userInfoString, @"user-info-string"); + XCTAssertEqual(request.locationID, @"location-id"); + XCTAssertEqual(request.notes, @"notes"); + XCTAssertEqual(request.customerID, @"customer-id"); + XCTAssertEqual(request.apiVersion, @"1.3"); + XCTAssertEqual(request.sdkVersion, @"3.4.1"); + XCTAssertEqual(request.supportedTenderTypes, SCCAPIRequestTenderTypeCard); + XCTAssertEqual(request.clearsDefaultFees, YES); + XCTAssertEqual(request.returnsAutomaticallyAfterPayment, YES); + XCTAssertEqual(request.disablesKeyedInCardEntry, YES); + XCTAssertEqual(request.skipsReceipt, YES); + + NSURL *apiRequest = [request APIRequestURLWithError:NULL]; + + XCTAssertTrue([apiRequest.absoluteString isEqualToString:@"square-commerce-v1://payment/create?data=%7B%22state%22%3A%22user-info-string%22%2C%22options%22%3A%7B%22auto_return%22%3Atrue%2C%22skip_receipt%22%3Atrue%2C%22clear_default_fees%22%3Atrue%2C%22disable_cnp%22%3Atrue%2C%22supported_tender_types%22%3A%5B%22CREDIT_CARD%22%5D%7D%2C%22notes%22%3A%22notes%22%2C%22callback_url%22%3A%22my-app%3A%5C%2F%5C%2Fperform-callback%5C%2Fsquare_request%22%2C%22location_id%22%3A%22location-id%22%2C%22version%22%3A%221.3%22%2C%22amount_money%22%3A%7B%22amount%22%3A100%2C%22currency_code%22%3A%22USD%22%7D%2C%22customer_id%22%3A%22customer-id%22%2C%22client_id%22%3A%22my-app-client-id%22%2C%22sdk_version%22%3A%223.4.1%22%7D"]); +} + +@end diff --git a/Tests/SCCAPIConnectionTests.m b/Tests/SCCAPIConnectionTests.m index 7d8fea9..f761a5d 100644 --- a/Tests/SCCAPIConnectionTests.m +++ b/Tests/SCCAPIConnectionTests.m @@ -40,7 +40,8 @@ - (void)test_canPerformRequestError_isYESWhenApplicationCanOpenURL; XCTAssertNotNil(callbackURL); XCTAssertNotNil(amount); - [SCCAPIRequest setClientID:@"my-app-client-id"]; + [SCCAPIRequest setApplicationID:@"my-app-client-id"]; + SCCAPIRequest *const request = [SCCAPIRequest requestWithCallbackURL:callbackURL amount:amount userInfoString:nil @@ -49,7 +50,9 @@ - (void)test_canPerformRequestError_isYESWhenApplicationCanOpenURL; customerID:nil supportedTenderTypes:SCCAPIRequestTenderTypeCard clearsDefaultFees:NO - returnAutomaticallyAfterPayment:NO + returnsAutomaticallyAfterPayment:NO + disablesKeyedInCardEntry:NO + skipsReceipt:NO error:NULL]; id const bundleMock = OCMPartialMock([NSBundle mainBundle]); @@ -73,7 +76,7 @@ - (void)test_canPerformRequestError_isNOWhenApplicationCannotOpenURL; XCTAssertNotNil(callbackURL); XCTAssertNotNil(amount); - [SCCAPIRequest setClientID:@"my-app-client-id"]; + [SCCAPIRequest setApplicationID:@"my-app-client-id"]; SCCAPIRequest *const request = [SCCAPIRequest requestWithCallbackURL:callbackURL amount:amount userInfoString:nil @@ -82,7 +85,9 @@ - (void)test_canPerformRequestError_isNOWhenApplicationCannotOpenURL; customerID:nil supportedTenderTypes:SCCAPIRequestTenderTypeCard clearsDefaultFees:NO - returnAutomaticallyAfterPayment:NO + returnsAutomaticallyAfterPayment:NO + disablesKeyedInCardEntry:NO + skipsReceipt:NO error:NULL]; id const bundleMock = OCMPartialMock([NSBundle mainBundle]); From e84feffbabbde5444413f9a3d7d038982865d87c Mon Sep 17 00:00:00 2001 From: Mike Silvis Date: Wed, 14 Oct 2020 16:49:48 -0400 Subject: [PATCH 3/3] Resolving flaky tests --- Tests/SCAPIRequestTests.m | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/Tests/SCAPIRequestTests.m b/Tests/SCAPIRequestTests.m index ea024eb..0ed43a5 100644 --- a/Tests/SCAPIRequestTests.m +++ b/Tests/SCAPIRequestTests.m @@ -39,21 +39,17 @@ - (void)test_initializerSetsAllProperties; error:NULL]; XCTAssertEqual(request.amount, amount); - XCTAssertEqual(request.userInfoString, @"user-info-string"); - XCTAssertEqual(request.locationID, @"location-id"); - XCTAssertEqual(request.notes, @"notes"); - XCTAssertEqual(request.customerID, @"customer-id"); - XCTAssertEqual(request.apiVersion, @"1.3"); - XCTAssertEqual(request.sdkVersion, @"3.4.1"); + XCTAssertTrue([request.userInfoString isEqualToString:@"user-info-string"]); + XCTAssertTrue([request.locationID isEqualToString:@"location-id"]); + XCTAssertTrue([request.notes isEqualToString:@"notes"]); + XCTAssertTrue([request.customerID isEqualToString:@"customer-id"]); + XCTAssertTrue([request.apiVersion isEqualToString:@"1.3"]); + XCTAssertTrue([request.sdkVersion isEqualToString:@"3.4.1"]); XCTAssertEqual(request.supportedTenderTypes, SCCAPIRequestTenderTypeCard); XCTAssertEqual(request.clearsDefaultFees, YES); XCTAssertEqual(request.returnsAutomaticallyAfterPayment, YES); XCTAssertEqual(request.disablesKeyedInCardEntry, YES); XCTAssertEqual(request.skipsReceipt, YES); - - NSURL *apiRequest = [request APIRequestURLWithError:NULL]; - - XCTAssertTrue([apiRequest.absoluteString isEqualToString:@"square-commerce-v1://payment/create?data=%7B%22state%22%3A%22user-info-string%22%2C%22options%22%3A%7B%22auto_return%22%3Atrue%2C%22skip_receipt%22%3Atrue%2C%22clear_default_fees%22%3Atrue%2C%22disable_cnp%22%3Atrue%2C%22supported_tender_types%22%3A%5B%22CREDIT_CARD%22%5D%7D%2C%22notes%22%3A%22notes%22%2C%22callback_url%22%3A%22my-app%3A%5C%2F%5C%2Fperform-callback%5C%2Fsquare_request%22%2C%22location_id%22%3A%22location-id%22%2C%22version%22%3A%221.3%22%2C%22amount_money%22%3A%7B%22amount%22%3A100%2C%22currency_code%22%3A%22USD%22%7D%2C%22customer_id%22%3A%22customer-id%22%2C%22client_id%22%3A%22my-app-client-id%22%2C%22sdk_version%22%3A%223.4.1%22%7D"]); } @end