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
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
59 additions
and
99 deletions
+59
-99
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
+0
-0
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
+34
-13
No files found.
Mobile Buy SDK/Mobile Buy SDK Tests/BUYClientTest_Customer.m
View file @
dc2579cb
...
...
@@ -52,11 +52,7 @@
-
(
void
)
testCustomerDuplicateEmail
{
[
OHHTTPStubs
stubRequestsPassingTest
:
^
BOOL
(
NSURLRequest
*
_Nonnull
request
)
{
return
[
self
shouldUseMocks
];
}
withStubResponse
:
^
OHHTTPStubsResponse
*
_Nonnull
(
NSURLRequest
*
_Nonnull
request
)
{
return
[
OHHTTPStubsResponse
responseWithKey
:
@"testCustomerDuplicateEmail"
];
}];
[
OHHTTPStubs
stubUsingResponseWithKey
:
@"testCustomerDuplicateEmail"
useMocks
:[
self
shouldUseMocks
]];
XCTestExpectation
*
expectation
=
[
self
expectationWithDescription
:
NSStringFromSelector
(
_cmd
)];
[
self
.
client
createCustomerWithCredentials
:[
self
credentialsForCreation
]
callback
:
^
(
BUYCustomer
*
customer
,
NSString
*
token
,
NSError
*
error
)
{
...
...
@@ -83,11 +79,7 @@
-
(
void
)
testCustomerInvalidEmailPassword
{
[
OHHTTPStubs
stubRequestsPassingTest
:
^
BOOL
(
NSURLRequest
*
_Nonnull
request
)
{
return
[
self
shouldUseMocks
];
}
withStubResponse
:
^
OHHTTPStubsResponse
*
_Nonnull
(
NSURLRequest
*
_Nonnull
request
)
{
return
[
OHHTTPStubsResponse
responseWithKey
:
@"testCustomerInvalidEmailPassword"
];
}];
[
OHHTTPStubs
stubUsingResponseWithKey
:
@"testCustomerInvalidEmailPassword"
useMocks
:[
self
shouldUseMocks
]];
XCTestExpectation
*
expectation
=
[
self
expectationWithDescription
:
NSStringFromSelector
(
_cmd
)];
[
self
.
client
createCustomerWithCredentials
:[
self
credentialsForFailure
]
callback
:
^
(
BUYCustomer
*
customer
,
NSString
*
token
,
NSError
*
error
)
{
...
...
@@ -121,11 +113,7 @@
-
(
void
)
testCustomerLogin
{
[
OHHTTPStubs
stubRequestsPassingTest
:
^
BOOL
(
NSURLRequest
*
_Nonnull
request
)
{
return
[
self
shouldUseMocks
];
}
withStubResponse
:
^
OHHTTPStubsResponse
*
_Nonnull
(
NSURLRequest
*
_Nonnull
request
)
{
return
[
OHHTTPStubsResponse
responseWithKey
:
@"testCustomerLogin"
];
}];
[
OHHTTPStubs
stubUsingResponseWithKey
:
@"testCustomerLogin"
useMocks
:[
self
shouldUseMocks
]];
XCTestExpectation
*
expectation
=
[
self
expectationWithDescription
:
NSStringFromSelector
(
_cmd
)];
[
self
.
client
loginCustomerWithCredentials
:[
self
credentialsForLogin
]
callback
:
^
(
BUYCustomer
*
customer
,
NSString
*
token
,
NSError
*
error
)
{
...
...
@@ -144,20 +132,12 @@
-
(
void
)
testCustomerLogout
{
[
OHHTTPStubs
stubRequestsPassingTest
:
^
BOOL
(
NSURLRequest
*
_Nonnull
request
)
{
return
[
self
shouldUseMocks
];
}
withStubResponse
:
^
OHHTTPStubsResponse
*
_Nonnull
(
NSURLRequest
*
_Nonnull
request
)
{
return
[
OHHTTPStubsResponse
responseWithKey
:
@"testCustomerLogin"
];
}];
[
OHHTTPStubs
stubUsingResponseWithKey
:
@"testCustomerLogin"
useMocks
:[
self
shouldUseMocks
]];
XCTestExpectation
*
expectation
=
[
self
expectationWithDescription
:
NSStringFromSelector
(
_cmd
)];
[
self
.
client
loginCustomerWithCredentials
:[
self
credentialsForLogin
]
callback
:
^
(
BUYCustomer
*
customer
,
NSString
*
token
,
NSError
*
error
)
{
[
OHHTTPStubs
stubRequestsPassingTest
:
^
BOOL
(
NSURLRequest
*
_Nonnull
request
)
{
return
[
self
shouldUseMocks
];
}
withStubResponse
:
^
OHHTTPStubsResponse
*
_Nonnull
(
NSURLRequest
*
_Nonnull
request
)
{
return
[
OHHTTPStubsResponse
responseWithKey
:
@"testCustomerLogout"
];
}];
[
OHHTTPStubs
stubUsingResponseWithKey
:
@"testCustomerLogout"
useMocks
:[
self
shouldUseMocks
]];
[
self
.
client
logoutCustomerID
:
customer
.
identifier
.
stringValue
callback
:
^
(
BUYStatus
status
,
NSError
*
_Nullable
error
)
{
...
...
@@ -175,11 +155,7 @@
-
(
void
)
testCustomerUpdate
{
[
OHHTTPStubs
stubRequestsPassingTest
:
^
BOOL
(
NSURLRequest
*
_Nonnull
request
)
{
return
[
self
shouldUseMocks
];
}
withStubResponse
:
^
OHHTTPStubsResponse
*
_Nonnull
(
NSURLRequest
*
_Nonnull
request
)
{
return
[
OHHTTPStubsResponse
responseWithKey
:
@"testCustomerLogin"
];
}];
[
OHHTTPStubs
stubUsingResponseWithKey
:
@"testCustomerLogin"
useMocks
:[
self
shouldUseMocks
]];
XCTestExpectation
*
expectation
=
[
self
expectationWithDescription
:
NSStringFromSelector
(
_cmd
)];
...
...
@@ -188,11 +164,7 @@
[
self
.
client
loginCustomerWithCredentials
:[
self
credentialsForLogin
]
callback
:
^
(
BUYCustomer
*
_Nullable
customer
,
NSString
*
_Nullable
token
,
NSError
*
_Nullable
error
)
{
[
OHHTTPStubs
stubRequestsPassingTest
:
^
BOOL
(
NSURLRequest
*
_Nonnull
request
)
{
return
[
self
shouldUseMocks
];
}
withStubResponse
:
^
OHHTTPStubsResponse
*
_Nonnull
(
NSURLRequest
*
_Nonnull
request
)
{
return
[
OHHTTPStubsResponse
responseWithKey
:
@"testCustomerLogin"
];
}];
[
OHHTTPStubs
stubUsingResponseWithKey
:
@"testCustomerLogin"
useMocks
:[
self
shouldUseMocks
]];
[
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 @@
-
(
void
)
testGetProductList
{
[
OHHTTPStubs
stubRequestsPassingTest
:
^
BOOL
(
NSURLRequest
*
_Nonnull
request
)
{
return
[
self
shouldUseMocks
];
}
withStubResponse
:
^
OHHTTPStubsResponse
*
_Nonnull
(
NSURLRequest
*
_Nonnull
request
)
{
return
[
OHHTTPStubsResponse
responseWithKey
:
@"testGetProducts_0"
];
}];
[
OHHTTPStubs
stubUsingResponseWithKey
:
@"testGetProducts_0"
useMocks
:[
self
shouldUseMocks
]];
XCTestExpectation
*
expectation
=
[
self
expectationWithDescription
:
NSStringFromSelector
(
_cmd
)];
[
self
.
client
getProductsPage
:
0
completion
:
^
(
NSArray
*
products
,
NSUInteger
page
,
BOOL
reachedEnd
,
NSError
*
error
)
{
...
...
@@ -86,11 +82,7 @@
-
(
void
)
testGetShop
{
[
OHHTTPStubs
stubRequestsPassingTest
:
^
BOOL
(
NSURLRequest
*
_Nonnull
request
)
{
return
[
self
shouldUseMocks
];
}
withStubResponse
:
^
OHHTTPStubsResponse
*
_Nonnull
(
NSURLRequest
*
_Nonnull
request
)
{
return
[
OHHTTPStubsResponse
responseWithKey
:
@"testGetShop_0"
];
}];
[
OHHTTPStubs
stubUsingResponseWithKey
:
@"testGetShop_0"
useMocks
:[
self
shouldUseMocks
]];
XCTestExpectation
*
expectation
=
[
self
expectationWithDescription
:
NSStringFromSelector
(
_cmd
)];
[
self
.
client
getShop
:
^
(
BUYShop
*
shop
,
NSError
*
error
)
{
...
...
@@ -107,11 +99,7 @@
-
(
void
)
testGetProductById
{
[
OHHTTPStubs
stubRequestsPassingTest
:
^
BOOL
(
NSURLRequest
*
_Nonnull
request
)
{
return
[
self
shouldUseMocks
];
}
withStubResponse
:
^
OHHTTPStubsResponse
*
_Nonnull
(
NSURLRequest
*
_Nonnull
request
)
{
return
[
OHHTTPStubsResponse
responseWithKey
:
@"testGetProduct_0"
];
}];
[
OHHTTPStubs
stubUsingResponseWithKey
:
@"testGetProduct_0"
useMocks
:[
self
shouldUseMocks
]];
XCTestExpectation
*
expectation
=
[
self
expectationWithDescription
:
NSStringFromSelector
(
_cmd
)];
[
self
.
client
getProductById
:
self
.
productIds
[
0
]
completion
:
^
(
BUYProduct
*
product
,
NSError
*
error
)
{
...
...
@@ -136,11 +124,7 @@
-
(
void
)
testGetMultipleProductByIds
{
[
OHHTTPStubs
stubRequestsPassingTest
:
^
BOOL
(
NSURLRequest
*
_Nonnull
request
)
{
return
[
self
shouldUseMocks
];
}
withStubResponse
:
^
OHHTTPStubsResponse
*
_Nonnull
(
NSURLRequest
*
_Nonnull
request
)
{
return
[
OHHTTPStubsResponse
responseWithKey
:
@"testGetProducts_0"
];
}];
[
OHHTTPStubs
stubUsingResponseWithKey
:
@"testGetProducts_0"
useMocks
:[
self
shouldUseMocks
]];
XCTestExpectation
*
expectation
=
[
self
expectationWithDescription
:
NSStringFromSelector
(
_cmd
)];
...
...
@@ -171,11 +155,7 @@
-
(
void
)
testProductRequestError
{
[
OHHTTPStubs
stubRequestsPassingTest
:
^
BOOL
(
NSURLRequest
*
_Nonnull
request
)
{
return
[
self
shouldUseMocks
];
}
withStubResponse
:
^
OHHTTPStubsResponse
*
_Nonnull
(
NSURLRequest
*
_Nonnull
request
)
{
return
[
OHHTTPStubsResponse
responseWithKey
:
@"testGetNonexistentProduct_0"
];
}];
[
OHHTTPStubs
stubUsingResponseWithKey
:
@"testGetNonexistentProduct_0"
useMocks
:[
self
shouldUseMocks
]];
XCTestExpectation
*
expectation
=
[
self
expectationWithDescription
:
NSStringFromSelector
(
_cmd
)];
[
self
.
client
getProductById
:
@"asdfdsasdfdsasdfdsasdfjkllkj"
completion
:
^
(
BUYProduct
*
product
,
NSError
*
error
)
{
...
...
@@ -191,11 +171,7 @@
-
(
void
)
testCollections
{
[
OHHTTPStubs
stubRequestsPassingTest
:
^
BOOL
(
NSURLRequest
*
_Nonnull
request
)
{
return
[
self
shouldUseMocks
];
}
withStubResponse
:
^
OHHTTPStubsResponse
*
_Nonnull
(
NSURLRequest
*
_Nonnull
request
)
{
return
[
OHHTTPStubsResponse
responseWithKey
:
@"testGetCollection_0"
];
}];
[
OHHTTPStubs
stubUsingResponseWithKey
:
@"testGetCollection_0"
useMocks
:[
self
shouldUseMocks
]];
XCTestExpectation
*
expectation
=
[
self
expectationWithDescription
:
NSStringFromSelector
(
_cmd
)];
[
self
.
client
getCollections
:
^
(
NSArray
*
collections
,
NSError
*
error
)
{
...
...
@@ -217,11 +193,7 @@
-
(
void
)
testCollectionsFromFirstPage
{
[
OHHTTPStubs
stubRequestsPassingTest
:
^
BOOL
(
NSURLRequest
*
_Nonnull
request
)
{
return
[
self
shouldUseMocks
];
}
withStubResponse
:
^
OHHTTPStubsResponse
*
_Nonnull
(
NSURLRequest
*
_Nonnull
request
)
{
return
[
OHHTTPStubsResponse
responseWithKey
:
@"testGetCollection_0"
];
}];
[
OHHTTPStubs
stubUsingResponseWithKey
:
@"testGetCollection_0"
useMocks
:[
self
shouldUseMocks
]];
XCTestExpectation
*
expectation
=
[
self
expectationWithDescription
:
NSStringFromSelector
(
_cmd
)];
[
self
.
client
getCollectionsPage
:
1
completion
:
^
(
NSArray
<
BUYCollection
*>
*
collections
,
NSUInteger
page
,
BOOL
reachedEnd
,
NSError
*
error
)
{
...
...
@@ -244,11 +216,7 @@
-
(
void
)
testCollectionsFromEmptyPage
{
[
OHHTTPStubs
stubRequestsPassingTest
:
^
BOOL
(
NSURLRequest
*
_Nonnull
request
)
{
return
[
self
shouldUseMocks
];
}
withStubResponse
:
^
OHHTTPStubsResponse
*
_Nonnull
(
NSURLRequest
*
_Nonnull
request
)
{
return
[
OHHTTPStubsResponse
responseWithKey
:
@"testGetOutOfIndexCollectionPage_0"
];
}];
[
OHHTTPStubs
stubUsingResponseWithKey
:
@"testGetOutOfIndexCollectionPage_0"
useMocks
:[
self
shouldUseMocks
]];
XCTestExpectation
*
expectation
=
[
self
expectationWithDescription
:
NSStringFromSelector
(
_cmd
)];
[
self
.
client
getCollectionsPage
:
999
completion
:
^
(
NSArray
<
BUYCollection
*>
*
collections
,
NSUInteger
page
,
BOOL
reachedEnd
,
NSError
*
error
)
{
...
...
@@ -274,11 +242,7 @@
XCTAssertNotNil
(
self
.
collection
);
[
OHHTTPStubs
stubRequestsPassingTest
:
^
BOOL
(
NSURLRequest
*
_Nonnull
request
)
{
return
[
self
shouldUseMocks
];
}
withStubResponse
:
^
OHHTTPStubsResponse
*
_Nonnull
(
NSURLRequest
*
_Nonnull
request
)
{
return
[
OHHTTPStubsResponse
responseWithKey
:
@"testGetProductsInCollection_0"
];
}];
[
OHHTTPStubs
stubUsingResponseWithKey
:
@"testGetProductsInCollection_0"
useMocks
:[
self
shouldUseMocks
]];
XCTestExpectation
*
expectation
=
[
self
expectationWithDescription
:
NSStringFromSelector
(
_cmd
)];
...
...
@@ -298,11 +262,7 @@
-
(
void
)
testValidTags
{
[
OHHTTPStubs
stubRequestsPassingTest
:
^
BOOL
(
NSURLRequest
*
_Nonnull
request
)
{
return
[
self
shouldUseMocks
];
}
withStubResponse
:
^
OHHTTPStubsResponse
*
_Nonnull
(
NSURLRequest
*
_Nonnull
request
)
{
return
[
OHHTTPStubsResponse
responseWithKey
:
@"testGetValidTag_0"
];
}];
[
OHHTTPStubs
stubUsingResponseWithKey
:
@"testGetValidTag_0"
useMocks
:[
self
shouldUseMocks
]];
XCTestExpectation
*
expectation
=
[
self
expectationWithDescription
:
NSStringFromSelector
(
_cmd
)];
...
...
Mobile Buy SDK/Mobile Buy SDK Tests/BUYIntegrationTest.m
View file @
dc2579cb
This diff is collapsed.
Click to expand it.
Mobile Buy SDK/Mobile Buy SDK Tests/OHHTTPStubsResponse+Helpers.h
View file @
dc2579cb
...
...
@@ -26,8 +26,15 @@
#import <OHHTTPStubs/OHHTTPStubs.h>
@interface
OHHTTPStubsResponse
(
Helpers
)
@interface
OHHTTPStubsResponse
(
Buy
)
+
(
instancetype
)
responseWithKey
:(
NSString
*
)
key
;
@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 @@
#import "OHHTTPStubsResponse+Helpers.h"
static
NSDictionary
*
JSONMock
;
@implementation
OHHTTPStubsResponse
(
Buy
)
@implementation
OHHTTPStubsResponse
(
Helpers
)
+
(
instancetype
)
responseWithKey
:(
NSString
*
)
key
+
(
NSDictionary
*
)
mockResponses
{
static
NSDictionary
*
dictionary
=
nil
;
static
dispatch_once_t
onceToken
;
dispatch_once
(
&
onceToken
,
^
{
NSBundle
*
bundle
=
[
NSBundle
bundleForClass
:[
self
class
]];
NSBundle
*
bundle
=
[
NSBundle
bundleForClass
:[
self
class
]];
NSString
*
jsonPath
=
[
bundle
pathForResource
:
@"mocked_responses"
ofType
:
@"json"
];
NSData
*
jsonData
=
[
NSData
dataWithContentsOfFile
:
jsonPath
];
JSONMock
=
[
NSJSONSerialization
JSONObjectWithData
:
jsonData
options
:
0
error
:
nil
];
NSData
*
jsonData
=
[
NSData
dataWithContentsOfFile
:
jsonPath
];
dictionary
=
[
NSJSONSerialization
JSONObjectWithData
:
jsonData
options
:
0
error
:
nil
];
});
NSDictionary
*
json
=
JSONMock
[
key
];
NSData
*
data
=
[
json
[
@"body"
]
dataUsingEncoding
:
NSUTF8StringEncoding
];
int
code
=
[
json
[
@"code"
]
intValue
];
return
dictionary
;
}
+
(
instancetype
)
responseWithKey
:
(
NSString
*
)
key
{
NSDictionary
*
mocks
=
[
self
mockResponses
];
NSDictionary
*
json
=
mocks
[
key
];
NSData
*
data
=
[
json
[
@"body"
]
dataUsingEncoding
:
NSUTF8StringEncoding
];
int
code
=
[
json
[
@"code"
]
intValue
];
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
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