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
dc2579cb
Commit
dc2579cb
authored
May 31, 2016
by
Dima Bart
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor stubbing to be less verbose for keyed responses.
parent
d89492b9
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
99 additions
and
319 deletions
+99
-319
BUYClientTest_Customer.m
Mobile Buy SDK/Mobile Buy SDK Tests/BUYClientTest_Customer.m
+7
-35
BUYClientTest_Storefront.m
...e Buy SDK/Mobile Buy SDK Tests/BUYClientTest_Storefront.m
+10
-50
BUYIntegrationTest.m
Mobile Buy SDK/Mobile Buy SDK Tests/BUYIntegrationTest.m
+45
-225
OHHTTPStubsResponse+Helpers.h
...uy SDK/Mobile Buy SDK Tests/OHHTTPStubsResponse+Helpers.h
+8
-1
OHHTTPStubsResponse+Helpers.m
...uy SDK/Mobile Buy SDK Tests/OHHTTPStubsResponse+Helpers.m
+29
-8
No files found.
Mobile Buy SDK/Mobile Buy SDK Tests/BUYClientTest_Customer.m
View file @
dc2579cb
...
@@ -52,11 +52,7 @@
...
@@ -52,11 +52,7 @@
-
(
void
)
testCustomerDuplicateEmail
-
(
void
)
testCustomerDuplicateEmail
{
{
[
OHHTTPStubs
stubRequestsPassingTest
:
^
BOOL
(
NSURLRequest
*
_Nonnull
request
)
{
[
OHHTTPStubs
stubUsingResponseWithKey
:
@"testCustomerDuplicateEmail"
useMocks
:[
self
shouldUseMocks
]];
return
[
self
shouldUseMocks
];
}
withStubResponse
:
^
OHHTTPStubsResponse
*
_Nonnull
(
NSURLRequest
*
_Nonnull
request
)
{
return
[
OHHTTPStubsResponse
responseWithKey
:
@"testCustomerDuplicateEmail"
];
}];
XCTestExpectation
*
expectation
=
[
self
expectationWithDescription
:
NSStringFromSelector
(
_cmd
)];
XCTestExpectation
*
expectation
=
[
self
expectationWithDescription
:
NSStringFromSelector
(
_cmd
)];
[
self
.
client
createCustomerWithCredentials
:[
self
credentialsForCreation
]
callback
:
^
(
BUYCustomer
*
customer
,
NSString
*
token
,
NSError
*
error
)
{
[
self
.
client
createCustomerWithCredentials
:[
self
credentialsForCreation
]
callback
:
^
(
BUYCustomer
*
customer
,
NSString
*
token
,
NSError
*
error
)
{
...
@@ -83,11 +79,7 @@
...
@@ -83,11 +79,7 @@
-
(
void
)
testCustomerInvalidEmailPassword
-
(
void
)
testCustomerInvalidEmailPassword
{
{
[
OHHTTPStubs
stubRequestsPassingTest
:
^
BOOL
(
NSURLRequest
*
_Nonnull
request
)
{
[
OHHTTPStubs
stubUsingResponseWithKey
:
@"testCustomerInvalidEmailPassword"
useMocks
:[
self
shouldUseMocks
]];
return
[
self
shouldUseMocks
];
}
withStubResponse
:
^
OHHTTPStubsResponse
*
_Nonnull
(
NSURLRequest
*
_Nonnull
request
)
{
return
[
OHHTTPStubsResponse
responseWithKey
:
@"testCustomerInvalidEmailPassword"
];
}];
XCTestExpectation
*
expectation
=
[
self
expectationWithDescription
:
NSStringFromSelector
(
_cmd
)];
XCTestExpectation
*
expectation
=
[
self
expectationWithDescription
:
NSStringFromSelector
(
_cmd
)];
[
self
.
client
createCustomerWithCredentials
:[
self
credentialsForFailure
]
callback
:
^
(
BUYCustomer
*
customer
,
NSString
*
token
,
NSError
*
error
)
{
[
self
.
client
createCustomerWithCredentials
:[
self
credentialsForFailure
]
callback
:
^
(
BUYCustomer
*
customer
,
NSString
*
token
,
NSError
*
error
)
{
...
@@ -121,11 +113,7 @@
...
@@ -121,11 +113,7 @@
-
(
void
)
testCustomerLogin
-
(
void
)
testCustomerLogin
{
{
[
OHHTTPStubs
stubRequestsPassingTest
:
^
BOOL
(
NSURLRequest
*
_Nonnull
request
)
{
[
OHHTTPStubs
stubUsingResponseWithKey
:
@"testCustomerLogin"
useMocks
:[
self
shouldUseMocks
]];
return
[
self
shouldUseMocks
];
}
withStubResponse
:
^
OHHTTPStubsResponse
*
_Nonnull
(
NSURLRequest
*
_Nonnull
request
)
{
return
[
OHHTTPStubsResponse
responseWithKey
:
@"testCustomerLogin"
];
}];
XCTestExpectation
*
expectation
=
[
self
expectationWithDescription
:
NSStringFromSelector
(
_cmd
)];
XCTestExpectation
*
expectation
=
[
self
expectationWithDescription
:
NSStringFromSelector
(
_cmd
)];
[
self
.
client
loginCustomerWithCredentials
:[
self
credentialsForLogin
]
callback
:
^
(
BUYCustomer
*
customer
,
NSString
*
token
,
NSError
*
error
)
{
[
self
.
client
loginCustomerWithCredentials
:[
self
credentialsForLogin
]
callback
:
^
(
BUYCustomer
*
customer
,
NSString
*
token
,
NSError
*
error
)
{
...
@@ -144,20 +132,12 @@
...
@@ -144,20 +132,12 @@
-
(
void
)
testCustomerLogout
-
(
void
)
testCustomerLogout
{
{
[
OHHTTPStubs
stubRequestsPassingTest
:
^
BOOL
(
NSURLRequest
*
_Nonnull
request
)
{
[
OHHTTPStubs
stubUsingResponseWithKey
:
@"testCustomerLogin"
useMocks
:[
self
shouldUseMocks
]];
return
[
self
shouldUseMocks
];
}
withStubResponse
:
^
OHHTTPStubsResponse
*
_Nonnull
(
NSURLRequest
*
_Nonnull
request
)
{
return
[
OHHTTPStubsResponse
responseWithKey
:
@"testCustomerLogin"
];
}];
XCTestExpectation
*
expectation
=
[
self
expectationWithDescription
:
NSStringFromSelector
(
_cmd
)];
XCTestExpectation
*
expectation
=
[
self
expectationWithDescription
:
NSStringFromSelector
(
_cmd
)];
[
self
.
client
loginCustomerWithCredentials
:[
self
credentialsForLogin
]
callback
:
^
(
BUYCustomer
*
customer
,
NSString
*
token
,
NSError
*
error
)
{
[
self
.
client
loginCustomerWithCredentials
:[
self
credentialsForLogin
]
callback
:
^
(
BUYCustomer
*
customer
,
NSString
*
token
,
NSError
*
error
)
{
[
OHHTTPStubs
stubRequestsPassingTest
:
^
BOOL
(
NSURLRequest
*
_Nonnull
request
)
{
[
OHHTTPStubs
stubUsingResponseWithKey
:
@"testCustomerLogout"
useMocks
:[
self
shouldUseMocks
]];
return
[
self
shouldUseMocks
];
}
withStubResponse
:
^
OHHTTPStubsResponse
*
_Nonnull
(
NSURLRequest
*
_Nonnull
request
)
{
return
[
OHHTTPStubsResponse
responseWithKey
:
@"testCustomerLogout"
];
}];
[
self
.
client
logoutCustomerID
:
customer
.
identifier
.
stringValue
callback
:
^
(
BUYStatus
status
,
NSError
*
_Nullable
error
)
{
[
self
.
client
logoutCustomerID
:
customer
.
identifier
.
stringValue
callback
:
^
(
BUYStatus
status
,
NSError
*
_Nullable
error
)
{
...
@@ -175,11 +155,7 @@
...
@@ -175,11 +155,7 @@
-
(
void
)
testCustomerUpdate
-
(
void
)
testCustomerUpdate
{
{
[
OHHTTPStubs
stubRequestsPassingTest
:
^
BOOL
(
NSURLRequest
*
_Nonnull
request
)
{
[
OHHTTPStubs
stubUsingResponseWithKey
:
@"testCustomerLogin"
useMocks
:[
self
shouldUseMocks
]];
return
[
self
shouldUseMocks
];
}
withStubResponse
:
^
OHHTTPStubsResponse
*
_Nonnull
(
NSURLRequest
*
_Nonnull
request
)
{
return
[
OHHTTPStubsResponse
responseWithKey
:
@"testCustomerLogin"
];
}];
XCTestExpectation
*
expectation
=
[
self
expectationWithDescription
:
NSStringFromSelector
(
_cmd
)];
XCTestExpectation
*
expectation
=
[
self
expectationWithDescription
:
NSStringFromSelector
(
_cmd
)];
...
@@ -188,11 +164,7 @@
...
@@ -188,11 +164,7 @@
[
self
.
client
loginCustomerWithCredentials
:[
self
credentialsForLogin
]
callback
:
^
(
BUYCustomer
*
_Nullable
customer
,
NSString
*
_Nullable
token
,
NSError
*
_Nullable
error
)
{
[
self
.
client
loginCustomerWithCredentials
:[
self
credentialsForLogin
]
callback
:
^
(
BUYCustomer
*
_Nullable
customer
,
NSString
*
_Nullable
token
,
NSError
*
_Nullable
error
)
{
[
OHHTTPStubs
stubRequestsPassingTest
:
^
BOOL
(
NSURLRequest
*
_Nonnull
request
)
{
[
OHHTTPStubs
stubUsingResponseWithKey
:
@"testCustomerLogin"
useMocks
:[
self
shouldUseMocks
]];
return
[
self
shouldUseMocks
];
}
withStubResponse
:
^
OHHTTPStubsResponse
*
_Nonnull
(
NSURLRequest
*
_Nonnull
request
)
{
return
[
OHHTTPStubsResponse
responseWithKey
:
@"testCustomerLogin"
];
}];
[
self
.
client
updateCustomerWithCredentials
:
credentials
customerID
:
customer
.
identifier
.
stringValue
callback
:^
(
BUYCustomer
*
customer
,
NSError
*
error
)
{
[
self
.
client
updateCustomerWithCredentials
:
credentials
customerID
:
customer
.
identifier
.
stringValue
callback
:^
(
BUYCustomer
*
customer
,
NSError
*
error
)
{
...
...
Mobile Buy SDK/Mobile Buy SDK Tests/BUYClientTest_Storefront.m
View file @
dc2579cb
...
@@ -65,11 +65,7 @@
...
@@ -65,11 +65,7 @@
-
(
void
)
testGetProductList
-
(
void
)
testGetProductList
{
{
[
OHHTTPStubs
stubRequestsPassingTest
:
^
BOOL
(
NSURLRequest
*
_Nonnull
request
)
{
[
OHHTTPStubs
stubUsingResponseWithKey
:
@"testGetProducts_0"
useMocks
:[
self
shouldUseMocks
]];
return
[
self
shouldUseMocks
];
}
withStubResponse
:
^
OHHTTPStubsResponse
*
_Nonnull
(
NSURLRequest
*
_Nonnull
request
)
{
return
[
OHHTTPStubsResponse
responseWithKey
:
@"testGetProducts_0"
];
}];
XCTestExpectation
*
expectation
=
[
self
expectationWithDescription
:
NSStringFromSelector
(
_cmd
)];
XCTestExpectation
*
expectation
=
[
self
expectationWithDescription
:
NSStringFromSelector
(
_cmd
)];
[
self
.
client
getProductsPage
:
0
completion
:
^
(
NSArray
*
products
,
NSUInteger
page
,
BOOL
reachedEnd
,
NSError
*
error
)
{
[
self
.
client
getProductsPage
:
0
completion
:
^
(
NSArray
*
products
,
NSUInteger
page
,
BOOL
reachedEnd
,
NSError
*
error
)
{
...
@@ -86,11 +82,7 @@
...
@@ -86,11 +82,7 @@
-
(
void
)
testGetShop
-
(
void
)
testGetShop
{
{
[
OHHTTPStubs
stubRequestsPassingTest
:
^
BOOL
(
NSURLRequest
*
_Nonnull
request
)
{
[
OHHTTPStubs
stubUsingResponseWithKey
:
@"testGetShop_0"
useMocks
:[
self
shouldUseMocks
]];
return
[
self
shouldUseMocks
];
}
withStubResponse
:
^
OHHTTPStubsResponse
*
_Nonnull
(
NSURLRequest
*
_Nonnull
request
)
{
return
[
OHHTTPStubsResponse
responseWithKey
:
@"testGetShop_0"
];
}];
XCTestExpectation
*
expectation
=
[
self
expectationWithDescription
:
NSStringFromSelector
(
_cmd
)];
XCTestExpectation
*
expectation
=
[
self
expectationWithDescription
:
NSStringFromSelector
(
_cmd
)];
[
self
.
client
getShop
:
^
(
BUYShop
*
shop
,
NSError
*
error
)
{
[
self
.
client
getShop
:
^
(
BUYShop
*
shop
,
NSError
*
error
)
{
...
@@ -107,11 +99,7 @@
...
@@ -107,11 +99,7 @@
-
(
void
)
testGetProductById
-
(
void
)
testGetProductById
{
{
[
OHHTTPStubs
stubRequestsPassingTest
:
^
BOOL
(
NSURLRequest
*
_Nonnull
request
)
{
[
OHHTTPStubs
stubUsingResponseWithKey
:
@"testGetProduct_0"
useMocks
:[
self
shouldUseMocks
]];
return
[
self
shouldUseMocks
];
}
withStubResponse
:
^
OHHTTPStubsResponse
*
_Nonnull
(
NSURLRequest
*
_Nonnull
request
)
{
return
[
OHHTTPStubsResponse
responseWithKey
:
@"testGetProduct_0"
];
}];
XCTestExpectation
*
expectation
=
[
self
expectationWithDescription
:
NSStringFromSelector
(
_cmd
)];
XCTestExpectation
*
expectation
=
[
self
expectationWithDescription
:
NSStringFromSelector
(
_cmd
)];
[
self
.
client
getProductById
:
self
.
productIds
[
0
]
completion
:
^
(
BUYProduct
*
product
,
NSError
*
error
)
{
[
self
.
client
getProductById
:
self
.
productIds
[
0
]
completion
:
^
(
BUYProduct
*
product
,
NSError
*
error
)
{
...
@@ -136,11 +124,7 @@
...
@@ -136,11 +124,7 @@
-
(
void
)
testGetMultipleProductByIds
-
(
void
)
testGetMultipleProductByIds
{
{
[
OHHTTPStubs
stubRequestsPassingTest
:
^
BOOL
(
NSURLRequest
*
_Nonnull
request
)
{
[
OHHTTPStubs
stubUsingResponseWithKey
:
@"testGetProducts_0"
useMocks
:[
self
shouldUseMocks
]];
return
[
self
shouldUseMocks
];
}
withStubResponse
:
^
OHHTTPStubsResponse
*
_Nonnull
(
NSURLRequest
*
_Nonnull
request
)
{
return
[
OHHTTPStubsResponse
responseWithKey
:
@"testGetProducts_0"
];
}];
XCTestExpectation
*
expectation
=
[
self
expectationWithDescription
:
NSStringFromSelector
(
_cmd
)];
XCTestExpectation
*
expectation
=
[
self
expectationWithDescription
:
NSStringFromSelector
(
_cmd
)];
...
@@ -171,11 +155,7 @@
...
@@ -171,11 +155,7 @@
-
(
void
)
testProductRequestError
-
(
void
)
testProductRequestError
{
{
[
OHHTTPStubs
stubRequestsPassingTest
:
^
BOOL
(
NSURLRequest
*
_Nonnull
request
)
{
[
OHHTTPStubs
stubUsingResponseWithKey
:
@"testGetNonexistentProduct_0"
useMocks
:[
self
shouldUseMocks
]];
return
[
self
shouldUseMocks
];
}
withStubResponse
:
^
OHHTTPStubsResponse
*
_Nonnull
(
NSURLRequest
*
_Nonnull
request
)
{
return
[
OHHTTPStubsResponse
responseWithKey
:
@"testGetNonexistentProduct_0"
];
}];
XCTestExpectation
*
expectation
=
[
self
expectationWithDescription
:
NSStringFromSelector
(
_cmd
)];
XCTestExpectation
*
expectation
=
[
self
expectationWithDescription
:
NSStringFromSelector
(
_cmd
)];
[
self
.
client
getProductById
:
@"asdfdsasdfdsasdfdsasdfjkllkj"
completion
:
^
(
BUYProduct
*
product
,
NSError
*
error
)
{
[
self
.
client
getProductById
:
@"asdfdsasdfdsasdfdsasdfjkllkj"
completion
:
^
(
BUYProduct
*
product
,
NSError
*
error
)
{
...
@@ -191,11 +171,7 @@
...
@@ -191,11 +171,7 @@
-
(
void
)
testCollections
-
(
void
)
testCollections
{
{
[
OHHTTPStubs
stubRequestsPassingTest
:
^
BOOL
(
NSURLRequest
*
_Nonnull
request
)
{
[
OHHTTPStubs
stubUsingResponseWithKey
:
@"testGetCollection_0"
useMocks
:[
self
shouldUseMocks
]];
return
[
self
shouldUseMocks
];
}
withStubResponse
:
^
OHHTTPStubsResponse
*
_Nonnull
(
NSURLRequest
*
_Nonnull
request
)
{
return
[
OHHTTPStubsResponse
responseWithKey
:
@"testGetCollection_0"
];
}];
XCTestExpectation
*
expectation
=
[
self
expectationWithDescription
:
NSStringFromSelector
(
_cmd
)];
XCTestExpectation
*
expectation
=
[
self
expectationWithDescription
:
NSStringFromSelector
(
_cmd
)];
[
self
.
client
getCollections
:
^
(
NSArray
*
collections
,
NSError
*
error
)
{
[
self
.
client
getCollections
:
^
(
NSArray
*
collections
,
NSError
*
error
)
{
...
@@ -217,11 +193,7 @@
...
@@ -217,11 +193,7 @@
-
(
void
)
testCollectionsFromFirstPage
-
(
void
)
testCollectionsFromFirstPage
{
{
[
OHHTTPStubs
stubRequestsPassingTest
:
^
BOOL
(
NSURLRequest
*
_Nonnull
request
)
{
[
OHHTTPStubs
stubUsingResponseWithKey
:
@"testGetCollection_0"
useMocks
:[
self
shouldUseMocks
]];
return
[
self
shouldUseMocks
];
}
withStubResponse
:
^
OHHTTPStubsResponse
*
_Nonnull
(
NSURLRequest
*
_Nonnull
request
)
{
return
[
OHHTTPStubsResponse
responseWithKey
:
@"testGetCollection_0"
];
}];
XCTestExpectation
*
expectation
=
[
self
expectationWithDescription
:
NSStringFromSelector
(
_cmd
)];
XCTestExpectation
*
expectation
=
[
self
expectationWithDescription
:
NSStringFromSelector
(
_cmd
)];
[
self
.
client
getCollectionsPage
:
1
completion
:
^
(
NSArray
<
BUYCollection
*>
*
collections
,
NSUInteger
page
,
BOOL
reachedEnd
,
NSError
*
error
)
{
[
self
.
client
getCollectionsPage
:
1
completion
:
^
(
NSArray
<
BUYCollection
*>
*
collections
,
NSUInteger
page
,
BOOL
reachedEnd
,
NSError
*
error
)
{
...
@@ -244,11 +216,7 @@
...
@@ -244,11 +216,7 @@
-
(
void
)
testCollectionsFromEmptyPage
-
(
void
)
testCollectionsFromEmptyPage
{
{
[
OHHTTPStubs
stubRequestsPassingTest
:
^
BOOL
(
NSURLRequest
*
_Nonnull
request
)
{
[
OHHTTPStubs
stubUsingResponseWithKey
:
@"testGetOutOfIndexCollectionPage_0"
useMocks
:[
self
shouldUseMocks
]];
return
[
self
shouldUseMocks
];
}
withStubResponse
:
^
OHHTTPStubsResponse
*
_Nonnull
(
NSURLRequest
*
_Nonnull
request
)
{
return
[
OHHTTPStubsResponse
responseWithKey
:
@"testGetOutOfIndexCollectionPage_0"
];
}];
XCTestExpectation
*
expectation
=
[
self
expectationWithDescription
:
NSStringFromSelector
(
_cmd
)];
XCTestExpectation
*
expectation
=
[
self
expectationWithDescription
:
NSStringFromSelector
(
_cmd
)];
[
self
.
client
getCollectionsPage
:
999
completion
:
^
(
NSArray
<
BUYCollection
*>
*
collections
,
NSUInteger
page
,
BOOL
reachedEnd
,
NSError
*
error
)
{
[
self
.
client
getCollectionsPage
:
999
completion
:
^
(
NSArray
<
BUYCollection
*>
*
collections
,
NSUInteger
page
,
BOOL
reachedEnd
,
NSError
*
error
)
{
...
@@ -274,11 +242,7 @@
...
@@ -274,11 +242,7 @@
XCTAssertNotNil
(
self
.
collection
);
XCTAssertNotNil
(
self
.
collection
);
[
OHHTTPStubs
stubRequestsPassingTest
:
^
BOOL
(
NSURLRequest
*
_Nonnull
request
)
{
[
OHHTTPStubs
stubUsingResponseWithKey
:
@"testGetProductsInCollection_0"
useMocks
:[
self
shouldUseMocks
]];
return
[
self
shouldUseMocks
];
}
withStubResponse
:
^
OHHTTPStubsResponse
*
_Nonnull
(
NSURLRequest
*
_Nonnull
request
)
{
return
[
OHHTTPStubsResponse
responseWithKey
:
@"testGetProductsInCollection_0"
];
}];
XCTestExpectation
*
expectation
=
[
self
expectationWithDescription
:
NSStringFromSelector
(
_cmd
)];
XCTestExpectation
*
expectation
=
[
self
expectationWithDescription
:
NSStringFromSelector
(
_cmd
)];
...
@@ -298,11 +262,7 @@
...
@@ -298,11 +262,7 @@
-
(
void
)
testValidTags
-
(
void
)
testValidTags
{
{
[
OHHTTPStubs
stubRequestsPassingTest
:
^
BOOL
(
NSURLRequest
*
_Nonnull
request
)
{
[
OHHTTPStubs
stubUsingResponseWithKey
:
@"testGetValidTag_0"
useMocks
:[
self
shouldUseMocks
]];
return
[
self
shouldUseMocks
];
}
withStubResponse
:
^
OHHTTPStubsResponse
*
_Nonnull
(
NSURLRequest
*
_Nonnull
request
)
{
return
[
OHHTTPStubsResponse
responseWithKey
:
@"testGetValidTag_0"
];
}];
XCTestExpectation
*
expectation
=
[
self
expectationWithDescription
:
NSStringFromSelector
(
_cmd
)];
XCTestExpectation
*
expectation
=
[
self
expectationWithDescription
:
NSStringFromSelector
(
_cmd
)];
...
...
Mobile Buy SDK/Mobile Buy SDK Tests/BUYIntegrationTest.m
View file @
dc2579cb
...
@@ -70,11 +70,7 @@
...
@@ -70,11 +70,7 @@
-
(
void
)
fetchProducts
-
(
void
)
fetchProducts
{
{
[
OHHTTPStubs
stubRequestsPassingTest
:
^
BOOL
(
NSURLRequest
*
_Nonnull
request
)
{
[
OHHTTPStubs
stubUsingResponseWithKey
:
@"testGetProductPage_0"
useMocks
:[
self
shouldUseMocks
]];
return
[
self
shouldUseMocks
];
}
withStubResponse
:
^
OHHTTPStubsResponse
*
_Nonnull
(
NSURLRequest
*
_Nonnull
request
)
{
return
[
OHHTTPStubsResponse
responseWithKey
:
@"testGetProductPage_0"
];
}];
XCTestExpectation
*
expectation
=
[
self
expectationWithDescription
:
NSStringFromSelector
(
_cmd
)];
XCTestExpectation
*
expectation
=
[
self
expectationWithDescription
:
NSStringFromSelector
(
_cmd
)];
...
@@ -103,11 +99,7 @@
...
@@ -103,11 +99,7 @@
-
(
void
)
createCheckout
-
(
void
)
createCheckout
{
{
[
OHHTTPStubs
stubRequestsPassingTest
:
^
BOOL
(
NSURLRequest
*
_Nonnull
request
)
{
[
OHHTTPStubs
stubUsingResponseWithKey
:
@"testCheckoutFlowUsingCreditCard_1"
useMocks
:[
self
shouldUseMocks
]];
return
[
self
shouldUseMocks
];
}
withStubResponse
:
^
OHHTTPStubsResponse
*
_Nonnull
(
NSURLRequest
*
_Nonnull
request
)
{
return
[
OHHTTPStubsResponse
responseWithKey
:
@"testCheckoutFlowUsingCreditCard_1"
];
}];
_checkout
=
[[
BUYCheckout
alloc
]
initWithCart
:
_cart
];
_checkout
=
[[
BUYCheckout
alloc
]
initWithCart
:
_cart
];
_checkout
.
shippingAddress
=
[
self
shippingAddress
];
_checkout
.
shippingAddress
=
[
self
shippingAddress
];
...
@@ -129,11 +121,7 @@
...
@@ -129,11 +121,7 @@
-
(
void
)
testCheckoutAttributesAndNotes
-
(
void
)
testCheckoutAttributesAndNotes
{
{
[
OHHTTPStubs
stubRequestsPassingTest
:
^
BOOL
(
NSURLRequest
*
_Nonnull
request
)
{
[
OHHTTPStubs
stubUsingResponseWithKey
:
@"testCheckoutFlowUsingCreditCard_1"
useMocks
:[
self
shouldUseMocks
]];
return
[
self
shouldUseMocks
];
}
withStubResponse
:
^
OHHTTPStubsResponse
*
_Nonnull
(
NSURLRequest
*
_Nonnull
request
)
{
return
[
OHHTTPStubsResponse
responseWithKey
:
@"testCheckoutFlowUsingCreditCard_1"
];
}];
[
self
createCart
];
[
self
createCart
];
_checkout
=
[[
BUYCheckout
alloc
]
initWithCart
:
_cart
];
_checkout
=
[[
BUYCheckout
alloc
]
initWithCart
:
_cart
];
...
@@ -163,11 +151,7 @@
...
@@ -163,11 +151,7 @@
-
(
void
)
fetchShippingRates
-
(
void
)
fetchShippingRates
{
{
[
OHHTTPStubs
stubRequestsPassingTest
:
^
BOOL
(
NSURLRequest
*
_Nonnull
request
)
{
[
OHHTTPStubs
stubUsingResponseWithKey
:
@"testCheckoutFlowUsingCreditCard_2"
useMocks
:[
self
shouldUseMocks
]];
return
[
self
shouldUseMocks
];
}
withStubResponse
:
^
OHHTTPStubsResponse
*
_Nonnull
(
NSURLRequest
*
_Nonnull
request
)
{
return
[
OHHTTPStubsResponse
responseWithKey
:
@"testCheckoutFlowUsingCreditCard_2"
];
}];
XCTestExpectation
*
expectation
=
[
self
expectationWithDescription
:
NSStringFromSelector
(
_cmd
)];
XCTestExpectation
*
expectation
=
[
self
expectationWithDescription
:
NSStringFromSelector
(
_cmd
)];
[
self
.
client
getShippingRatesForCheckout
:
_checkout
completion
:
^
(
NSArray
*
shippingRates
,
BUYStatus
status
,
NSError
*
error
)
{
[
self
.
client
getShippingRatesForCheckout
:
_checkout
completion
:
^
(
NSArray
*
shippingRates
,
BUYStatus
status
,
NSError
*
error
)
{
...
@@ -186,11 +170,7 @@
...
@@ -186,11 +170,7 @@
-
(
void
)
updateCheckout
-
(
void
)
updateCheckout
{
{
[
OHHTTPStubs
stubRequestsPassingTest
:
^
BOOL
(
NSURLRequest
*
_Nonnull
request
)
{
[
OHHTTPStubs
stubUsingResponseWithKey
:
@"testCheckoutFlowUsingCreditCard_3"
useMocks
:[
self
shouldUseMocks
]];
return
[
self
shouldUseMocks
];
}
withStubResponse
:
^
OHHTTPStubsResponse
*
_Nonnull
(
NSURLRequest
*
_Nonnull
request
)
{
return
[
OHHTTPStubsResponse
responseWithKey
:
@"testCheckoutFlowUsingCreditCard_3"
];
}];
_checkout
.
email
=
@"test@test.com"
;
_checkout
.
email
=
@"test@test.com"
;
_checkout
.
shippingRate
=
_shippingRates
[
0
];
_checkout
.
shippingRate
=
_shippingRates
[
0
];
XCTestExpectation
*
expectation
=
[
self
expectationWithDescription
:
NSStringFromSelector
(
_cmd
)];
XCTestExpectation
*
expectation
=
[
self
expectationWithDescription
:
NSStringFromSelector
(
_cmd
)];
...
@@ -210,11 +190,7 @@
...
@@ -210,11 +190,7 @@
-
(
id
<
BUYPaymentToken
>
)
addCreditCardToCheckout
-
(
id
<
BUYPaymentToken
>
)
addCreditCardToCheckout
{
{
[
OHHTTPStubs
stubRequestsPassingTest
:
^
BOOL
(
NSURLRequest
*
_Nonnull
request
)
{
[
OHHTTPStubs
stubUsingResponseWithKey
:
@"testCheckoutFlowUsingCreditCard_4"
useMocks
:[
self
shouldUseMocks
]];
return
[
self
shouldUseMocks
];
}
withStubResponse
:
^
OHHTTPStubsResponse
*
_Nonnull
(
NSURLRequest
*
_Nonnull
request
)
{
return
[
OHHTTPStubsResponse
responseWithKey
:
@"testCheckoutFlowUsingCreditCard_4"
];
}];
BUYCreditCard
*
creditCard
=
[
self
creditCard
];
BUYCreditCard
*
creditCard
=
[
self
creditCard
];
__block
id
<
BUYPaymentToken
>
token
=
nil
;
__block
id
<
BUYPaymentToken
>
token
=
nil
;
...
@@ -307,11 +283,7 @@
...
@@ -307,11 +283,7 @@
[
self
createCart
];
[
self
createCart
];
[
self
createCheckout
];
[
self
createCheckout
];
[
OHHTTPStubs
stubRequestsPassingTest
:
^
BOOL
(
NSURLRequest
*
_Nonnull
request
)
{
[
OHHTTPStubs
stubUsingResponseWithKey
:
@"testApplyingGiftCardToCheckout_2"
useMocks
:[
self
shouldUseMocks
]];
return
[
self
shouldUseMocks
];
}
withStubResponse
:
^
OHHTTPStubsResponse
*
_Nonnull
(
NSURLRequest
*
_Nonnull
request
)
{
return
[
OHHTTPStubsResponse
responseWithKey
:
@"testApplyingGiftCardToCheckout_2"
];
}];
[
self
applyGiftCardToCheckout
];
[
self
applyGiftCardToCheckout
];
}
}
...
@@ -356,11 +328,7 @@
...
@@ -356,11 +328,7 @@
XCTAssertGreaterThan
([
_checkout
.
paymentDue
integerValue
],
1
);
XCTAssertGreaterThan
([
_checkout
.
paymentDue
integerValue
],
1
);
NSDecimalNumber
*
originalPaymentDue
=
[
_checkout
.
paymentDue
copy
];
NSDecimalNumber
*
originalPaymentDue
=
[
_checkout
.
paymentDue
copy
];
[
OHHTTPStubs
stubRequestsPassingTest
:
^
BOOL
(
NSURLRequest
*
_Nonnull
request
)
{
[
OHHTTPStubs
stubUsingResponseWithKey
:
@"testApplyingInvalidGiftCardToCheckout_2"
useMocks
:[
self
shouldUseMocks
]];
return
[
self
shouldUseMocks
];
}
withStubResponse
:
^
OHHTTPStubsResponse
*
_Nonnull
(
NSURLRequest
*
_Nonnull
request
)
{
return
[
OHHTTPStubsResponse
responseWithKey
:
@"testApplyingInvalidGiftCardToCheckout_2"
];
}];
XCTestExpectation
*
expectation
=
[
self
expectationWithDescription
:
NSStringFromSelector
(
_cmd
)];
XCTestExpectation
*
expectation
=
[
self
expectationWithDescription
:
NSStringFromSelector
(
_cmd
)];
[
self
.
client
applyGiftCardWithCode
:
@"000"
toCheckout
:
_checkout
completion
:^
(
BUYCheckout
*
checkout
,
NSError
*
error
)
{
[
self
.
client
applyGiftCardWithCode
:
@"000"
toCheckout
:
_checkout
completion
:^
(
BUYCheckout
*
checkout
,
NSError
*
error
)
{
...
@@ -384,11 +352,7 @@
...
@@ -384,11 +352,7 @@
NSDecimalNumber
*
originalPaymentDue
=
[
_checkout
.
paymentDue
copy
];
NSDecimalNumber
*
originalPaymentDue
=
[
_checkout
.
paymentDue
copy
];
[
OHHTTPStubs
stubRequestsPassingTest
:
^
BOOL
(
NSURLRequest
*
_Nonnull
request
)
{
[
OHHTTPStubs
stubUsingResponseWithKey
:
@"testApplyingInvalidGiftCardToCheckout_2"
useMocks
:[
self
shouldUseMocks
]];
return
[
self
shouldUseMocks
];
}
withStubResponse
:
^
OHHTTPStubsResponse
*
_Nonnull
(
NSURLRequest
*
_Nonnull
request
)
{
return
[
OHHTTPStubsResponse
responseWithKey
:
@"testApplyingInvalidGiftCardToCheckout_2"
];
}];
XCTestExpectation
*
expectation
=
[
self
expectationWithDescription
:
NSStringFromSelector
(
_cmd
)];
XCTestExpectation
*
expectation
=
[
self
expectationWithDescription
:
NSStringFromSelector
(
_cmd
)];
[
self
.
client
applyGiftCardWithCode
:
self
.
giftCardCodeExpired
toCheckout
:
_checkout
completion
:^
(
BUYCheckout
*
checkout
,
NSError
*
error
)
{
[
self
.
client
applyGiftCardWithCode
:
self
.
giftCardCodeExpired
toCheckout
:
_checkout
completion
:^
(
BUYCheckout
*
checkout
,
NSError
*
error
)
{
...
@@ -410,11 +374,7 @@
...
@@ -410,11 +374,7 @@
[
self
createCart
];
[
self
createCart
];
[
self
createCheckout
];
[
self
createCheckout
];
[
OHHTTPStubs
stubRequestsPassingTest
:
^
BOOL
(
NSURLRequest
*
_Nonnull
request
)
{
[
OHHTTPStubs
stubUsingResponseWithKey
:
@"testRemovingGiftCardFromCheckout_2"
useMocks
:[
self
shouldUseMocks
]];
return
[
self
shouldUseMocks
];
}
withStubResponse
:
^
OHHTTPStubsResponse
*
_Nonnull
(
NSURLRequest
*
_Nonnull
request
)
{
return
[
OHHTTPStubsResponse
responseWithKey
:
@"testRemovingGiftCardFromCheckout_2"
];
}];
[
self
applyGiftCardToCheckout
];
[
self
applyGiftCardToCheckout
];
...
@@ -423,11 +383,7 @@
...
@@ -423,11 +383,7 @@
NSDecimalNumber
*
originalPaymentDue
=
[
_checkout
.
paymentDue
copy
];
NSDecimalNumber
*
originalPaymentDue
=
[
_checkout
.
paymentDue
copy
];
NSDecimalNumber
*
giftCardValue
=
[
giftCard
.
amountUsed
copy
];
NSDecimalNumber
*
giftCardValue
=
[
giftCard
.
amountUsed
copy
];
[
OHHTTPStubs
stubRequestsPassingTest
:
^
BOOL
(
NSURLRequest
*
_Nonnull
request
)
{
[
OHHTTPStubs
stubUsingResponseWithKey
:
@"testRemovingGiftCardFromCheckout_3"
useMocks
:[
self
shouldUseMocks
]];
return
[
self
shouldUseMocks
];
}
withStubResponse
:
^
OHHTTPStubsResponse
*
_Nonnull
(
NSURLRequest
*
_Nonnull
request
)
{
return
[
OHHTTPStubsResponse
responseWithKey
:
@"testRemovingGiftCardFromCheckout_3"
];
}];
XCTestExpectation
*
expectation
=
[
self
expectationWithDescription
:
NSStringFromSelector
(
_cmd
)];
XCTestExpectation
*
expectation
=
[
self
expectationWithDescription
:
NSStringFromSelector
(
_cmd
)];
[
self
.
client
removeGiftCard
:
giftCard
fromCheckout
:
_checkout
completion
:^
(
BUYCheckout
*
checkout
,
NSError
*
error
)
{
[
self
.
client
removeGiftCard
:
giftCard
fromCheckout
:
_checkout
completion
:^
(
BUYCheckout
*
checkout
,
NSError
*
error
)
{
...
@@ -452,11 +408,7 @@
...
@@ -452,11 +408,7 @@
NSDecimalNumber
*
originalPaymentDue
=
[
_checkout
.
paymentDue
copy
];
NSDecimalNumber
*
originalPaymentDue
=
[
_checkout
.
paymentDue
copy
];
[
OHHTTPStubs
stubRequestsPassingTest
:
^
BOOL
(
NSURLRequest
*
_Nonnull
request
)
{
[
OHHTTPStubs
stubUsingResponseWithKey
:
@"testRemovingInvalidGiftCardFromCheckout_2"
useMocks
:[
self
shouldUseMocks
]];
return
[
self
shouldUseMocks
];
}
withStubResponse
:
^
OHHTTPStubsResponse
*
_Nonnull
(
NSURLRequest
*
_Nonnull
request
)
{
return
[
OHHTTPStubsResponse
responseWithKey
:
@"testRemovingInvalidGiftCardFromCheckout_2"
];
}];
BUYGiftCard
*
giftCard
=
[[
BUYGiftCard
alloc
]
initWithModelManager
:
_modelManager
JSONDictionary
:@{
@"id"
:
@
(
000
)
}];
BUYGiftCard
*
giftCard
=
[[
BUYGiftCard
alloc
]
initWithModelManager
:
_modelManager
JSONDictionary
:@{
@"id"
:
@
(
000
)
}];
XCTestExpectation
*
expectation
=
[
self
expectationWithDescription
:
NSStringFromSelector
(
_cmd
)];
XCTestExpectation
*
expectation
=
[
self
expectationWithDescription
:
NSStringFromSelector
(
_cmd
)];
...
@@ -480,11 +432,7 @@
...
@@ -480,11 +432,7 @@
NSDecimalNumber
*
originalPaymentDue
=
[
_checkout
.
paymentDue
copy
];
NSDecimalNumber
*
originalPaymentDue
=
[
_checkout
.
paymentDue
copy
];
[
OHHTTPStubs
stubRequestsPassingTest
:
^
BOOL
(
NSURLRequest
*
_Nonnull
request
)
{
[
OHHTTPStubs
stubUsingResponseWithKey
:
@"testRemovingExpiredGiftCardFromCheckout_2"
useMocks
:[
self
shouldUseMocks
]];
return
[
self
shouldUseMocks
];
}
withStubResponse
:
^
OHHTTPStubsResponse
*
_Nonnull
(
NSURLRequest
*
_Nonnull
request
)
{
return
[
OHHTTPStubsResponse
responseWithKey
:
@"testRemovingExpiredGiftCardFromCheckout_2"
];
}];
BUYGiftCard
*
giftCard
=
[[
BUYGiftCard
alloc
]
initWithModelManager
:
_modelManager
JSONDictionary
:@{
@"id"
:
self
.
giftCardIdExpired
}];
BUYGiftCard
*
giftCard
=
[[
BUYGiftCard
alloc
]
initWithModelManager
:
_modelManager
JSONDictionary
:@{
@"id"
:
self
.
giftCardIdExpired
}];
XCTestExpectation
*
expectation
=
[
self
expectationWithDescription
:
NSStringFromSelector
(
_cmd
)];
XCTestExpectation
*
expectation
=
[
self
expectationWithDescription
:
NSStringFromSelector
(
_cmd
)];
...
@@ -507,21 +455,13 @@
...
@@ -507,21 +455,13 @@
[
self
createCart
];
[
self
createCart
];
[
self
createCheckout
];
[
self
createCheckout
];
[
OHHTTPStubs
stubRequestsPassingTest
:
^
BOOL
(
NSURLRequest
*
_Nonnull
request
)
{
[
OHHTTPStubs
stubUsingResponseWithKey
:
@"testApplyingTwoGiftCardsToCheckout_2"
useMocks
:[
self
shouldUseMocks
]];
return
[
self
shouldUseMocks
];
}
withStubResponse
:
^
OHHTTPStubsResponse
*
_Nonnull
(
NSURLRequest
*
_Nonnull
request
)
{
return
[
OHHTTPStubsResponse
responseWithKey
:
@"testApplyingTwoGiftCardsToCheckout_2"
];
}];
[
self
applyGiftCardToCheckout
];
[
self
applyGiftCardToCheckout
];
XCTAssertEqual
([
_checkout
.
giftCards
count
],
1
);
XCTAssertEqual
([
_checkout
.
giftCards
count
],
1
);
[
OHHTTPStubs
stubRequestsPassingTest
:
^
BOOL
(
NSURLRequest
*
_Nonnull
request
)
{
[
OHHTTPStubs
stubUsingResponseWithKey
:
@"testApplyingTwoGiftCardsToCheckout_3"
useMocks
:[
self
shouldUseMocks
]];
return
[
self
shouldUseMocks
];
}
withStubResponse
:
^
OHHTTPStubsResponse
*
_Nonnull
(
NSURLRequest
*
_Nonnull
request
)
{
return
[
OHHTTPStubsResponse
responseWithKey
:
@"testApplyingTwoGiftCardsToCheckout_3"
];
}];
[
self
applyGiftCardTwoToCheckout
];
[
self
applyGiftCardTwoToCheckout
];
}
}
...
@@ -555,31 +495,19 @@
...
@@ -555,31 +495,19 @@
[
self
createCart
];
[
self
createCart
];
[
self
createCheckout
];
[
self
createCheckout
];
[
OHHTTPStubs
stubRequestsPassingTest
:
^
BOOL
(
NSURLRequest
*
_Nonnull
request
)
{
[
OHHTTPStubs
stubUsingResponseWithKey
:
@"testApplyingThreeGiftCardsToCheckout_2"
useMocks
:[
self
shouldUseMocks
]];
return
[
self
shouldUseMocks
];
}
withStubResponse
:
^
OHHTTPStubsResponse
*
_Nonnull
(
NSURLRequest
*
_Nonnull
request
)
{
return
[
OHHTTPStubsResponse
responseWithKey
:
@"testApplyingThreeGiftCardsToCheckout_2"
];
}];
[
self
applyGiftCardToCheckout
];
[
self
applyGiftCardToCheckout
];
XCTAssertEqual
([
_checkout
.
giftCards
count
],
1
);
XCTAssertEqual
([
_checkout
.
giftCards
count
],
1
);
[
OHHTTPStubs
stubRequestsPassingTest
:
^
BOOL
(
NSURLRequest
*
_Nonnull
request
)
{
[
OHHTTPStubs
stubUsingResponseWithKey
:
@"testApplyingThreeGiftCardsToCheckout_3"
useMocks
:[
self
shouldUseMocks
]];
return
[
self
shouldUseMocks
];
}
withStubResponse
:
^
OHHTTPStubsResponse
*
_Nonnull
(
NSURLRequest
*
_Nonnull
request
)
{
return
[
OHHTTPStubsResponse
responseWithKey
:
@"testApplyingThreeGiftCardsToCheckout_3"
];
}];
[
self
applyGiftCardTwoToCheckout
];
[
self
applyGiftCardTwoToCheckout
];
XCTAssertEqual
([
_checkout
.
giftCards
count
],
2
);
XCTAssertEqual
([
_checkout
.
giftCards
count
],
2
);
[
OHHTTPStubs
stubRequestsPassingTest
:
^
BOOL
(
NSURLRequest
*
_Nonnull
request
)
{
[
OHHTTPStubs
stubUsingResponseWithKey
:
@"testApplyingThreeGiftCardsToCheckout_4"
useMocks
:[
self
shouldUseMocks
]];
return
[
self
shouldUseMocks
];
}
withStubResponse
:
^
OHHTTPStubsResponse
*
_Nonnull
(
NSURLRequest
*
_Nonnull
request
)
{
return
[
OHHTTPStubsResponse
responseWithKey
:
@"testApplyingThreeGiftCardsToCheckout_4"
];
}];
[
self
applyGiftCardThreeToCheckout
];
[
self
applyGiftCardThreeToCheckout
];
}
}
...
@@ -613,41 +541,25 @@
...
@@ -613,41 +541,25 @@
[
self
createCart
];
[
self
createCart
];
[
self
createCheckout
];
[
self
createCheckout
];
[
OHHTTPStubs
stubRequestsPassingTest
:
^
BOOL
(
NSURLRequest
*
_Nonnull
request
)
{
[
OHHTTPStubs
stubUsingResponseWithKey
:
@"testRemovingSecondGiftCard_2"
useMocks
:[
self
shouldUseMocks
]];
return
[
self
shouldUseMocks
];
}
withStubResponse
:
^
OHHTTPStubsResponse
*
_Nonnull
(
NSURLRequest
*
_Nonnull
request
)
{
return
[
OHHTTPStubsResponse
responseWithKey
:
@"testRemovingSecondGiftCard_2"
];
}];
[
self
applyGiftCardToCheckout
];
[
self
applyGiftCardToCheckout
];
XCTAssertEqual
([
_checkout
.
giftCards
count
],
1
);
XCTAssertEqual
([
_checkout
.
giftCards
count
],
1
);
[
OHHTTPStubs
stubRequestsPassingTest
:
^
BOOL
(
NSURLRequest
*
_Nonnull
request
)
{
[
OHHTTPStubs
stubUsingResponseWithKey
:
@"testRemovingSecondGiftCard_3"
useMocks
:[
self
shouldUseMocks
]];
return
[
self
shouldUseMocks
];
}
withStubResponse
:
^
OHHTTPStubsResponse
*
_Nonnull
(
NSURLRequest
*
_Nonnull
request
)
{
return
[
OHHTTPStubsResponse
responseWithKey
:
@"testRemovingSecondGiftCard_3"
];
}];
[
self
applyGiftCardTwoToCheckout
];
[
self
applyGiftCardTwoToCheckout
];
XCTAssertEqual
([
_checkout
.
giftCards
count
],
2
);
XCTAssertEqual
([
_checkout
.
giftCards
count
],
2
);
[
OHHTTPStubs
stubRequestsPassingTest
:
^
BOOL
(
NSURLRequest
*
_Nonnull
request
)
{
[
OHHTTPStubs
stubUsingResponseWithKey
:
@"testRemovingSecondGiftCard_4"
useMocks
:[
self
shouldUseMocks
]];
return
[
self
shouldUseMocks
];
}
withStubResponse
:
^
OHHTTPStubsResponse
*
_Nonnull
(
NSURLRequest
*
_Nonnull
request
)
{
return
[
OHHTTPStubsResponse
responseWithKey
:
@"testRemovingSecondGiftCard_4"
];
}];
[
self
applyGiftCardThreeToCheckout
];
[
self
applyGiftCardThreeToCheckout
];
XCTAssertEqual
([
_checkout
.
giftCards
count
],
3
);
XCTAssertEqual
([
_checkout
.
giftCards
count
],
3
);
[
OHHTTPStubs
stubRequestsPassingTest
:
^
BOOL
(
NSURLRequest
*
_Nonnull
request
)
{
[
OHHTTPStubs
stubUsingResponseWithKey
:
@"testRemovingSecondGiftCard_5"
useMocks
:[
self
shouldUseMocks
]];
return
[
self
shouldUseMocks
];
}
withStubResponse
:
^
OHHTTPStubsResponse
*
_Nonnull
(
NSURLRequest
*
_Nonnull
request
)
{
return
[
OHHTTPStubsResponse
responseWithKey
:
@"testRemovingSecondGiftCard_5"
];
}];
[
self
removeSecondGiftCard
];
[
self
removeSecondGiftCard
];
}
}
...
@@ -681,51 +593,31 @@
...
@@ -681,51 +593,31 @@
[
self
createCart
];
[
self
createCart
];
[
self
createCheckout
];
[
self
createCheckout
];
[
OHHTTPStubs
stubRequestsPassingTest
:
^
BOOL
(
NSURLRequest
*
_Nonnull
request
)
{
[
OHHTTPStubs
stubUsingResponseWithKey
:
@"testRemovingFirstGiftCard_2"
useMocks
:[
self
shouldUseMocks
]];
return
[
self
shouldUseMocks
];
}
withStubResponse
:
^
OHHTTPStubsResponse
*
_Nonnull
(
NSURLRequest
*
_Nonnull
request
)
{
return
[
OHHTTPStubsResponse
responseWithKey
:
@"testRemovingFirstGiftCard_2"
];
}];
[
self
applyGiftCardToCheckout
];
[
self
applyGiftCardToCheckout
];
XCTAssertEqual
([
_checkout
.
giftCards
count
],
1
);
XCTAssertEqual
([
_checkout
.
giftCards
count
],
1
);
[
OHHTTPStubs
stubRequestsPassingTest
:
^
BOOL
(
NSURLRequest
*
_Nonnull
request
)
{
[
OHHTTPStubs
stubUsingResponseWithKey
:
@"testRemovingFirstGiftCard_3"
useMocks
:[
self
shouldUseMocks
]];
return
[
self
shouldUseMocks
];
}
withStubResponse
:
^
OHHTTPStubsResponse
*
_Nonnull
(
NSURLRequest
*
_Nonnull
request
)
{
return
[
OHHTTPStubsResponse
responseWithKey
:
@"testRemovingFirstGiftCard_3"
];
}];
[
self
applyGiftCardTwoToCheckout
];
[
self
applyGiftCardTwoToCheckout
];
XCTAssertEqual
([
_checkout
.
giftCards
count
],
2
);
XCTAssertEqual
([
_checkout
.
giftCards
count
],
2
);
[
OHHTTPStubs
stubRequestsPassingTest
:
^
BOOL
(
NSURLRequest
*
_Nonnull
request
)
{
[
OHHTTPStubs
stubUsingResponseWithKey
:
@"testRemovingFirstGiftCard_4"
useMocks
:[
self
shouldUseMocks
]];
return
[
self
shouldUseMocks
];
}
withStubResponse
:
^
OHHTTPStubsResponse
*
_Nonnull
(
NSURLRequest
*
_Nonnull
request
)
{
return
[
OHHTTPStubsResponse
responseWithKey
:
@"testRemovingFirstGiftCard_4"
];
}];
[
self
applyGiftCardThreeToCheckout
];
[
self
applyGiftCardThreeToCheckout
];
XCTAssertEqual
([
_checkout
.
giftCards
count
],
3
);
XCTAssertEqual
([
_checkout
.
giftCards
count
],
3
);
[
OHHTTPStubs
stubRequestsPassingTest
:
^
BOOL
(
NSURLRequest
*
_Nonnull
request
)
{
[
OHHTTPStubs
stubUsingResponseWithKey
:
@"testRemovingFirstGiftCard_5"
useMocks
:[
self
shouldUseMocks
]];
return
[
self
shouldUseMocks
];
}
withStubResponse
:
^
OHHTTPStubsResponse
*
_Nonnull
(
NSURLRequest
*
_Nonnull
request
)
{
return
[
OHHTTPStubsResponse
responseWithKey
:
@"testRemovingFirstGiftCard_5"
];
}];
[
self
removeSecondGiftCard
];
[
self
removeSecondGiftCard
];
XCTAssertEqual
([
_checkout
.
giftCards
count
],
2
);
XCTAssertEqual
([
_checkout
.
giftCards
count
],
2
);
[
OHHTTPStubs
stubRequestsPassingTest
:
^
BOOL
(
NSURLRequest
*
_Nonnull
request
)
{
[
OHHTTPStubs
stubUsingResponseWithKey
:
@"testRemovingFirstGiftCard_6"
useMocks
:[
self
shouldUseMocks
]];
return
[
self
shouldUseMocks
];
}
withStubResponse
:
^
OHHTTPStubsResponse
*
_Nonnull
(
NSURLRequest
*
_Nonnull
request
)
{
return
[
OHHTTPStubsResponse
responseWithKey
:
@"testRemovingFirstGiftCard_6"
];
}];
[
self
removeFirstGiftCard
];
[
self
removeFirstGiftCard
];
}
}
...
@@ -760,59 +652,35 @@
...
@@ -760,59 +652,35 @@
[
self
createCart
];
[
self
createCart
];
[
self
createCheckout
];
[
self
createCheckout
];
[
OHHTTPStubs
stubRequestsPassingTest
:
^
BOOL
(
NSURLRequest
*
_Nonnull
request
)
{
[
OHHTTPStubs
stubUsingResponseWithKey
:
@"testRemovingAllGiftCards_2"
useMocks
:[
self
shouldUseMocks
]];
return
[
self
shouldUseMocks
];
}
withStubResponse
:
^
OHHTTPStubsResponse
*
_Nonnull
(
NSURLRequest
*
_Nonnull
request
)
{
return
[
OHHTTPStubsResponse
responseWithKey
:
@"testRemovingAllGiftCards_2"
];
}];
[
self
applyGiftCardToCheckout
];
[
self
applyGiftCardToCheckout
];
XCTAssertEqual
([
_checkout
.
giftCards
count
],
1
);
XCTAssertEqual
([
_checkout
.
giftCards
count
],
1
);
[
OHHTTPStubs
stubRequestsPassingTest
:
^
BOOL
(
NSURLRequest
*
_Nonnull
request
)
{
[
OHHTTPStubs
stubUsingResponseWithKey
:
@"testRemovingAllGiftCards_3"
useMocks
:[
self
shouldUseMocks
]];
return
[
self
shouldUseMocks
];
}
withStubResponse
:
^
OHHTTPStubsResponse
*
_Nonnull
(
NSURLRequest
*
_Nonnull
request
)
{
return
[
OHHTTPStubsResponse
responseWithKey
:
@"testRemovingAllGiftCards_3"
];
}];
[
self
applyGiftCardTwoToCheckout
];
[
self
applyGiftCardTwoToCheckout
];
XCTAssertEqual
([
_checkout
.
giftCards
count
],
2
);
XCTAssertEqual
([
_checkout
.
giftCards
count
],
2
);
[
OHHTTPStubs
stubRequestsPassingTest
:
^
BOOL
(
NSURLRequest
*
_Nonnull
request
)
{
[
OHHTTPStubs
stubUsingResponseWithKey
:
@"testRemovingAllGiftCards_4"
useMocks
:[
self
shouldUseMocks
]];
return
[
self
shouldUseMocks
];
}
withStubResponse
:
^
OHHTTPStubsResponse
*
_Nonnull
(
NSURLRequest
*
_Nonnull
request
)
{
return
[
OHHTTPStubsResponse
responseWithKey
:
@"testRemovingAllGiftCards_4"
];
}];
[
self
applyGiftCardThreeToCheckout
];
[
self
applyGiftCardThreeToCheckout
];
XCTAssertEqual
([
_checkout
.
giftCards
count
],
3
);
XCTAssertEqual
([
_checkout
.
giftCards
count
],
3
);
[
OHHTTPStubs
stubRequestsPassingTest
:
^
BOOL
(
NSURLRequest
*
_Nonnull
request
)
{
[
OHHTTPStubs
stubUsingResponseWithKey
:
@"testRemovingAllGiftCards_5"
useMocks
:[
self
shouldUseMocks
]];
return
[
self
shouldUseMocks
];
}
withStubResponse
:
^
OHHTTPStubsResponse
*
_Nonnull
(
NSURLRequest
*
_Nonnull
request
)
{
return
[
OHHTTPStubsResponse
responseWithKey
:
@"testRemovingAllGiftCards_5"
];
}];
[
self
removeSecondGiftCard
];
[
self
removeSecondGiftCard
];
XCTAssertEqual
([
_checkout
.
giftCards
count
],
2
);
XCTAssertEqual
([
_checkout
.
giftCards
count
],
2
);
[
OHHTTPStubs
stubRequestsPassingTest
:
^
BOOL
(
NSURLRequest
*
_Nonnull
request
)
{
[
OHHTTPStubs
stubUsingResponseWithKey
:
@"testRemovingAllGiftCards_6"
useMocks
:[
self
shouldUseMocks
]];
return
[
self
shouldUseMocks
];
}
withStubResponse
:
^
OHHTTPStubsResponse
*
_Nonnull
(
NSURLRequest
*
_Nonnull
request
)
{
return
[
OHHTTPStubsResponse
responseWithKey
:
@"testRemovingAllGiftCards_6"
];
}];
[
self
removeFirstGiftCard
];
[
self
removeFirstGiftCard
];
[
OHHTTPStubs
stubRequestsPassingTest
:
^
BOOL
(
NSURLRequest
*
_Nonnull
request
)
{
[
OHHTTPStubs
stubUsingResponseWithKey
:
@"testRemovingAllGiftCards_7"
useMocks
:[
self
shouldUseMocks
]];
return
[
self
shouldUseMocks
];
}
withStubResponse
:
^
OHHTTPStubsResponse
*
_Nonnull
(
NSURLRequest
*
_Nonnull
request
)
{
return
[
OHHTTPStubsResponse
responseWithKey
:
@"testRemovingAllGiftCards_7"
];
}];
[
self
removeAllGiftCards
];
[
self
removeAllGiftCards
];
}
}
...
@@ -844,11 +712,7 @@
...
@@ -844,11 +712,7 @@
_checkout
=
[[
BUYCheckout
alloc
]
initWithCart
:
_cart
];
_checkout
=
[[
BUYCheckout
alloc
]
initWithCart
:
_cart
];
XCTestExpectation
*
expectation
=
[
self
expectationWithDescription
:
NSStringFromSelector
(
_cmd
)];
XCTestExpectation
*
expectation
=
[
self
expectationWithDescription
:
NSStringFromSelector
(
_cmd
)];
[
OHHTTPStubs
stubRequestsPassingTest
:
^
BOOL
(
NSURLRequest
*
_Nonnull
request
)
{
[
OHHTTPStubs
stubUsingResponseWithKey
:
@"testInvalidIntegrationBadShopUrl_0"
useMocks
:[
self
shouldUseMocks
]];
return
[
self
shouldUseMocks
];
}
withStubResponse
:
^
OHHTTPStubsResponse
*
_Nonnull
(
NSURLRequest
*
_Nonnull
request
)
{
return
[
OHHTTPStubsResponse
responseWithKey
:
@"testInvalidIntegrationBadShopUrl_0"
];
}];
self
.
client
=
[[
BUYClient
alloc
]
initWithShopDomain
:
@"asdfdsasdfdsasdfdsadsfowinfaoinfw.myshopify.com"
apiKey
:
self
.
apiKey
appId
:
@"88234"
];
self
.
client
=
[[
BUYClient
alloc
]
initWithShopDomain
:
@"asdfdsasdfdsasdfdsadsfowinfaoinfw.myshopify.com"
apiKey
:
self
.
apiKey
appId
:
@"88234"
];
[
self
.
client
createCheckout
:
_checkout
completion
:
^
(
BUYCheckout
*
checkout
,
NSError
*
error
)
{
[
self
.
client
createCheckout
:
_checkout
completion
:
^
(
BUYCheckout
*
checkout
,
NSError
*
error
)
{
...
@@ -866,11 +730,7 @@
...
@@ -866,11 +730,7 @@
-
(
void
)
testFetchingShippingRatesWithoutShippingAddressShouldReturnPreconditionFailed
-
(
void
)
testFetchingShippingRatesWithoutShippingAddressShouldReturnPreconditionFailed
{
{
[
OHHTTPStubs
stubRequestsPassingTest
:
^
BOOL
(
NSURLRequest
*
_Nonnull
request
)
{
[
OHHTTPStubs
stubUsingResponseWithKey
:
@"testFetchingShippingRatesWithoutShippingAddress_1"
useMocks
:[
self
shouldUseMocks
]];
return
[
self
shouldUseMocks
];
}
withStubResponse
:
^
OHHTTPStubsResponse
*
_Nonnull
(
NSURLRequest
*
_Nonnull
request
)
{
return
[
OHHTTPStubsResponse
responseWithKey
:
@"testFetchingShippingRatesWithoutShippingAddress_1"
];
}];
[
self
createCart
];
[
self
createCart
];
_checkout
=
[[
BUYCheckout
alloc
]
initWithCart
:
_cart
];
_checkout
=
[[
BUYCheckout
alloc
]
initWithCart
:
_cart
];
...
@@ -888,11 +748,7 @@
...
@@ -888,11 +748,7 @@
XCTAssertNil
(
error
);
XCTAssertNil
(
error
);
}];
}];
[
OHHTTPStubs
stubRequestsPassingTest
:
^
BOOL
(
NSURLRequest
*
_Nonnull
request
)
{
[
OHHTTPStubs
stubUsingResponseWithKey
:
@"testFetchingShippingRatesWithoutShippingAddress_2"
useMocks
:[
self
shouldUseMocks
]];
return
[
self
shouldUseMocks
];
}
withStubResponse
:
^
OHHTTPStubsResponse
*
_Nonnull
(
NSURLRequest
*
_Nonnull
request
)
{
return
[
OHHTTPStubsResponse
responseWithKey
:
@"testFetchingShippingRatesWithoutShippingAddress_2"
];
}];
XCTestExpectation
*
expectation2
=
[
self
expectationWithDescription
:
NSStringFromSelector
(
_cmd
)];
XCTestExpectation
*
expectation2
=
[
self
expectationWithDescription
:
NSStringFromSelector
(
_cmd
)];
...
@@ -908,11 +764,7 @@
...
@@ -908,11 +764,7 @@
-
(
void
)
testFetchingShippingRatesForInvalidCheckoutShouldReturnNotFound
-
(
void
)
testFetchingShippingRatesForInvalidCheckoutShouldReturnNotFound
{
{
[
OHHTTPStubs
stubRequestsPassingTest
:
^
BOOL
(
NSURLRequest
*
_Nonnull
request
)
{
[
OHHTTPStubs
stubUsingResponseWithKey
:
@"testFetchingShippingRatesWithInvalidCheckout_1"
useMocks
:[
self
shouldUseMocks
]];
return
[
self
shouldUseMocks
];
}
withStubResponse
:
^
OHHTTPStubsResponse
*
_Nonnull
(
NSURLRequest
*
_Nonnull
request
)
{
return
[
OHHTTPStubsResponse
responseWithKey
:
@"testFetchingShippingRatesWithInvalidCheckout_1"
];
}];
BUYCheckout
*
checkout
=
[[
BUYCheckout
alloc
]
initWithCart
:
nil
];
BUYCheckout
*
checkout
=
[[
BUYCheckout
alloc
]
initWithCart
:
nil
];
checkout
.
token
=
@"bananaaaa"
;
checkout
.
token
=
@"bananaaaa"
;
...
@@ -947,11 +799,7 @@
...
@@ -947,11 +799,7 @@
_checkout
.
partialAddressesValue
=
YES
;
_checkout
.
partialAddressesValue
=
YES
;
}
}
[
OHHTTPStubs
stubRequestsPassingTest
:
^
BOOL
(
NSURLRequest
*
_Nonnull
request
)
{
[
OHHTTPStubs
stubUsingResponseWithKey
:
@"testCheckoutWithAPartialAddress"
useMocks
:[
self
shouldUseMocks
]];
return
[
self
shouldUseMocks
];
}
withStubResponse
:
^
OHHTTPStubsResponse
*
_Nonnull
(
NSURLRequest
*
_Nonnull
request
)
{
return
[
OHHTTPStubsResponse
responseWithKey
:
@"testCheckoutWithAPartialAddress"
];
}];
//Create the checkout
//Create the checkout
XCTestExpectation
*
expectation
=
[
self
expectationWithDescription
:
NSStringFromSelector
(
_cmd
)];
XCTestExpectation
*
expectation
=
[
self
expectationWithDescription
:
NSStringFromSelector
(
_cmd
)];
...
@@ -986,11 +834,7 @@
...
@@ -986,11 +834,7 @@
{
{
[
self
createCart
];
[
self
createCart
];
[
OHHTTPStubs
stubRequestsPassingTest
:
^
BOOL
(
NSURLRequest
*
_Nonnull
request
)
{
[
OHHTTPStubs
stubUsingResponseWithKey
:
@"testCreateCheckoutWithValidDiscount_1"
useMocks
:[
self
shouldUseMocks
]];
return
[
self
shouldUseMocks
];
}
withStubResponse
:
^
OHHTTPStubsResponse
*
_Nonnull
(
NSURLRequest
*
_Nonnull
request
)
{
return
[
OHHTTPStubsResponse
responseWithKey
:
@"testCreateCheckoutWithValidDiscount_1"
];
}];
_checkout
=
[[
BUYCheckout
alloc
]
initWithCart
:
_cart
];
_checkout
=
[[
BUYCheckout
alloc
]
initWithCart
:
_cart
];
_checkout
.
discount
=
[
self
applicableDiscount
];
_checkout
.
discount
=
[
self
applicableDiscount
];
...
@@ -1019,11 +863,7 @@
...
@@ -1019,11 +863,7 @@
{
{
[
self
createCart
];
[
self
createCart
];
[
OHHTTPStubs
stubRequestsPassingTest
:
^
BOOL
(
NSURLRequest
*
_Nonnull
request
)
{
[
OHHTTPStubs
stubUsingResponseWithKey
:
@"testCreateCheckoutWithExpiredDiscount_1"
useMocks
:[
self
shouldUseMocks
]];
return
[
self
shouldUseMocks
];
}
withStubResponse
:
^
OHHTTPStubsResponse
*
_Nonnull
(
NSURLRequest
*
_Nonnull
request
)
{
return
[
OHHTTPStubsResponse
responseWithKey
:
@"testCreateCheckoutWithExpiredDiscount_1"
];
}];
_checkout
=
[[
BUYCheckout
alloc
]
initWithCart
:
_cart
];
_checkout
=
[[
BUYCheckout
alloc
]
initWithCart
:
_cart
];
_checkout
.
discount
=
[
self
inapplicableDiscount
];
_checkout
.
discount
=
[
self
inapplicableDiscount
];
...
@@ -1045,11 +885,7 @@
...
@@ -1045,11 +885,7 @@
{
{
[
self
createCart
];
[
self
createCart
];
[
OHHTTPStubs
stubRequestsPassingTest
:
^
BOOL
(
NSURLRequest
*
_Nonnull
request
)
{
[
OHHTTPStubs
stubUsingResponseWithKey
:
@"testCreateCheckoutWithNonExistentDiscount_1"
useMocks
:[
self
shouldUseMocks
]];
return
[
self
shouldUseMocks
];
}
withStubResponse
:
^
OHHTTPStubsResponse
*
_Nonnull
(
NSURLRequest
*
_Nonnull
request
)
{
return
[
OHHTTPStubsResponse
responseWithKey
:
@"testCreateCheckoutWithNonExistentDiscount_1"
];
}];
_checkout
=
[[
BUYCheckout
alloc
]
initWithCart
:
_cart
];
_checkout
=
[[
BUYCheckout
alloc
]
initWithCart
:
_cart
];
_checkout
.
discount
=
[
self
nonExistentDiscount
];
_checkout
.
discount
=
[
self
nonExistentDiscount
];
...
@@ -1073,11 +909,7 @@
...
@@ -1073,11 +909,7 @@
[
self
createCart
];
[
self
createCart
];
[
self
createCheckout
];
[
self
createCheckout
];
[
OHHTTPStubs
stubRequestsPassingTest
:
^
BOOL
(
NSURLRequest
*
_Nonnull
request
)
{
[
OHHTTPStubs
stubUsingResponseWithKey
:
@"testCreateCheckoutWithValidDiscount_1"
useMocks
:[
self
shouldUseMocks
]];
return
[
self
shouldUseMocks
];
}
withStubResponse
:
^
OHHTTPStubsResponse
*
_Nonnull
(
NSURLRequest
*
_Nonnull
request
)
{
return
[
OHHTTPStubsResponse
responseWithKey
:
@"testCreateCheckoutWithValidDiscount_1"
];
}];
_checkout
.
discount
=
[
self
applicableDiscount
];
_checkout
.
discount
=
[
self
applicableDiscount
];
...
@@ -1098,11 +930,7 @@
...
@@ -1098,11 +930,7 @@
-
(
void
)
testGetCheckoutWithInvalidToken
-
(
void
)
testGetCheckoutWithInvalidToken
{
{
[
OHHTTPStubs
stubRequestsPassingTest
:
^
BOOL
(
NSURLRequest
*
_Nonnull
request
)
{
[
OHHTTPStubs
stubUsingResponseWithKey
:
@"testGetCheckoutWithInvalidToken_0"
useMocks
:[
self
shouldUseMocks
]];
return
[
self
shouldUseMocks
];
}
withStubResponse
:
^
OHHTTPStubsResponse
*
_Nonnull
(
NSURLRequest
*
_Nonnull
request
)
{
return
[
OHHTTPStubsResponse
responseWithKey
:
@"testGetCheckoutWithInvalidToken_0"
];
}];
XCTestExpectation
*
expectation
=
[
self
expectationWithDescription
:
NSStringFromSelector
(
_cmd
)];
XCTestExpectation
*
expectation
=
[
self
expectationWithDescription
:
NSStringFromSelector
(
_cmd
)];
...
@@ -1193,11 +1021,7 @@
...
@@ -1193,11 +1021,7 @@
XCTAssertTrue
([
_checkout
.
reservationTime
isKindOfClass
:[
NSNumber
class
]]);
XCTAssertTrue
([
_checkout
.
reservationTime
isKindOfClass
:[
NSNumber
class
]]);
XCTAssertEqual
(
300
,
_checkout
.
reservationTime
.
intValue
);
XCTAssertEqual
(
300
,
_checkout
.
reservationTime
.
intValue
);
[
OHHTTPStubs
stubRequestsPassingTest
:
^
BOOL
(
NSURLRequest
*
_Nonnull
request
)
{
[
OHHTTPStubs
stubUsingResponseWithKey
:
@"testExpiringCheckout_2"
useMocks
:[
self
shouldUseMocks
]];
return
[
self
shouldUseMocks
];
}
withStubResponse
:
^
OHHTTPStubsResponse
*
_Nonnull
(
NSURLRequest
*
_Nonnull
request
)
{
return
[
OHHTTPStubsResponse
responseWithKey
:
@"testExpiringCheckout_2"
];
}];
// Expire the checkout
// Expire the checkout
XCTestExpectation
*
expectation2
=
[
self
expectationWithDescription
:
NSStringFromSelector
(
_cmd
)];
XCTestExpectation
*
expectation2
=
[
self
expectationWithDescription
:
NSStringFromSelector
(
_cmd
)];
...
@@ -1218,11 +1042,7 @@
...
@@ -1218,11 +1042,7 @@
-
(
void
)
testCallbackQueue
-
(
void
)
testCallbackQueue
{
{
[
OHHTTPStubs
stubRequestsPassingTest
:
^
BOOL
(
NSURLRequest
*
_Nonnull
request
)
{
[
OHHTTPStubs
stubUsingResponseWithKey
:
@"testGetShop_0"
useMocks
:[
self
shouldUseMocks
]];
return
[
self
shouldUseMocks
];
}
withStubResponse
:
^
OHHTTPStubsResponse
*
_Nonnull
(
NSURLRequest
*
_Nonnull
request
)
{
return
[
OHHTTPStubsResponse
responseWithKey
:
@"testGetShop_0"
];
}];
XCTestExpectation
*
expectation
=
[
self
expectationWithDescription
:
NSStringFromSelector
(
_cmd
)];
XCTestExpectation
*
expectation
=
[
self
expectationWithDescription
:
NSStringFromSelector
(
_cmd
)];
XCTestExpectation
*
expectation2
=
[
self
expectationWithDescription
:
NSStringFromSelector
(
_cmd
)];
XCTestExpectation
*
expectation2
=
[
self
expectationWithDescription
:
NSStringFromSelector
(
_cmd
)];
...
...
Mobile Buy SDK/Mobile Buy SDK Tests/OHHTTPStubsResponse+Helpers.h
View file @
dc2579cb
...
@@ -26,8 +26,15 @@
...
@@ -26,8 +26,15 @@
#import <OHHTTPStubs/OHHTTPStubs.h>
#import <OHHTTPStubs/OHHTTPStubs.h>
@interface
OHHTTPStubsResponse
(
Helpers
)
@interface
OHHTTPStubsResponse
(
Buy
)
+
(
instancetype
)
responseWithKey
:(
NSString
*
)
key
;
+
(
instancetype
)
responseWithKey
:(
NSString
*
)
key
;
@end
@end
@interface
OHHTTPStubs
(
Buy
)
+
(
void
)
stubUsingResponseWithKey
:(
NSString
*
)
key
;
+
(
void
)
stubUsingResponseWithKey
:(
NSString
*
)
key
useMocks
:(
BOOL
)
useMocks
;
@end
Mobile Buy SDK/Mobile Buy SDK Tests/OHHTTPStubsResponse+Helpers.m
View file @
dc2579cb
...
@@ -26,28 +26,49 @@
...
@@ -26,28 +26,49 @@
#import "OHHTTPStubsResponse+Helpers.h"
#import "OHHTTPStubsResponse+Helpers.h"
static
NSDictionary
*
JSONMock
;
@implementation
OHHTTPStubsResponse
(
Buy
)
@implementation
OHHTTPStubsResponse
(
Helpers
)
+
(
NSDictionary
*
)
mockResponses
+
(
instancetype
)
responseWithKey
:(
NSString
*
)
key
{
{
static
NSDictionary
*
dictionary
=
nil
;
static
dispatch_once_t
onceToken
;
static
dispatch_once_t
onceToken
;
dispatch_once
(
&
onceToken
,
^
{
dispatch_once
(
&
onceToken
,
^
{
NSBundle
*
bundle
=
[
NSBundle
bundleForClass
:[
self
class
]];
NSBundle
*
bundle
=
[
NSBundle
bundleForClass
:[
self
class
]];
NSString
*
jsonPath
=
[
bundle
pathForResource
:
@"mocked_responses"
ofType
:
@"json"
];
NSString
*
jsonPath
=
[
bundle
pathForResource
:
@"mocked_responses"
ofType
:
@"json"
];
NSData
*
jsonData
=
[
NSData
dataWithContentsOfFile
:
jsonPath
];
NSData
*
jsonData
=
[
NSData
dataWithContentsOfFile
:
jsonPath
];
JSONMock
=
[
NSJSONSerialization
JSONObjectWithData
:
jsonData
options
:
0
error
:
nil
];
dictionary
=
[
NSJSONSerialization
JSONObjectWithData
:
jsonData
options
:
0
error
:
nil
];
});
});
return
dictionary
;
}
+
(
instancetype
)
responseWithKey
:
(
NSString
*
)
key
NSDictionary
*
json
=
JSONMock
[
key
];
{
NSDictionary
*
mocks
=
[
self
mockResponses
];
NSDictionary
*
json
=
mocks
[
key
];
NSData
*
data
=
[
json
[
@"body"
]
dataUsingEncoding
:
NSUTF8StringEncoding
];
NSData
*
data
=
[
json
[
@"body"
]
dataUsingEncoding
:
NSUTF8StringEncoding
];
int
code
=
[
json
[
@"code"
]
intValue
];
int
code
=
[
json
[
@"code"
]
intValue
];
return
[
OHHTTPStubsResponse
responseWithData
:
data
statusCode
:
code
headers
:
nil
];
return
[
OHHTTPStubsResponse
responseWithData
:
data
statusCode
:
code
headers
:
nil
];
}
}
@end
@implementation
OHHTTPStubs
(
Buy
)
+
(
void
)
stubUsingResponseWithKey
:(
NSString
*
)
key
{
[
self
stubUsingResponseWithKey
:
key
useMocks
:
YES
];
}
+
(
void
)
stubUsingResponseWithKey
:(
NSString
*
)
key
useMocks
:(
BOOL
)
useMocks
{
if
(
useMocks
)
{
[
OHHTTPStubs
stubRequestsPassingTest
:
^
BOOL
(
NSURLRequest
*
_Nonnull
request
)
{
return
YES
;
}
withStubResponse
:
^
OHHTTPStubsResponse
*
_Nonnull
(
NSURLRequest
*
_Nonnull
request
)
{
return
[
OHHTTPStubsResponse
responseWithKey
:
key
];
}];
}
}
@end
@end
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