Commit 0935d49b by Dima Bart

Improve test coverage for BUYOperation subclasses.

parent 7b5cf27c
//
// BUYOperationTests.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 <XCTest/XCTest.h>
#import "BUYOperation.h"
@interface BUYOperationTests : XCTestCase
@end
@implementation BUYOperationTests
#pragma mark - Init -
- (void)testInit
{
BUYOperation *operation = [[BUYOperation alloc] init];
XCTAssertNotNil(operation);
}
#pragma mark - State -
- (void)testNormalExecutionFlow
{
BUYOperation *operation = [[BUYOperation alloc] init];
XCTAssertTrue(operation.isReady);
[operation start];
XCTAssertTrue(operation.isExecuting);
[operation finishExecution];
XCTAssertTrue(operation.isFinished);
XCTAssertFalse(operation.isCancelled);
}
- (void)testCancelledExecutionFlow
{
BUYOperation *operation = [[BUYOperation alloc] init];
XCTAssertTrue(operation.isReady);
[operation start];
XCTAssertTrue(operation.isExecuting);
[operation cancel];
XCTAssertTrue(operation.isCancelled);
XCTAssertTrue(operation.isFinished);
[operation cancelExecution];
XCTAssertTrue(operation.isFinished);
}
@end
...@@ -2,8 +2,26 @@ ...@@ -2,8 +2,26 @@
// BUYRequestOperationTests.m // BUYRequestOperationTests.m
// Mobile Buy SDK // Mobile Buy SDK
// //
// Created by Dima Bart on 2016-05-16. // Created by Shopify.
// Copyright © 2016 Shopify Inc. All rights reserved. // 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 <XCTest/XCTest.h> #import <XCTest/XCTest.h>
...@@ -239,8 +257,8 @@ ...@@ -239,8 +257,8 @@
[self createExpectationDelay]; [self createExpectationDelay];
[operation cancel];
[self.queue addOperation:operation]; [self.queue addOperation:operation];
[operation cancel];
[self waitForExpectationsWithTimeout:3.0 handler:nil]; [self waitForExpectationsWithTimeout:3.0 handler:nil];
} }
...@@ -262,6 +280,21 @@ ...@@ -262,6 +280,21 @@
[self waitForExpectationsWithTimeout:4.0 handler:nil]; [self waitForExpectationsWithTimeout:4.0 handler:nil];
} }
- (void)testCancellationWithoutQueue
{
[self stubRequestsWithDelay:0.5];
BUYRequestOperation *operation = [self operationFulfillingExpectation:nil completion:^{
XCTAssert(NO, @"Operation should not call completion if cancelled.");
}];
[operation start];
[operation cancel];
[self createExpectationDelay];
[self waitForExpectationsWithTimeout:4.0 handler:nil];
}
- (void)testCancellationDuringPolling - (void)testCancellationDuringPolling
{ {
[self stubRequestsWithDelay:0.1 status:BUYStatusProcessing]; [self stubRequestsWithDelay:0.1 status:BUYStatusProcessing];
......
...@@ -389,6 +389,7 @@ ...@@ -389,6 +389,7 @@
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 */; };
B2653EC61CEF55CC0012D57D /* BUYModelManager+ApplePay.m in Sources */ = {isa = PBXBuildFile; fileRef = B2653EC21CEF55CC0012D57D /* BUYModelManager+ApplePay.m */; }; B2653EC61CEF55CC0012D57D /* BUYModelManager+ApplePay.m in Sources */ = {isa = PBXBuildFile; fileRef = B2653EC21CEF55CC0012D57D /* BUYModelManager+ApplePay.m */; };
B2653EC71CEF55CC0012D57D /* BUYModelManager+ApplePay.m in Sources */ = {isa = PBXBuildFile; fileRef = B2653EC21CEF55CC0012D57D /* BUYModelManager+ApplePay.m */; }; B2653EC71CEF55CC0012D57D /* BUYModelManager+ApplePay.m in Sources */ = {isa = PBXBuildFile; fileRef = B2653EC21CEF55CC0012D57D /* BUYModelManager+ApplePay.m */; };
9A7652C31CF487BD00220E4B /* BUYOperationTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 9A7652C21CF487BD00220E4B /* BUYOperationTests.m */; };
BE47340F1B66C4EF00AA721A /* BUYError.h in Headers */ = {isa = PBXBuildFile; fileRef = BE47340D1B66C4EF00AA721A /* BUYError.h */; settings = {ATTRIBUTES = (Public, ); }; }; BE47340F1B66C4EF00AA721A /* BUYError.h in Headers */ = {isa = PBXBuildFile; fileRef = BE47340D1B66C4EF00AA721A /* BUYError.h */; settings = {ATTRIBUTES = (Public, ); }; };
BE4734101B66C4EF00AA721A /* BUYError.m in Sources */ = {isa = PBXBuildFile; fileRef = BE47340E1B66C4EF00AA721A /* BUYError.m */; }; BE4734101B66C4EF00AA721A /* BUYError.m in Sources */ = {isa = PBXBuildFile; fileRef = BE47340E1B66C4EF00AA721A /* BUYError.m */; };
BE5DC3631B71022D00B2BC1E /* BUYMaskedCreditCard.h in Headers */ = {isa = PBXBuildFile; fileRef = BE5DC3611B71022D00B2BC1E /* BUYMaskedCreditCard.h */; settings = {ATTRIBUTES = (Public, ); }; }; BE5DC3631B71022D00B2BC1E /* BUYMaskedCreditCard.h in Headers */ = {isa = PBXBuildFile; fileRef = BE5DC3611B71022D00B2BC1E /* BUYMaskedCreditCard.h */; settings = {ATTRIBUTES = (Public, ); }; };
...@@ -676,6 +677,9 @@ ...@@ -676,6 +677,9 @@
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>"; };
BE33B4EE1B15FF4D0067982B /* BUYApplePayAuthorizationDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BUYApplePayAuthorizationDelegate.m; sourceTree = "<group>"; }; BE33B4EE1B15FF4D0067982B /* BUYApplePayAuthorizationDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BUYApplePayAuthorizationDelegate.m; sourceTree = "<group>"; };
9A7652C21CF487BD00220E4B /* BUYOperationTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BUYOperationTests.m; sourceTree = "<group>"; };
BE33B4ED1B15FF4D0067982B /* BUYApplePayHelpers.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BUYApplePayHelpers.h; sourceTree = "<group>"; };
BE33B4EE1B15FF4D0067982B /* BUYApplePayHelpers.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BUYApplePayHelpers.m; sourceTree = "<group>"; };
BE47340D1B66C4EF00AA721A /* BUYError.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BUYError.h; sourceTree = "<group>"; }; BE47340D1B66C4EF00AA721A /* BUYError.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BUYError.h; sourceTree = "<group>"; };
BE47340E1B66C4EF00AA721A /* BUYError.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BUYError.m; sourceTree = "<group>"; }; BE47340E1B66C4EF00AA721A /* BUYError.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BUYError.m; sourceTree = "<group>"; };
BE5DC3611B71022D00B2BC1E /* BUYMaskedCreditCard.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BUYMaskedCreditCard.h; sourceTree = "<group>"; }; BE5DC3611B71022D00B2BC1E /* BUYMaskedCreditCard.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BUYMaskedCreditCard.h; sourceTree = "<group>"; };
...@@ -1006,6 +1010,7 @@ ...@@ -1006,6 +1010,7 @@
9A0B0C611CE9F8310037D68F /* Operation Tests */ = { 9A0B0C611CE9F8310037D68F /* Operation Tests */ = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
9A7652C21CF487BD00220E4B /* BUYOperationTests.m */,
9A0B0C621CE9F8530037D68F /* BUYRequestOperationTests.m */, 9A0B0C621CE9F8530037D68F /* BUYRequestOperationTests.m */,
); );
name = "Operation Tests"; name = "Operation Tests";
...@@ -1723,6 +1728,7 @@ ...@@ -1723,6 +1728,7 @@
BE98DB5C1BB1F4D000C29564 /* OHHTTPStubsResponse+Helpers.m in Sources */, BE98DB5C1BB1F4D000C29564 /* OHHTTPStubsResponse+Helpers.m in Sources */,
849110311CCE708900E53B93 /* BUYArrayAdditionsTests.m in Sources */, 849110311CCE708900E53B93 /* BUYArrayAdditionsTests.m in Sources */,
9A0B0C631CE9F8530037D68F /* BUYRequestOperationTests.m in Sources */, 9A0B0C631CE9F8530037D68F /* BUYRequestOperationTests.m in Sources */,
9A7652C31CF487BD00220E4B /* BUYOperationTests.m in Sources */,
8498DCCF1CDD208200BD12A8 /* BUYTestModel.xcdatamodeld in Sources */, 8498DCCF1CDD208200BD12A8 /* BUYTestModel.xcdatamodeld in Sources */,
); );
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;
......
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