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
36eb71af
Commit
36eb71af
authored
9 years ago
by
Dima Bart
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor tests. Add test for data integrity.
parent
fa883965
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
53 additions
and
3 deletions
+53
-3
BUYRequestOperationTests.m
...e Buy SDK/Mobile Buy SDK Tests/BUYRequestOperationTests.m
+53
-3
No files found.
Mobile Buy SDK/Mobile Buy SDK Tests/BUYRequestOperationTests.m
View file @
36eb71af
...
@@ -58,6 +58,40 @@
...
@@ -58,6 +58,40 @@
[
self
waitForExpectationsWithTimeout
:
3
.
0
handler
:
nil
];
[
self
waitForExpectationsWithTimeout
:
3
.
0
handler
:
nil
];
}
}
#pragma mark - Data Tests -
-
(
void
)
testSuccessfulRequest
{
NSDictionary
*
payload
=
@{
@"name"
:
@"Water"
,
@"type"
:
@"liquid"
,
@"melting_point"
:
@0.0
,
};
NSData
*
payloadData
=
[
NSJSONSerialization
dataWithJSONObject
:
payload
options
:
0
error
:
nil
];
OHHTTPStubsResponse
*
response
=
[
OHHTTPStubsResponse
responseWithData
:
payloadData
statusCode
:
200
headers
:
nil
];
[
OHHTTPStubs
stubRequestsPassingTest
:
^
BOOL
(
NSURLRequest
*
request
)
{
return
YES
;
}
withStubResponse
:
^
OHHTTPStubsResponse
*
(
NSURLRequest
*
request
)
{
return
response
;
}];
XCTestExpectation
*
expectation
=
[
self
expectationWithDescription
:
@"Expect successful operation"
];
BUYRequestOperation
*
operation
=
[
self
operationFulfillingExpectation
:
expectation
responseCompletion
:
^
(
NSDictionary
*
json
,
NSHTTPURLResponse
*
response
,
NSError
*
error
)
{
XCTAssertNotNil
(
json
);
XCTAssertNotNil
(
response
);
XCTAssertNil
(
error
);
XCTAssertEqualObjects
(
json
,
payload
);
XCTAssertEqual
(
response
.
statusCode
,
200
);
}];
[
self
.
queue
addOperation
:
operation
];
[
self
waitForExpectationsWithTimeout
:
3
.
0
handler
:
nil
];
}
#pragma mark - Dependency Tests -
#pragma mark - Dependency Tests -
-
(
void
)
testSerialSuccessfulDependencies
-
(
void
)
testSerialSuccessfulDependencies
...
@@ -102,18 +136,25 @@
...
@@ -102,18 +136,25 @@
XCTestExpectation
*
expectation3
=
[
self
expectationWithDescription
:
@"Expect operation 3"
];
XCTestExpectation
*
expectation3
=
[
self
expectationWithDescription
:
@"Expect operation 3"
];
BUYRequestOperation
*
operation3
=
[
self
operationFulfillingExpectation
:
expectation3
completion
:
^
{
BUYRequestOperation
*
operation3
=
[
self
operationFulfillingExpectation
:
expectation3
completion
:
^
{
[
container
appendString
:
@"
2
"
];
[
container
appendString
:
@"
3
"
];
}];
}];
XCTestExpectation
*
expectation4
=
[
self
expectationWithDescription
:
@"Expect operation 4"
];
BUYRequestOperation
*
operation4
=
[
self
operationFulfillingExpectation
:
expectation4
completion
:
^
{
[
container
appendString
:
@"4"
];
}];
[
operation4
addDependency
:
operation3
];
[
operation3
addDependency
:
operation1
];
[
operation3
addDependency
:
operation1
];
[
operation3
addDependency
:
operation2
];
[
operation3
addDependency
:
operation2
];
[
self
.
queue
addOperation
:
operation4
];
[
self
.
queue
addOperation
:
operation3
];
[
self
.
queue
addOperation
:
operation3
];
[
self
.
queue
addOperation
:
operation2
];
[
self
.
queue
addOperation
:
operation2
];
[
self
.
queue
addOperation
:
operation1
];
[
self
.
queue
addOperation
:
operation1
];
[
self
waitForExpectationsWithTimeout
:
10
.
0
handler
:
nil
];
[
self
waitForExpectationsWithTimeout
:
10
.
0
handler
:
nil
];
XCTAssertEqualObjects
(
container
,
@"11
2
"
);
XCTAssertEqualObjects
(
container
,
@"11
34
"
);
}
}
-
(
void
)
testCancellationBeforeExecution
-
(
void
)
testCancellationBeforeExecution
...
@@ -176,10 +217,19 @@
...
@@ -176,10 +217,19 @@
-
(
BUYRequestOperation
*
)
operationFulfillingExpectation
:
(
XCTestExpectation
*
)
expectation
completion
:
(
dispatch_block_t
)
completion
-
(
BUYRequestOperation
*
)
operationFulfillingExpectation
:
(
XCTestExpectation
*
)
expectation
completion
:
(
dispatch_block_t
)
completion
{
{
return
[
self
operationFulfillingExpectation
:
expectation
responseCompletion
:
^
(
NSDictionary
*
json
,
NSURLResponse
*
response
,
NSError
*
error
)
{
if
(
completion
)
{
completion
();
}
}];
}
-
(
BUYRequestOperation
*
)
operationFulfillingExpectation
:
(
XCTestExpectation
*
)
expectation
responseCompletion
:
(
void
(
^
)(
NSDictionary
*
json
,
NSHTTPURLResponse
*
response
,
NSError
*
error
))
completion
{
BUYRequestOperation
*
operation
=
[
BUYRequestOperation
operationWithSession
:
self
.
session
request
:
self
.
request
payload
:
nil
completion
:^
(
NSDictionary
*
json
,
NSURLResponse
*
response
,
NSError
*
error
)
{
BUYRequestOperation
*
operation
=
[
BUYRequestOperation
operationWithSession
:
self
.
session
request
:
self
.
request
payload
:
nil
completion
:^
(
NSDictionary
*
json
,
NSURLResponse
*
response
,
NSError
*
error
)
{
[
self
asyncMain
:
^
{
[
self
asyncMain
:
^
{
if
(
completion
)
{
if
(
completion
)
{
completion
();
completion
(
json
,
(
id
)
response
,
error
);
}
}
[
expectation
fulfill
];
[
expectation
fulfill
];
}];
}];
...
...
This diff is collapsed.
Click to expand it.
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