Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
shopify_iossdk
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
cemarose
shopify_iossdk
Commits
fa883965
Commit
fa883965
authored
May 16, 2016
by
Dima Bart
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add tests for BUYRequestOperation.
parent
a22d1f29
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
291 additions
and
0 deletions
+291
-0
BUYRequestOperationTests.m
...e Buy SDK/Mobile Buy SDK Tests/BUYRequestOperationTests.m
+216
-0
project.pbxproj
Mobile Buy SDK/Mobile Buy SDK.xcodeproj/project.pbxproj
+75
-0
No files found.
Mobile Buy SDK/Mobile Buy SDK Tests/BUYRequestOperationTests.m
0 → 100644
View file @
fa883965
//
// BUYRequestOperationTests.m
// Mobile Buy SDK
//
// Created by Dima Bart on 2016-05-16.
// Copyright © 2016 Shopify Inc. All rights reserved.
//
#import <XCTest/XCTest.h>
#import <OHHTTPStubs/OHHTTPStubs.h>
#import "BUYRequestOperation.h"
@interface
BUYRequestOperationTests
:
XCTestCase
@property
(
strong
,
nonatomic
)
NSOperationQueue
*
queue
;
@property
(
strong
,
nonatomic
)
NSURLSession
*
session
;
@property
(
strong
,
nonatomic
)
NSMutableURLRequest
*
request
;
@end
@implementation
BUYRequestOperationTests
#pragma mark - Setup -
-
(
void
)
setUp
{
[
super
setUp
];
self
.
request
=
[
NSMutableURLRequest
requestWithURL
:[
NSURL
URLWithString
:
@"https://www.google.com"
]];
self
.
queue
=
[
NSOperationQueue
new
];
self
.
session
=
[
NSURLSession
sessionWithConfiguration
:[
NSURLSessionConfiguration
defaultSessionConfiguration
]
delegate
:
nil
delegateQueue
:
self
.
queue
];
}
#pragma mark - Tests -
-
(
void
)
testInit
{
BUYRequestOperation
*
operation
=
[
BUYRequestOperation
operationWithSession
:
self
.
session
request
:
self
.
request
payload
:
nil
completion
:^
(
NSDictionary
*
json
,
NSURLResponse
*
response
,
NSError
*
error
)
{
// We don't start the session
}];
XCTAssertNotNil
(
operation
);
XCTAssertEqualObjects
(
operation
.
session
,
self
.
session
);
XCTAssertEqualObjects
(
operation
.
originalRequest
,
self
.
request
);
}
#pragma mark - No Queue Tests -
-
(
void
)
testOperationWithoutQueue
{
[
self
stubRequests
];
XCTestExpectation
*
expectation
=
[
self
expectationWithDescription
:
@"Expect successful operation"
];
BUYRequestOperation
*
operation
=
[
self
operationFulfillingExpectation
:
expectation
completion
:
nil
];
[
operation
start
];
[
self
waitForExpectationsWithTimeout
:
3
.
0
handler
:
nil
];
}
#pragma mark - Dependency Tests -
-
(
void
)
testSerialSuccessfulDependencies
{
[
self
stubRequests
];
__block
NSMutableString
*
container
=
[
@""
mutableCopy
];
XCTestExpectation
*
expectation1
=
[
self
expectationWithDescription
:
@"Expect operation 1"
];
BUYRequestOperation
*
operation1
=
[
self
operationFulfillingExpectation
:
expectation1
completion
:
^
{
[
container
appendString
:
@"1"
];
}];
XCTestExpectation
*
expectation2
=
[
self
expectationWithDescription
:
@"Expect operation 2"
];
BUYRequestOperation
*
operation2
=
[
self
operationFulfillingExpectation
:
expectation2
completion
:
^
{
[
container
appendString
:
@"2"
];
}];
[
operation2
addDependency
:
operation1
];
[
self
.
queue
addOperation
:
operation2
];
[
self
.
queue
addOperation
:
operation1
];
[
self
waitForExpectationsWithTimeout
:
10
.
0
handler
:
nil
];
XCTAssertEqualObjects
(
container
,
@"12"
);
}
-
(
void
)
testParallelSuccessfulDependencies
{
[
self
stubRequests
];
__block
NSMutableString
*
container
=
[
@""
mutableCopy
];
XCTestExpectation
*
expectation1
=
[
self
expectationWithDescription
:
@"Expect operation 1"
];
BUYRequestOperation
*
operation1
=
[
self
operationFulfillingExpectation
:
expectation1
completion
:
^
{
[
container
appendString
:
@"1"
];
}];
XCTestExpectation
*
expectation2
=
[
self
expectationWithDescription
:
@"Expect operation 2"
];
BUYRequestOperation
*
operation2
=
[
self
operationFulfillingExpectation
:
expectation2
completion
:
^
{
[
container
appendString
:
@"1"
];
}];
XCTestExpectation
*
expectation3
=
[
self
expectationWithDescription
:
@"Expect operation 3"
];
BUYRequestOperation
*
operation3
=
[
self
operationFulfillingExpectation
:
expectation3
completion
:
^
{
[
container
appendString
:
@"2"
];
}];
[
operation3
addDependency
:
operation1
];
[
operation3
addDependency
:
operation2
];
[
self
.
queue
addOperation
:
operation3
];
[
self
.
queue
addOperation
:
operation2
];
[
self
.
queue
addOperation
:
operation1
];
[
self
waitForExpectationsWithTimeout
:
10
.
0
handler
:
nil
];
XCTAssertEqualObjects
(
container
,
@"112"
);
}
-
(
void
)
testCancellationBeforeExecution
{
[
self
stubRequests
];
BUYRequestOperation
*
operation
=
[
self
operationFulfillingExpectation
:
nil
completion
:
^
{
XCTAssert
(
NO
,
@"Operation should not call completion if cancelled."
);
}];
[
self
createExpectationDelay
];
[
operation
cancel
];
[
self
.
queue
addOperation
:
operation
];
[
self
waitForExpectationsWithTimeout
:
3
.
0
handler
:
nil
];
}
-
(
void
)
testCancellationDuringExecution
{
[
self
stubRequestsWithDelay
:
2
.
0
];
BUYRequestOperation
*
operation
=
[
self
operationFulfillingExpectation
:
nil
completion
:
^
{
XCTAssert
(
NO
,
@"Operation should not call completion if cancelled."
);
}];
[
self
createExpectationDelay
:
3
.
0
];
[
self
.
queue
addOperation
:
operation
];
[
self
after
:
1
.
0
block
:
^
{
[
operation
cancel
];
}];
[
self
waitForExpectationsWithTimeout
:
4
.
0
handler
:
nil
];
}
#pragma mark - Convenience -
-
(
void
)
asyncMain
:
(
dispatch_block_t
)
block
{
dispatch_async
(
dispatch_get_main_queue
(),
block
);
}
-
(
void
)
after
:
(
NSTimeInterval
)
delay
block
:
(
dispatch_block_t
)
block
{
dispatch_after
(
dispatch_time
(
DISPATCH_TIME_NOW
,
(
int64_t
)(
delay
*
NSEC_PER_SEC
)),
dispatch_get_main_queue
(),
block
);
}
-
(
void
)
createExpectationDelay
{
[
self
createExpectationDelay
:
1
.
0
];
}
-
(
void
)
createExpectationDelay
:
(
NSTimeInterval
)
delay
{
XCTestExpectation
*
expectation
=
[
self
expectationWithDescription
:
@"Delay"
];
[
self
after
:
delay
block
:
^
{
[
expectation
fulfill
];
}];
}
-
(
BUYRequestOperation
*
)
operationFulfillingExpectation
:
(
XCTestExpectation
*
)
expectation
completion
:
(
dispatch_block_t
)
completion
{
BUYRequestOperation
*
operation
=
[
BUYRequestOperation
operationWithSession
:
self
.
session
request
:
self
.
request
payload
:
nil
completion
:^
(
NSDictionary
*
json
,
NSURLResponse
*
response
,
NSError
*
error
)
{
[
self
asyncMain
:
^
{
if
(
completion
)
{
completion
();
}
[
expectation
fulfill
];
}];
}];
return
operation
;
}
#pragma mark - Stubs -
-
(
void
)
stubRequests
{
[
self
stubRequestsWithDelay
:
0
.
0
];
}
-
(
void
)
stubRequestsWithDelay
:
(
NSTimeInterval
)
delay
{
NSDictionary
*
payload
=
@{
@"first_name"
:
@"John"
,
@"last_name"
:
@"Smith"
,
};
NSData
*
payloadData
=
[
NSJSONSerialization
dataWithJSONObject
:
payload
options
:
0
error
:
nil
];
OHHTTPStubsResponse
*
response
=
[
OHHTTPStubsResponse
responseWithData
:
payloadData
statusCode
:
200
headers
:
nil
];
response
.
requestTime
=
delay
;
[
OHHTTPStubs
stubRequestsPassingTest
:
^
BOOL
(
NSURLRequest
*
request
)
{
return
YES
;
}
withStubResponse
:
^
OHHTTPStubsResponse
*
_Nonnull
(
NSURLRequest
*
request
)
{
return
response
;
}];
}
@end
Mobile Buy SDK/Mobile Buy SDK.xcodeproj/project.pbxproj
View file @
fa883965
...
...
@@ -363,6 +363,7 @@
9A0B0C5E1CE662ED0037D68F
/* BUYRequestOperation.m in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
9A585C121CE65811001F20F0
/* BUYRequestOperation.m */
;
};
9A0B0C5F1CE662EF0037D68F
/* BUYRequestOperation.h in Headers */
=
{
isa
=
PBXBuildFile
;
fileRef
=
9A585C111CE65811001F20F0
/* BUYRequestOperation.h */
;
};
9A0B0C601CE662EF0037D68F
/* BUYRequestOperation.h in Headers */
=
{
isa
=
PBXBuildFile
;
fileRef
=
9A585C111CE65811001F20F0
/* BUYRequestOperation.h */
;
};
9A0B0C631CE9F8530037D68F
/* BUYRequestOperationTests.m in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
9A0B0C621CE9F8530037D68F
/* BUYRequestOperationTests.m */
;
};
9A102D1B1CDD1F960026CC43
/* BUYErrorTests.m in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
9A102D1A1CDD1F960026CC43
/* BUYErrorTests.m */
;
};
9A102D1E1CDD25980026CC43
/* BUYOptionValueTests.m in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
9A102D1D1CDD25980026CC43
/* BUYOptionValueTests.m */
;
};
9A47CEFD1CE39F6000A6D5BA
/* BUYCreditCardToken.m in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
9A47CEFB1CE39F5B00A6D5BA
/* BUYCreditCardToken.m */
;
};
...
...
@@ -668,6 +669,8 @@
9A0B0C711CEB52B90037D68F
/* BUYClient+Checkout.m */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.c.objc
;
path
=
"BUYClient+Checkout.m"
;
sourceTree
=
"<group>"
;
};
9A0B0C761CEB5BBD0037D68F
/* BUYAuthenticatedResponse.h */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.c.h
;
path
=
BUYAuthenticatedResponse.h
;
sourceTree
=
"<group>"
;
};
9A0B0C771CEB5BBD0037D68F
/* BUYAuthenticatedResponse.m */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.c.objc
;
path
=
BUYAuthenticatedResponse.m
;
sourceTree
=
"<group>"
;
};
9A0B0C821CEB981C0037D68F
/* BUYClient+RoutingTests.m */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.c.objc
;
path
=
"BUYClient+RoutingTests.m"
;
sourceTree
=
"<group>"
;
};
9A0B0C621CE9F8530037D68F
/* BUYRequestOperationTests.m */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.c.objc
;
path
=
BUYRequestOperationTests.m
;
sourceTree
=
"<group>"
;
};
9A102D1A1CDD1F960026CC43
/* BUYErrorTests.m */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.c.objc
;
path
=
BUYErrorTests.m
;
sourceTree
=
"<group>"
;
};
9A102D1D1CDD25980026CC43
/* BUYOptionValueTests.m */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.c.objc
;
path
=
BUYOptionValueTests.m
;
sourceTree
=
"<group>"
;
};
9A47CEF81CE39EC200A6D5BA
/* BUYPaymentToken.h */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
sourcecode.c.h
;
path
=
BUYPaymentToken.h
;
sourceTree
=
"<group>"
;
};
...
...
@@ -967,6 +970,7 @@
isa
=
PBXGroup
;
children
=
(
9A47CF1D1CE50EAB00A6D5BA
/* Test Objects */
,
9A0B0C611CE9F8310037D68F
/* Operation Tests */
,
9A47CF0B1CE4D6A500A6D5BA
/* Payment Session Providers */
,
9A102D1C1CDD257D0026CC43
/* Models Tests */
,
90F592F91B0D5F4C0026B382
/* BUYApplePayAdditionsTest.m */
,
...
...
@@ -1019,6 +1023,76 @@
name
=
"Supporting Files"
;
sourceTree
=
"<group>"
;
};
90FC31AA1B50576400AFAB51
/* Variant Selection */
=
{
isa
=
PBXGroup
;
children
=
(
BEB74A251B554BFB0005A300
/* BUYOptionSelectionNavigationController.h */
,
BEB74A261B554BFB0005A300
/* BUYOptionSelectionNavigationController.m */
,
BE9496AE1B4D96D800B38949
/* BUYOptionSelectionViewController.h */
,
BE9496AF1B4D96D800B38949
/* BUYOptionSelectionViewController.m */
,
BEB74A1F1B554BF20005A300
/* BUYPresentationControllerForVariantSelection.h */
,
BEB74A201B554BF20005A300
/* BUYPresentationControllerForVariantSelection.m */
,
90DE926E1B9897B6002EF4DA
/* BUYVariantOptionBreadCrumbsView.h */
,
90DE926F1B9897B6002EF4DA
/* BUYVariantOptionBreadCrumbsView.m */
,
90516CA11B4D771400E35E45
/* BUYVariantOptionView.h */
,
90516CA21B4D771400E35E45
/* BUYVariantOptionView.m */
,
BE9496B01B4D96D800B38949
/* BUYVariantSelectionViewController.h */
,
BE9496B11B4D96D800B38949
/* BUYVariantSelectionViewController.m */
,
BE1007981B6165CD0031CEE7
/* Cells */
,
);
name
=
"Variant Selection"
;
path
=
"Product View/Variant Selection"
;
sourceTree
=
"<group>"
;
};
90FC31AB1B50589800AFAB51
/* Product View */
=
{
isa
=
PBXGroup
;
children
=
(
900396AE1B67BD0A00226B73
/* BUYCheckoutButton.h */
,
900396AF1B67BD0A00226B73
/* BUYCheckoutButton.m */
,
90516CB21B4EE5E700E35E45
/* BUYGradientView.h */
,
90516CB31B4EE5E700E35E45
/* BUYGradientView.m */
,
90516CAE1B4EC9FE00E35E45
/* BUYImageView.h */
,
90516CAF1B4EC9FE00E35E45
/* BUYImageView.m */
,
90516CC11B4F1ED700E35E45
/* BUYNavigationController.h */
,
90516CC21B4F1ED700E35E45
/* BUYNavigationController.m */
,
905AA96F1B3B32A500CAE037
/* BUYPaymentButton.h */
,
905AA9701B3B32A500CAE037
/* BUYPaymentButton.m */
,
90516CBD1B4F110A00E35E45
/* BUYPresentationControllerWithNavigationController.h */
,
90516CBE1B4F110A00E35E45
/* BUYPresentationControllerWithNavigationController.m */
,
904606AD1B6BC8D700754173
/* BUYProductImageCollectionViewCell.h */
,
904606AE1B6BC8D700754173
/* BUYProductImageCollectionViewCell.m */
,
900396AA1B627CB900226B73
/* BUYProductView.h */
,
900396AB1B627CB900226B73
/* BUYProductView.m */
,
905ECCC01B4C39710094F336
/* BUYProductViewController.h */
,
905ECCC11B4C39710094F336
/* BUYProductViewController.m */
,
903BCC7A1B7D1C2D00C21FEB
/* BUYProductViewErrorView.h */
,
903BCC7B1B7D1C2D00C21FEB
/* BUYProductViewErrorView.m */
,
90516C791B4C589A00E35E45
/* BUYProductViewFooter.h */
,
90516C7A1B4C589A00E35E45
/* BUYProductViewFooter.m */
,
90516C851B4C6F7000E35E45
/* BUYProductViewHeader.h */
,
90516C861B4C6F7000E35E45
/* BUYProductViewHeader.m */
,
90FC31A61B50371600AFAB51
/* BUYProductViewHeaderBackgroundImageView.h */
,
90FC31A71B50371600AFAB51
/* BUYProductViewHeaderBackgroundImageView.m */
,
907874971B7276BA0023775B
/* BUYProductViewHeaderOverlay.h */
,
907874981B7276BA0023775B
/* BUYProductViewHeaderOverlay.m */
,
90516CB61B4F0DD500E35E45
/* BUYTheme.h */
,
90516CB71B4F0DD500E35E45
/* BUYTheme.m */
,
906EAE411B836DE000976165
/* BUYTheme+Additions.h */
,
906EAE421B836DE000976165
/* BUYTheme+Additions.m */
,
BE2E1D371B599039009610DA
/* Cells */
,
90FC31AA1B50576400AFAB51
/* Variant Selection */
,
);
name
=
"Product View"
;
sourceTree
=
"<group>"
;
};
9A0B0C611CE9F8310037D68F
/* Operation Tests */
=
{
isa
=
PBXGroup
;
children
=
(
9A0B0C621CE9F8530037D68F
/* BUYRequestOperationTests.m */
,
);
name
=
"Operation Tests"
;
sourceTree
=
"<group>"
;
};
9A102D1C1CDD257D0026CC43
/* Models Tests */
=
{
isa
=
PBXGroup
;
children
=
(
...
...
@@ -1790,6 +1864,7 @@
8498DCCD1CDD208200BD12A8
/* BUYModelManagerTests.m in Sources */
,
BE98DB5C1BB1F4D000C29564
/* OHHTTPStubsResponse+Helpers.m in Sources */
,
849110311CCE708900E53B93
/* BUYArrayAdditionsTests.m in Sources */
,
9A0B0C631CE9F8530037D68F
/* BUYRequestOperationTests.m in Sources */
,
8498DCCF1CDD208200BD12A8
/* BUYTestModel.xcdatamodeld in Sources */
,
);
runOnlyForDeploymentPostprocessing
=
0
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment