Commit 839f95b0 by Dima Bart

Convert deprecated BUYCheckout initializers to use model manager.

parent 10f92a7e
...@@ -46,7 +46,7 @@ ...@@ -46,7 +46,7 @@
- (void)setUp - (void)setUp
{ {
_modelManager = [BUYModelManager modelManager]; _modelManager = [BUYModelManager modelManager];
_checkout = [[BUYCheckout alloc] initWithCart:nil]; _checkout = [[BUYCheckout alloc] initWithModelManager:_modelManager cart:nil];
} }
- (void)tearDown - (void)tearDown
......
...@@ -72,7 +72,7 @@ ...@@ -72,7 +72,7 @@
- (void)testInitWithCartAddsLineItems - (void)testInitWithCartAddsLineItems
{ {
[_cart addVariant:_variant]; [_cart addVariant:_variant];
BUYCheckout *checkout = [[BUYCheckout alloc] initWithCart:_cart]; BUYCheckout *checkout = [[BUYCheckout alloc] initWithModelManager:_modelManager cart:_cart];
XCTAssertEqual([[checkout lineItems] count], [[_cart lineItems] count]); XCTAssertEqual([[checkout lineItems] count], [[_cart lineItems] count]);
XCTAssertTrue([checkout isDirty]); XCTAssertTrue([checkout isDirty]);
} }
...@@ -140,7 +140,7 @@ ...@@ -140,7 +140,7 @@
- (void)testHasToken - (void)testHasToken
{ {
BUYCheckout *checkout = [[BUYCheckout alloc] initWithCart:_cart]; BUYCheckout *checkout = [[BUYCheckout alloc] initWithModelManager:_modelManager cart:_cart];
checkout.token = nil; checkout.token = nil;
XCTAssertFalse([checkout hasToken]); XCTAssertFalse([checkout hasToken]);
checkout.token = @""; checkout.token = @"";
......
...@@ -70,7 +70,7 @@ NSString * const BUYFakeCustomerToken = @"dsfasdgafdg"; ...@@ -70,7 +70,7 @@ NSString * const BUYFakeCustomerToken = @"dsfasdgafdg";
- (NSData *)dataForCartFromClient:(BUYClient *)client - (NSData *)dataForCartFromClient:(BUYClient *)client
{ {
BUYCart *cart = [self cart]; BUYCart *cart = [self cart];
BUYCheckout *checkout = [[BUYCheckout alloc] initWithCart:cart]; BUYCheckout *checkout = [[BUYCheckout alloc] initWithModelManager:cart.modelManager cart:cart];
BUYRequestOperation *task = (BUYRequestOperation *)[self.client createCheckout:checkout completion:^(BUYCheckout *checkout, NSError *error) {}]; BUYRequestOperation *task = (BUYRequestOperation *)[self.client createCheckout:checkout completion:^(BUYCheckout *checkout, NSError *error) {}];
XCTAssertNotNil(task); XCTAssertNotNil(task);
...@@ -99,7 +99,7 @@ NSString * const BUYFakeCustomerToken = @"dsfasdgafdg"; ...@@ -99,7 +99,7 @@ NSString * const BUYFakeCustomerToken = @"dsfasdgafdg";
- (void)testPartialAddressesFlag - (void)testPartialAddressesFlag
{ {
BUYCart *cart = [self cart]; BUYCart *cart = [self cart];
BUYCheckout *checkout = [[BUYCheckout alloc] initWithCart:cart]; BUYCheckout *checkout = [[BUYCheckout alloc] initWithModelManager:cart.modelManager cart:cart];
XCTAssertThrows([checkout setPartialAddressesValue:NO]); XCTAssertThrows([checkout setPartialAddressesValue:NO]);
...@@ -107,7 +107,7 @@ NSString * const BUYFakeCustomerToken = @"dsfasdgafdg"; ...@@ -107,7 +107,7 @@ NSString * const BUYFakeCustomerToken = @"dsfasdgafdg";
NSDictionary *json = [NSJSONSerialization JSONObjectWithData:task.originalRequest.HTTPBody options:0 error:nil]; NSDictionary *json = [NSJSONSerialization JSONObjectWithData:task.originalRequest.HTTPBody options:0 error:nil];
XCTAssertFalse([json[@"checkout"][@"partial_addresses"] boolValue]); XCTAssertFalse([json[@"checkout"][@"partial_addresses"] boolValue]);
checkout = [[BUYCheckout alloc] initWithCart:cart]; checkout = [[BUYCheckout alloc] initWithModelManager:cart.modelManager cart:cart];
BUYAddress *partialAddress = [self.client.modelManager insertAddressWithJSONDictionary:nil]; BUYAddress *partialAddress = [self.client.modelManager insertAddressWithJSONDictionary:nil];
partialAddress.address1 = nil; partialAddress.address1 = nil;
......
...@@ -101,7 +101,7 @@ ...@@ -101,7 +101,7 @@
{ {
[OHHTTPStubs stubUsingResponseWithKey:@"testCheckoutFlowUsingCreditCard_1" useMocks:[self shouldUseMocks]]; [OHHTTPStubs stubUsingResponseWithKey:@"testCheckoutFlowUsingCreditCard_1" useMocks:[self shouldUseMocks]];
_checkout = [[BUYCheckout alloc] initWithCart:_cart]; _checkout = [[BUYCheckout alloc] initWithModelManager:_modelManager cart:_cart];
_checkout.shippingAddress = [self shippingAddress]; _checkout.shippingAddress = [self shippingAddress];
_checkout.billingAddress = [self billingAddress]; _checkout.billingAddress = [self billingAddress];
XCTestExpectation *expectation = [self expectationWithDescription:NSStringFromSelector(_cmd)]; XCTestExpectation *expectation = [self expectationWithDescription:NSStringFromSelector(_cmd)];
...@@ -124,7 +124,7 @@ ...@@ -124,7 +124,7 @@
[OHHTTPStubs stubUsingResponseWithKey:@"testCheckoutFlowUsingCreditCard_1" useMocks:[self shouldUseMocks]]; [OHHTTPStubs stubUsingResponseWithKey:@"testCheckoutFlowUsingCreditCard_1" useMocks:[self shouldUseMocks]];
[self createCart]; [self createCart];
_checkout = [[BUYCheckout alloc] initWithCart:_cart]; _checkout = [[BUYCheckout alloc] initWithModelManager:_modelManager cart:_cart];
NSString *note = @"Order note"; NSString *note = @"Order note";
_checkout.note = note; _checkout.note = note;
...@@ -709,7 +709,7 @@ ...@@ -709,7 +709,7 @@
- (void)testCheckoutWithInvalidShop - (void)testCheckoutWithInvalidShop
{ {
[self createCart]; [self createCart];
_checkout = [[BUYCheckout alloc] initWithCart:_cart]; _checkout = [[BUYCheckout alloc] initWithModelManager:_modelManager cart:_cart];
XCTestExpectation *expectation = [self expectationWithDescription:NSStringFromSelector(_cmd)]; XCTestExpectation *expectation = [self expectationWithDescription:NSStringFromSelector(_cmd)];
[OHHTTPStubs stubUsingResponseWithKey:@"testInvalidIntegrationBadShopUrl_0" useMocks:[self shouldUseMocks]]; [OHHTTPStubs stubUsingResponseWithKey:@"testInvalidIntegrationBadShopUrl_0" useMocks:[self shouldUseMocks]];
...@@ -733,7 +733,7 @@ ...@@ -733,7 +733,7 @@
[OHHTTPStubs stubUsingResponseWithKey:@"testFetchingShippingRatesWithoutShippingAddress_1" useMocks:[self shouldUseMocks]]; [OHHTTPStubs stubUsingResponseWithKey:@"testFetchingShippingRatesWithoutShippingAddress_1" useMocks:[self shouldUseMocks]];
[self createCart]; [self createCart];
_checkout = [[BUYCheckout alloc] initWithCart:_cart]; _checkout = [[BUYCheckout alloc] initWithModelManager:_modelManager cart:_cart];
XCTestExpectation *expectation = [self expectationWithDescription:NSStringFromSelector(_cmd)]; XCTestExpectation *expectation = [self expectationWithDescription:NSStringFromSelector(_cmd)];
[self.client createCheckout:_checkout completion:^(BUYCheckout *returnedCheckout, NSError *error) { [self.client createCheckout:_checkout completion:^(BUYCheckout *returnedCheckout, NSError *error) {
...@@ -766,7 +766,7 @@ ...@@ -766,7 +766,7 @@
{ {
[OHHTTPStubs stubUsingResponseWithKey:@"testFetchingShippingRatesWithInvalidCheckout_1" useMocks:[self shouldUseMocks]]; [OHHTTPStubs stubUsingResponseWithKey:@"testFetchingShippingRatesWithInvalidCheckout_1" useMocks:[self shouldUseMocks]];
BUYCheckout *checkout = [[BUYCheckout alloc] initWithCart:nil]; BUYCheckout *checkout = [[BUYCheckout alloc] initWithModelManager:_modelManager cart:nil];
checkout.token = @"bananaaaa"; checkout.token = @"bananaaaa";
XCTestExpectation *expectation = [self expectationWithDescription:NSStringFromSelector(_cmd)]; XCTestExpectation *expectation = [self expectationWithDescription:NSStringFromSelector(_cmd)];
...@@ -792,7 +792,7 @@ ...@@ -792,7 +792,7 @@
- (void)testCheckoutWithAPartialAddress - (void)testCheckoutWithAPartialAddress
{ {
[self createCart]; [self createCart];
_checkout = [[BUYCheckout alloc] initWithCart:_cart]; _checkout = [[BUYCheckout alloc] initWithModelManager:_modelManager cart:_cart];
_checkout.shippingAddress = [self partialShippingAddress]; _checkout.shippingAddress = [self partialShippingAddress];
if ([_checkout.shippingAddress isPartialAddress]) { if ([_checkout.shippingAddress isPartialAddress]) {
...@@ -836,7 +836,7 @@ ...@@ -836,7 +836,7 @@
[OHHTTPStubs stubUsingResponseWithKey:@"testCreateCheckoutWithValidDiscount_1" useMocks:[self shouldUseMocks]]; [OHHTTPStubs stubUsingResponseWithKey:@"testCreateCheckoutWithValidDiscount_1" useMocks:[self shouldUseMocks]];
_checkout = [[BUYCheckout alloc] initWithCart:_cart]; _checkout = [[BUYCheckout alloc] initWithModelManager:_modelManager cart:_cart];
_checkout.discount = [self applicableDiscount]; _checkout.discount = [self applicableDiscount];
// Create the checkout // Create the checkout
...@@ -865,7 +865,7 @@ ...@@ -865,7 +865,7 @@
[OHHTTPStubs stubUsingResponseWithKey:@"testCreateCheckoutWithExpiredDiscount_1" useMocks:[self shouldUseMocks]]; [OHHTTPStubs stubUsingResponseWithKey:@"testCreateCheckoutWithExpiredDiscount_1" useMocks:[self shouldUseMocks]];
_checkout = [[BUYCheckout alloc] initWithCart:_cart]; _checkout = [[BUYCheckout alloc] initWithModelManager:_modelManager cart:_cart];
_checkout.discount = [self inapplicableDiscount]; _checkout.discount = [self inapplicableDiscount];
//Create the checkout //Create the checkout
...@@ -887,7 +887,7 @@ ...@@ -887,7 +887,7 @@
[OHHTTPStubs stubUsingResponseWithKey:@"testCreateCheckoutWithNonExistentDiscount_1" useMocks:[self shouldUseMocks]]; [OHHTTPStubs stubUsingResponseWithKey:@"testCreateCheckoutWithNonExistentDiscount_1" useMocks:[self shouldUseMocks]];
_checkout = [[BUYCheckout alloc] initWithCart:_cart]; _checkout = [[BUYCheckout alloc] initWithModelManager:_modelManager cart:_cart];
_checkout.discount = [self nonExistentDiscount]; _checkout.discount = [self nonExistentDiscount];
//Create the checkout //Create the checkout
......
...@@ -39,8 +39,8 @@ ...@@ -39,8 +39,8 @@
@property (nonatomic) BOOL hasToken; @property (nonatomic) BOOL hasToken;
- (instancetype)initWithCart:(BUYCart *)cart NS_DEPRECATED_IOS(8_0, 9_0, "Use `BUYModelManager` to create new instances of model objects instead"); - (instancetype)initWithModelManager:(id<BUYModelManager>)modelManager cart:(BUYCart *)cart;
- (instancetype)initWithCartToken:(NSString *)token NS_DEPRECATED_IOS(8_0, 9_0, "Use `BUYModelManager` to create new instances of model objects instead");; - (instancetype)initWithModelManager:(id<BUYModelManager>)modelManager cartToken:(NSString *)token;
- (void)updateWithCart:(BUYCart *)cart; - (void)updateWithCart:(BUYCart *)cart;
......
...@@ -94,18 +94,18 @@ ...@@ -94,18 +94,18 @@
} }
#endif #endif
- (instancetype)initWithCart:(BUYCart *)cart - (instancetype)initWithModelManager:(id<BUYModelManager>)modelManager cart:(BUYCart *)cart
{ {
self = [self initWithModelManager:cart.modelManager JSONDictionary:nil]; self = [self initWithModelManager:modelManager JSONDictionary:nil];
if (self) { if (self) {
[self updateWithCart:cart]; [self updateWithCart:cart];
} }
return self; return self;
} }
- (instancetype)initWithCartToken:(NSString *)token - (instancetype)initWithModelManager:(id<BUYModelManager>)modelManager cartToken:(NSString *)token
{ {
self = [self initWithModelManager:nil JSONDictionary:nil]; self = [self initWithModelManager:modelManager JSONDictionary:nil];
if (self) { if (self) {
self.cartToken = token; self.cartToken = token;
} }
......
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