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
b8d3e81b
Commit
b8d3e81b
authored
May 24, 2016
by
Dima Bart
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add endpoint for updating customer.
parent
1bee7bab
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
95 additions
and
26 deletions
+95
-26
BUYClientTest_Customer.m
Mobile Buy SDK/Mobile Buy SDK Tests/BUYClientTest_Customer.m
+71
-26
BUYClient+Customers.h
Mobile Buy SDK/Mobile Buy SDK/Data/BUYClient+Customers.h
+12
-0
BUYClient+Customers.m
Mobile Buy SDK/Mobile Buy SDK/Data/BUYClient+Customers.m
+12
-0
No files found.
Mobile Buy SDK/Mobile Buy SDK Tests/BUYClientTest_Customer.m
View file @
b8d3e81b
...
@@ -40,12 +40,16 @@
...
@@ -40,12 +40,16 @@
@implementation
BUYClientTest_Customer
@implementation
BUYClientTest_Customer
#pragma mark - Tear Down -
-
(
void
)
tearDown
-
(
void
)
tearDown
{
{
[
super
tearDown
];
[
super
tearDown
];
[
OHHTTPStubs
removeAllStubs
];
[
OHHTTPStubs
removeAllStubs
];
}
}
#pragma mark - Creation -
-
(
void
)
testCustomerDuplicateEmail
-
(
void
)
testCustomerDuplicateEmail
{
{
[
OHHTTPStubs
stubRequestsPassingTest
:
^
BOOL
(
NSURLRequest
*
_Nonnull
request
)
{
[
OHHTTPStubs
stubRequestsPassingTest
:
^
BOOL
(
NSURLRequest
*
_Nonnull
request
)
{
...
@@ -55,13 +59,7 @@
...
@@ -55,13 +59,7 @@
}];
}];
XCTestExpectation
*
expectation
=
[
self
expectationWithDescription
:
NSStringFromSelector
(
_cmd
)];
XCTestExpectation
*
expectation
=
[
self
expectationWithDescription
:
NSStringFromSelector
(
_cmd
)];
[
self
.
client
createCustomerWithCredentials
:[
self
credentialsForCreation
]
callback
:
^
(
BUYCustomer
*
customer
,
NSString
*
token
,
NSError
*
error
)
{
BUYAccountCredentialItem
*
emailItem
=
[
BUYAccountCredentialItem
itemWithEmail
:
self
.
customerEmail
];
BUYAccountCredentialItem
*
passwordItem
=
[
BUYAccountCredentialItem
itemWithPassword
:
self
.
customerPassword
];
BUYAccountCredentialItem
*
passwordConfItem
=
[
BUYAccountCredentialItem
itemWithPasswordConfirmation
:
self
.
customerPassword
];
BUYAccountCredentials
*
credentials
=
[
BUYAccountCredentials
credentialsWithItems
:@[
emailItem
,
passwordItem
,
passwordConfItem
]];
[
self
.
client
createCustomerWithCredentials
:
credentials
callback
:
^
(
BUYCustomer
*
customer
,
NSString
*
token
,
NSError
*
error
)
{
XCTAssertNil
(
customer
);
XCTAssertNil
(
customer
);
XCTAssertNotNil
(
error
);
XCTAssertNotNil
(
error
);
...
@@ -92,13 +90,7 @@
...
@@ -92,13 +90,7 @@
}];
}];
XCTestExpectation
*
expectation
=
[
self
expectationWithDescription
:
NSStringFromSelector
(
_cmd
)];
XCTestExpectation
*
expectation
=
[
self
expectationWithDescription
:
NSStringFromSelector
(
_cmd
)];
[
self
.
client
createCustomerWithCredentials
:[
self
credentialsForFailure
]
callback
:
^
(
BUYCustomer
*
customer
,
NSString
*
token
,
NSError
*
error
)
{
BUYAccountCredentialItem
*
emailItem
=
[
BUYAccountCredentialItem
itemWithEmail
:
@"a"
];
BUYAccountCredentialItem
*
passwordItem
=
[
BUYAccountCredentialItem
itemWithPassword
:
@"b"
];
BUYAccountCredentialItem
*
passwordConfItem
=
[
BUYAccountCredentialItem
itemWithPasswordConfirmation
:
@"c"
];
BUYAccountCredentials
*
credentials
=
[
BUYAccountCredentials
credentialsWithItems
:@[
emailItem
,
passwordItem
,
passwordConfItem
]];
[
self
.
client
createCustomerWithCredentials
:
credentials
callback
:
^
(
BUYCustomer
*
customer
,
NSString
*
token
,
NSError
*
error
)
{
XCTAssertNil
(
customer
);
XCTAssertNil
(
customer
);
XCTAssertNotNil
(
error
);
XCTAssertNotNil
(
error
);
...
@@ -125,6 +117,8 @@
...
@@ -125,6 +117,8 @@
}];
}];
}
}
#pragma mark - Auth -
-
(
void
)
testCustomerLogin
-
(
void
)
testCustomerLogin
{
{
[
OHHTTPStubs
stubRequestsPassingTest
:
^
BOOL
(
NSURLRequest
*
_Nonnull
request
)
{
[
OHHTTPStubs
stubRequestsPassingTest
:
^
BOOL
(
NSURLRequest
*
_Nonnull
request
)
{
...
@@ -134,12 +128,7 @@
...
@@ -134,12 +128,7 @@
}];
}];
XCTestExpectation
*
expectation
=
[
self
expectationWithDescription
:
NSStringFromSelector
(
_cmd
)];
XCTestExpectation
*
expectation
=
[
self
expectationWithDescription
:
NSStringFromSelector
(
_cmd
)];
[
self
.
client
loginCustomerWithCredentials
:[
self
credentialsForLogin
]
callback
:
^
(
BUYCustomer
*
customer
,
NSString
*
token
,
NSError
*
error
)
{
BUYAccountCredentialItem
*
emailItem
=
[
BUYAccountCredentialItem
itemWithEmail
:
self
.
customerEmail
];
BUYAccountCredentialItem
*
passwordItem
=
[
BUYAccountCredentialItem
itemWithPassword
:
self
.
customerPassword
];
BUYAccountCredentials
*
credentials
=
[
BUYAccountCredentials
credentialsWithItems
:@[
emailItem
,
passwordItem
]];
[
self
.
client
loginCustomerWithCredentials
:
credentials
callback
:
^
(
BUYCustomer
*
customer
,
NSString
*
token
,
NSError
*
error
)
{
XCTAssertNil
(
error
);
XCTAssertNil
(
error
);
XCTAssertNotNil
(
customer
);
XCTAssertNotNil
(
customer
);
...
@@ -162,12 +151,7 @@
...
@@ -162,12 +151,7 @@
}];
}];
XCTestExpectation
*
expectation
=
[
self
expectationWithDescription
:
NSStringFromSelector
(
_cmd
)];
XCTestExpectation
*
expectation
=
[
self
expectationWithDescription
:
NSStringFromSelector
(
_cmd
)];
[
self
.
client
loginCustomerWithCredentials
:[
self
credentialsForLogin
]
callback
:
^
(
BUYCustomer
*
customer
,
NSString
*
token
,
NSError
*
error
)
{
BUYAccountCredentialItem
*
emailItem
=
[
BUYAccountCredentialItem
itemWithEmail
:
self
.
customerEmail
];
BUYAccountCredentialItem
*
passwordItem
=
[
BUYAccountCredentialItem
itemWithPassword
:
self
.
customerPassword
];
BUYAccountCredentials
*
credentials
=
[
BUYAccountCredentials
credentialsWithItems
:@[
emailItem
,
passwordItem
]];
[
self
.
client
loginCustomerWithCredentials
:
credentials
callback
:
^
(
BUYCustomer
*
customer
,
NSString
*
token
,
NSError
*
error
)
{
[
OHHTTPStubs
stubRequestsPassingTest
:
^
BOOL
(
NSURLRequest
*
_Nonnull
request
)
{
[
OHHTTPStubs
stubRequestsPassingTest
:
^
BOOL
(
NSURLRequest
*
_Nonnull
request
)
{
return
[
self
shouldUseMocks
];
return
[
self
shouldUseMocks
];
...
@@ -187,4 +171,65 @@
...
@@ -187,4 +171,65 @@
[
self
waitForExpectationsWithTimeout
:
10000
handler
:
nil
];
[
self
waitForExpectationsWithTimeout
:
10000
handler
:
nil
];
}
}
#pragma mark - Update -
-
(
void
)
testCustomerUpdate
{
[
OHHTTPStubs
stubRequestsPassingTest
:
^
BOOL
(
NSURLRequest
*
_Nonnull
request
)
{
return
[
self
shouldUseMocks
];
}
withStubResponse
:
^
OHHTTPStubsResponse
*
_Nonnull
(
NSURLRequest
*
_Nonnull
request
)
{
return
[
OHHTTPStubsResponse
responseWithKey
:
@"testCustomerLogin"
];
}];
XCTestExpectation
*
expectation
=
[
self
expectationWithDescription
:
NSStringFromSelector
(
_cmd
)];
BUYAccountCredentialItem
*
email
=
[
BUYAccountCredentialItem
itemWithEmail
:
self
.
customerEmail
];
BUYAccountCredentials
*
credentials
=
[
BUYAccountCredentials
credentialsWithItems
:@[
email
]];
[
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"
];
}];
[
self
.
client
updateCustomerWithCredentials
:
credentials
customerID
:
customer
.
identifier
.
stringValue
callback
:^
(
BUYCustomer
*
customer
,
NSError
*
error
)
{
XCTAssertNil
(
error
);
XCTAssertNotNil
(
customer
);
XCTAssertEqualObjects
(
customer
.
email
,
self
.
customerEmail
);
[
expectation
fulfill
];
}];
}];
[
self
waitForExpectationsWithTimeout
:
10
handler
:
nil
];
}
#pragma mark - Credentials -
-
(
BUYAccountCredentials
*
)
credentialsForLogin
{
BUYAccountCredentialItem
*
email
=
[
BUYAccountCredentialItem
itemWithEmail
:
self
.
customerEmail
];
BUYAccountCredentialItem
*
password
=
[
BUYAccountCredentialItem
itemWithPassword
:
self
.
customerPassword
];
return
[
BUYAccountCredentials
credentialsWithItems
:@[
email
,
password
]];
}
-
(
BUYAccountCredentials
*
)
credentialsForCreation
{
BUYAccountCredentialItem
*
email
=
[
BUYAccountCredentialItem
itemWithEmail
:
self
.
customerEmail
];
BUYAccountCredentialItem
*
password
=
[
BUYAccountCredentialItem
itemWithPassword
:
self
.
customerPassword
];
BUYAccountCredentialItem
*
password2
=
[
BUYAccountCredentialItem
itemWithPassword
:
self
.
customerPassword
];
return
[
BUYAccountCredentials
credentialsWithItems
:@[
email
,
password
,
password2
]];
}
-
(
BUYAccountCredentials
*
)
credentialsForFailure
{
BUYAccountCredentialItem
*
email
=
[
BUYAccountCredentialItem
itemWithEmail
:
@"a"
];
BUYAccountCredentialItem
*
password
=
[
BUYAccountCredentialItem
itemWithPassword
:
@"b"
];
BUYAccountCredentialItem
*
password2
=
[
BUYAccountCredentialItem
itemWithPasswordConfirmation
:
@"c"
];
return
[
BUYAccountCredentials
credentialsWithItems
:@[
email
,
password
,
password2
]];
}
@end
@end
Mobile Buy SDK/Mobile Buy SDK/Data/BUYClient+Customers.h
View file @
b8d3e81b
...
@@ -152,6 +152,18 @@ typedef void (^BUYDataOrdersBlock)(NSArray <BUYOrder*> * _Nullable orders, NSErr
...
@@ -152,6 +152,18 @@ typedef void (^BUYDataOrdersBlock)(NSArray <BUYOrder*> * _Nullable orders, NSErr
-
(
BUYRequestOperation
*
)
activateCustomerWithCredentials
:(
BUYAccountCredentials
*
)
credentials
customerID
:(
NSString
*
)
customerID
token
:(
NSString
*
)
token
callback
:(
BUYDataCustomerTokenBlock
)
block
;
-
(
BUYRequestOperation
*
)
activateCustomerWithCredentials
:(
BUYAccountCredentials
*
)
credentials
customerID
:(
NSString
*
)
customerID
token
:(
NSString
*
)
token
callback
:(
BUYDataCustomerTokenBlock
)
block
;
/**
/**
* PUT /api/customers/:customer_id
* Update customer credentials represented by BUYAccountCredentials object
*
* @param credentials Credentials containing a password and password confirmation
* @param customerID ID of customer being activated
* @param block (BUYCustomer *customer, NSError *error)
*
* @return The associated BUYRequestOperation
*/
-
(
BUYRequestOperation
*
)
updateCustomerWithCredentials
:(
BUYAccountCredentials
*
)
credentials
customerID
:(
NSString
*
)
customerID
callback
:(
BUYDataCustomerBlock
)
block
;
/**
* PUT /api/customers/:customer_id/reset
* PUT /api/customers/:customer_id/reset
* Resets an existing customer's password
* Resets an existing customer's password
*
*
...
...
Mobile Buy SDK/Mobile Buy SDK/Data/BUYClient+Customers.m
View file @
b8d3e81b
...
@@ -145,6 +145,18 @@
...
@@ -145,6 +145,18 @@
}];
}];
}
}
-
(
BUYRequestOperation
*
)
updateCustomerWithCredentials
:(
BUYAccountCredentials
*
)
credentials
customerID
:(
NSString
*
)
customerID
callback
:(
BUYDataCustomerBlock
)
block
{
NSURL
*
route
=
[
self
urlForCustomersWithID
:
customerID
];
return
[
self
putRequestForURL
:
route
object
:
credentials
.
JSONRepresentation
completionHandler
:^
(
NSDictionary
*
json
,
NSHTTPURLResponse
*
response
,
NSError
*
error
)
{
BUYCustomer
*
customer
=
nil
;
if
(
json
&&
!
error
)
{
customer
=
[
self
.
modelManager
customerWithJSONDictionary
:
json
];
}
block
(
customer
,
error
);
}];
}
-
(
BUYRequestOperation
*
)
resetPasswordWithCredentials
:(
BUYAccountCredentials
*
)
credentials
customerID
:(
NSString
*
)
customerID
token
:(
NSString
*
)
token
callback
:(
BUYDataCustomerTokenBlock
)
block
-
(
BUYRequestOperation
*
)
resetPasswordWithCredentials
:(
BUYAccountCredentials
*
)
credentials
customerID
:(
NSString
*
)
customerID
token
:(
NSString
*
)
token
callback
:(
BUYDataCustomerTokenBlock
)
block
{
{
NSURL
*
route
=
[
self
urlForCustomersPasswordResetWithID
:
customerID
parameters
:@{
@"token"
:
token
}];
NSURL
*
route
=
[
self
urlForCustomersPasswordResetWithID
:
customerID
parameters
:@{
@"token"
:
token
}];
...
...
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