Commit 839f95b0 by Dima Bart

Convert deprecated BUYCheckout initializers to use model manager.

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