Commit a353280d by David Muzi Committed by GitHub

Merge pull request #273 from Shopify/task/customer-update

Add customer update endpoint
parents edcaa8e9 770a2411
...@@ -197,22 +197,16 @@ ...@@ -197,22 +197,16 @@
[self waitForExpectationsWithTimeout:10.0 handler:^(NSError *error) {}]; [self waitForExpectationsWithTimeout:10.0 handler:^(NSError *error) {}];
} }
#pragma mark - Update -
- (void)testCustomerUpdate - (void)testCustomerUpdate
{ {
[OHHTTPStubs stubUsingResponseWithKey:@"testCustomerLogin" useMocks:[self shouldUseMocks]]; [OHHTTPStubs stubUsingResponseWithKey:@"testCustomerLogin" useMocks:[self shouldUseMocks]];
XCTestExpectation *expectation = [self expectationWithDescription:NSStringFromSelector(_cmd)]; XCTestExpectation *expectation = [self expectationWithDescription:NSStringFromSelector(_cmd)];
BUYAccountCredentialItem *email = [BUYAccountCredentialItem itemWithEmail:self.customerEmail]; [self.client updateCustomer:_customer callback:^(BUYCustomer * _Nullable customer, NSError * _Nullable error) {
BUYAccountCredentials *credentials = [BUYAccountCredentials credentialsWithItems:@[email]];
[self.client updateCustomerWithCredentials:credentials callback:^(BUYCustomer *customer, NSError *error) {
XCTAssertNil(error); XCTAssertNil(error);
XCTAssertNotNil(customer); XCTAssertNotNil(customer);
XCTAssertEqualObjects(customer.email, self.customerEmail);
[expectation fulfill]; [expectation fulfill];
}]; }];
......
...@@ -119,14 +119,13 @@ typedef void (^BUYDataOrderBlock)(BUYOrder * _Nullable order, NSError * _Nullabl ...@@ -119,14 +119,13 @@ typedef void (^BUYDataOrderBlock)(BUYOrder * _Nullable order, NSError * _Nullabl
/** /**
* PUT /api/customers/:customer_id * PUT /api/customers/:customer_id
* Update customer credentials represented by BUYAccountCredentials object
* *
* @param credentials Credentials containing a password * @param customer the customer object to update
* @param block (BUYCustomer *customer, NSError *error) * @param block (BUYCustomer *customer, NSError *error)
* *
* @return The associated BUYRequestOperation * @return The associated BUYRequestOperation
*/ */
- (NSOperation *)updateCustomerWithCredentials:(BUYAccountCredentials *)credentials callback:(BUYDataCustomerBlock)block; - (NSOperation *)updateCustomer:(BUYCustomer *)customer callback:(BUYDataCustomerBlock)block;
/** /**
* PUT /api/customers/:customer_id/reset * PUT /api/customers/:customer_id/reset
......
...@@ -82,10 +82,10 @@ ...@@ -82,10 +82,10 @@
}]; }];
} }
- (NSOperation *)updateCustomerWithCredentials:(BUYAccountCredentials *)credentials callback:(BUYDataCustomerBlock)block - (NSOperation *)updateCustomer:(BUYCustomer *)customer callback:(BUYDataCustomerBlock)block
{ {
NSURL *url = [self urlForLoggedInCustomer]; NSURL *url = [self urlForCustomersWithID:customer.identifier.stringValue];
return [self putRequestForURL:url object:credentials.JSONRepresentation completionHandler:^(NSDictionary *json, NSHTTPURLResponse *response, NSError *error) { return [self putRequestForURL:url object:@{@"customer": customer.JSONDictionary} completionHandler:^(NSDictionary *json, NSHTTPURLResponse *response, NSError *error) {
BUYCustomer *customer = nil; BUYCustomer *customer = nil;
if (json && !error) { if (json && !error) {
customer = [self.modelManager customerWithJSONDictionary:json]; customer = [self.modelManager customerWithJSONDictionary:json];
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment