Commit d390ebc6 by Dima Bart

Merge pull request #183 from Shopify/bugfix/payment-providers-tests

Fix payment provider tests
parents e64df449 ddfbb567
//
// BUYFakeSafariController.h
// Mobile Buy SDK
//
// Created by Shopify.
// Copyright (c) 2015 Shopify Inc. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//
#import <Foundation/Foundation.h>
@interface BUYFakeSafariController : NSObject
@property (weak, nonatomic) id delegate;
@end
//
// BUYFakeSafariController.m
// Mobile Buy SDK
//
// Created by Shopify.
// Copyright (c) 2015 Shopify Inc. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//
#import "BUYFakeSafariController.h"
@implementation BUYFakeSafariController
- (instancetype)initWithURL:(NSURL *)URL {
return [self initWithURL:URL entersReaderIfAvailable:YES];
}
- (instancetype)initWithURL:(NSURL *)URL entersReaderIfAvailable:(BOOL)entersReaderIfAvailable {
return (id)[[[self class] alloc] init];
}
@end
...@@ -14,9 +14,12 @@ ...@@ -14,9 +14,12 @@
#import "BUYWebCheckoutPaymentProvider.h" #import "BUYWebCheckoutPaymentProvider.h"
#import "BUYClientTestBase.h" #import "BUYClientTestBase.h"
#import "BUYPaymentController.h" #import "BUYPaymentController.h"
#import "BUYFakeSafariController.h"
#import <OHHTTPStubs/OHHTTPStubs.h> #import <OHHTTPStubs/OHHTTPStubs.h>
@interface BUYPaymentController () extern Class SafariViewControllerClass;
@interface BUYPaymentController (Private)
- (id <BUYPaymentProvider>)providerForType:(NSString *)type; - (id <BUYPaymentProvider>)providerForType:(NSString *)type;
@end @end
...@@ -34,6 +37,15 @@ ...@@ -34,6 +37,15 @@
[super setUp]; [super setUp];
self.modelManager = [BUYModelManager modelManager]; self.modelManager = [BUYModelManager modelManager];
self.expectations = [@{} mutableCopy]; self.expectations = [@{} mutableCopy];
/* ---------------------------------
* We need to kick off the provider
* class initialization before setting
* the fake safari controller to
* prevent it getting overriden.
*/
[BUYWebCheckoutPaymentProvider class];
SafariViewControllerClass = [BUYFakeSafariController class];
} }
- (void)tearDown - (void)tearDown
......
...@@ -374,6 +374,7 @@ ...@@ -374,6 +374,7 @@
9A47CF221CE5112A00A6D5BA /* BUYAssert.h in Headers */ = {isa = PBXBuildFile; fileRef = 9A47CF211CE5112A00A6D5BA /* BUYAssert.h */; }; 9A47CF221CE5112A00A6D5BA /* BUYAssert.h in Headers */ = {isa = PBXBuildFile; fileRef = 9A47CF211CE5112A00A6D5BA /* BUYAssert.h */; };
9A47CF231CE5112A00A6D5BA /* BUYAssert.h in Headers */ = {isa = PBXBuildFile; fileRef = 9A47CF211CE5112A00A6D5BA /* BUYAssert.h */; }; 9A47CF231CE5112A00A6D5BA /* BUYAssert.h in Headers */ = {isa = PBXBuildFile; fileRef = 9A47CF211CE5112A00A6D5BA /* BUYAssert.h */; };
9A6B03791CDA5D4F0054C26E /* BUYAccountCredentialsTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 9A6B03781CDA5D4F0054C26E /* BUYAccountCredentialsTests.m */; }; 9A6B03791CDA5D4F0054C26E /* BUYAccountCredentialsTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 9A6B03781CDA5D4F0054C26E /* BUYAccountCredentialsTests.m */; };
9ABBCCA11CF5C9D10075B0C5 /* BUYFakeSafariController.m in Sources */ = {isa = PBXBuildFile; fileRef = 9ABBCCA01CF5C9D10075B0C5 /* BUYFakeSafariController.m */; };
B2653EC31CEF55CC0012D57D /* BUYModelManager+ApplePay.h in Headers */ = {isa = PBXBuildFile; fileRef = B2653EC11CEF55CC0012D57D /* BUYModelManager+ApplePay.h */; }; B2653EC31CEF55CC0012D57D /* BUYModelManager+ApplePay.h in Headers */ = {isa = PBXBuildFile; fileRef = B2653EC11CEF55CC0012D57D /* BUYModelManager+ApplePay.h */; };
B2653EC41CEF55CC0012D57D /* BUYModelManager+ApplePay.h in Headers */ = {isa = PBXBuildFile; fileRef = B2653EC11CEF55CC0012D57D /* BUYModelManager+ApplePay.h */; }; B2653EC41CEF55CC0012D57D /* BUYModelManager+ApplePay.h in Headers */ = {isa = PBXBuildFile; fileRef = B2653EC11CEF55CC0012D57D /* BUYModelManager+ApplePay.h */; };
B2653EC51CEF55CC0012D57D /* BUYModelManager+ApplePay.m in Sources */ = {isa = PBXBuildFile; fileRef = B2653EC21CEF55CC0012D57D /* BUYModelManager+ApplePay.m */; }; B2653EC51CEF55CC0012D57D /* BUYModelManager+ApplePay.m in Sources */ = {isa = PBXBuildFile; fileRef = B2653EC21CEF55CC0012D57D /* BUYModelManager+ApplePay.m */; };
...@@ -655,6 +656,8 @@ ...@@ -655,6 +656,8 @@
9A47CF1F1CE50EBB00A6D5BA /* BUYApplePayTestToken.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BUYApplePayTestToken.m; sourceTree = "<group>"; }; 9A47CF1F1CE50EBB00A6D5BA /* BUYApplePayTestToken.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BUYApplePayTestToken.m; sourceTree = "<group>"; };
9A47CF211CE5112A00A6D5BA /* BUYAssert.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = BUYAssert.h; path = ../Additions/BUYAssert.h; sourceTree = "<group>"; }; 9A47CF211CE5112A00A6D5BA /* BUYAssert.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = BUYAssert.h; path = ../Additions/BUYAssert.h; sourceTree = "<group>"; };
9A6B03781CDA5D4F0054C26E /* BUYAccountCredentialsTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BUYAccountCredentialsTests.m; sourceTree = "<group>"; }; 9A6B03781CDA5D4F0054C26E /* BUYAccountCredentialsTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BUYAccountCredentialsTests.m; sourceTree = "<group>"; };
9ABBCC9F1CF5C9D10075B0C5 /* BUYFakeSafariController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BUYFakeSafariController.h; sourceTree = "<group>"; };
9ABBCCA01CF5C9D10075B0C5 /* BUYFakeSafariController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BUYFakeSafariController.m; sourceTree = "<group>"; };
B2653EC11CEF55CC0012D57D /* BUYModelManager+ApplePay.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "BUYModelManager+ApplePay.h"; sourceTree = "<group>"; }; B2653EC11CEF55CC0012D57D /* BUYModelManager+ApplePay.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "BUYModelManager+ApplePay.h"; sourceTree = "<group>"; };
B2653EC21CEF55CC0012D57D /* BUYModelManager+ApplePay.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "BUYModelManager+ApplePay.m"; sourceTree = "<group>"; }; B2653EC21CEF55CC0012D57D /* BUYModelManager+ApplePay.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "BUYModelManager+ApplePay.m"; sourceTree = "<group>"; };
BE33B4ED1B15FF4D0067982B /* BUYApplePayAuthorizationDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BUYApplePayAuthorizationDelegate.h; sourceTree = "<group>"; }; BE33B4ED1B15FF4D0067982B /* BUYApplePayAuthorizationDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BUYApplePayAuthorizationDelegate.h; sourceTree = "<group>"; };
...@@ -1019,6 +1022,8 @@ ...@@ -1019,6 +1022,8 @@
children = ( children = (
9A47CF1E1CE50EBB00A6D5BA /* BUYApplePayTestToken.h */, 9A47CF1E1CE50EBB00A6D5BA /* BUYApplePayTestToken.h */,
9A47CF1F1CE50EBB00A6D5BA /* BUYApplePayTestToken.m */, 9A47CF1F1CE50EBB00A6D5BA /* BUYApplePayTestToken.m */,
9ABBCC9F1CF5C9D10075B0C5 /* BUYFakeSafariController.h */,
9ABBCCA01CF5C9D10075B0C5 /* BUYFakeSafariController.m */,
); );
name = "Test Objects"; name = "Test Objects";
sourceTree = "<group>"; sourceTree = "<group>";
...@@ -1643,6 +1648,7 @@ ...@@ -1643,6 +1648,7 @@
8498DCCC1CDD208200BD12A8 /* BUYCustomerTests.m in Sources */, 8498DCCC1CDD208200BD12A8 /* BUYCustomerTests.m in Sources */,
B2653EC51CEF55CC0012D57D /* BUYModelManager+ApplePay.m in Sources */, B2653EC51CEF55CC0012D57D /* BUYModelManager+ApplePay.m in Sources */,
8498DCCE1CDD208200BD12A8 /* BUYOrderTests.m in Sources */, 8498DCCE1CDD208200BD12A8 /* BUYOrderTests.m in Sources */,
9ABBCCA11CF5C9D10075B0C5 /* BUYFakeSafariController.m in Sources */,
9A0B0C831CEB981C0037D68F /* BUYClient+RoutingTests.m in Sources */, 9A0B0C831CEB981C0037D68F /* BUYClient+RoutingTests.m in Sources */,
849110351CCE70CE00E53B93 /* BUYDictionaryAdditionsTests.m in Sources */, 849110351CCE70CE00E53B93 /* BUYDictionaryAdditionsTests.m in Sources */,
90F5930A1B0D5F4C0026B382 /* BUYLineItemTest.m in Sources */, 90F5930A1B0D5F4C0026B382 /* BUYLineItemTest.m in Sources */,
......
...@@ -27,9 +27,12 @@ ...@@ -27,9 +27,12 @@
#import "BUYWebCheckoutPaymentProvider.h" #import "BUYWebCheckoutPaymentProvider.h"
#import "BUYCheckout.h" #import "BUYCheckout.h"
#import "BUYClient+CheckoutHelpers.h" #import "BUYClient+CheckoutHelpers.h"
#import "BUYAssert.h"
@import SafariServices; @import SafariServices;
Class SafariViewControllerClass;
NSString * BUYSafariCallbackURLNotification = @"kBUYSafariCallbackURLNotification"; NSString * BUYSafariCallbackURLNotification = @"kBUYSafariCallbackURLNotification";
NSString * BUYURLKey = @"url"; NSString * BUYURLKey = @"url";
NSString * const BUYWebPaymentProviderId = @"BUYWebPaymentProviderId"; NSString * const BUYWebPaymentProviderId = @"BUYWebPaymentProviderId";
...@@ -37,32 +40,60 @@ NSString * const BUYWebPaymentProviderId = @"BUYWebPaymentProviderId"; ...@@ -37,32 +40,60 @@ NSString * const BUYWebPaymentProviderId = @"BUYWebPaymentProviderId";
static NSString *const WebCheckoutCustomerAccessToken = @"customer_access_token"; static NSString *const WebCheckoutCustomerAccessToken = @"customer_access_token";
@interface BUYWebCheckoutPaymentProvider () <SFSafariViewControllerDelegate> @interface BUYWebCheckoutPaymentProvider () <SFSafariViewControllerDelegate>
@property (nonatomic, strong) BUYCheckout *checkout; @property (nonatomic, strong) BUYCheckout *checkout;
@property (nonatomic, strong) BUYClient *client; @property (nonatomic, strong) BUYClient *client;
@end @end
@implementation BUYWebCheckoutPaymentProvider @implementation BUYWebCheckoutPaymentProvider
@synthesize delegate; @synthesize delegate;
#pragma mark - Initialize -
+ (void)initialize
{
/* ----------------------------------
* Used in tests to set a fake / mock
* SFSafariViewController to avoid
* instantiating a real one.
*/
SafariViewControllerClass = [SFSafariViewController class];
}
#pragma mark - Init -
- (instancetype)initWithClient:(BUYClient *)client - (instancetype)initWithClient:(BUYClient *)client
{ {
NSParameterAssert(client); BUYAssert(client, @"Failed to initialize BUYWebCheckoutPaymentProvider, client must not be nil.");
self = [super init]; self = [super init];
if (self) { if (self) {
_client = client; _client = client;
} }
return self; return self;
} }
#pragma mark - Accessors -
- (BOOL)isAvailable
{
return YES;
}
- (BOOL)isInProgress - (BOOL)isInProgress
{ {
return (self.checkout != nil); return (self.checkout != nil);
} }
- (NSString *)identifier
{
return BUYWebPaymentProviderId;
}
#pragma mark - Equality -
- (NSUInteger)hash - (NSUInteger)hash
{ {
return self.identifier.hash; return self.identifier.hash;
...@@ -73,10 +104,7 @@ static NSString *const WebCheckoutCustomerAccessToken = @"customer_access_token" ...@@ -73,10 +104,7 @@ static NSString *const WebCheckoutCustomerAccessToken = @"customer_access_token"
return ([object isKindOfClass:[self class]] && [self.identifier isEqual:[object identifier]]); return ([object isKindOfClass:[self class]] && [self.identifier isEqual:[object identifier]]);
} }
- (NSString *)identifier #pragma mark - Checkout -
{
return BUYWebPaymentProviderId;
}
- (void)startCheckout:(BUYCheckout *)checkout - (void)startCheckout:(BUYCheckout *)checkout
{ {
...@@ -108,11 +136,6 @@ static NSString *const WebCheckoutCustomerAccessToken = @"customer_access_token" ...@@ -108,11 +136,6 @@ static NSString *const WebCheckoutCustomerAccessToken = @"customer_access_token"
self.checkout = nil; self.checkout = nil;
} }
- (BOOL)isAvailable
{
return YES;
}
- (void)postCheckoutCompletion:(BUYCheckout *)checkout error:(NSError *)error - (void)postCheckoutCompletion:(BUYCheckout *)checkout error:(NSError *)error
{ {
if (self.checkout && error == nil) { if (self.checkout && error == nil) {
...@@ -140,9 +163,9 @@ static NSString *const WebCheckoutCustomerAccessToken = @"customer_access_token" ...@@ -140,9 +163,9 @@ static NSString *const WebCheckoutCustomerAccessToken = @"customer_access_token"
- (void)openWebCheckout:(BUYCheckout *)checkout - (void)openWebCheckout:(BUYCheckout *)checkout
{ {
NSURL *checkoutURL = [self authenticatedWebCheckoutURL:checkout.webCheckoutURL]; NSURL *checkoutURL = [self authenticatedWebCheckoutURL:checkout.webCheckoutURL];
if ([SFSafariViewController class]) { if (SafariViewControllerClass) {
SFSafariViewController *safariViewController = [[SFSafariViewController alloc] initWithURL:checkoutURL]; SFSafariViewController *safariViewController = [[SafariViewControllerClass alloc] initWithURL:checkoutURL];
safariViewController.delegate = self; safariViewController.delegate = self;
[self.delegate paymentProvider:self wantsControllerPresented:safariViewController]; [self.delegate paymentProvider:self wantsControllerPresented:safariViewController];
} }
...@@ -163,7 +186,7 @@ static NSString *const WebCheckoutCustomerAccessToken = @"customer_access_token" ...@@ -163,7 +186,7 @@ static NSString *const WebCheckoutCustomerAccessToken = @"customer_access_token"
return authenticatedComponents.URL; return authenticatedComponents.URL;
} }
#pragma mark - Web Checkout delegate methods #pragma mark - Web Checkout Delegate Methods -
- (void)safariViewControllerDidFinish:(SFSafariViewController *)controller; - (void)safariViewControllerDidFinish:(SFSafariViewController *)controller;
{ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment