Commit ffb8db1c by Brent Gulanowski

Update tests for changes to customer and address client methods.

parent da1318c5
...@@ -64,7 +64,7 @@ ...@@ -64,7 +64,7 @@
[OHHTTPStubs stubUsingResponseWithKey:@"testCustomerLogin" useMocks:[self shouldUseMocks]]; [OHHTTPStubs stubUsingResponseWithKey:@"testCustomerLogin" useMocks:[self shouldUseMocks]];
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, BUYCustomerToken *token, NSError *error) {
XCTAssertNil(error); XCTAssertNil(error);
XCTAssertNotNil(customer); XCTAssertNotNil(customer);
...@@ -87,7 +87,7 @@ ...@@ -87,7 +87,7 @@
[OHHTTPStubs stubUsingResponseWithKey:@"testCustomerDuplicateEmail" useMocks:[self shouldUseMocks]]; [OHHTTPStubs stubUsingResponseWithKey:@"testCustomerDuplicateEmail" useMocks:[self shouldUseMocks]];
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, BUYCustomerToken *token, NSError *error) {
XCTAssertNil(customer); XCTAssertNil(customer);
XCTAssertNotNil(error); XCTAssertNotNil(error);
...@@ -114,7 +114,7 @@ ...@@ -114,7 +114,7 @@
[OHHTTPStubs stubUsingResponseWithKey:@"testCustomerInvalidEmailPassword" useMocks:[self shouldUseMocks]]; [OHHTTPStubs stubUsingResponseWithKey:@"testCustomerInvalidEmailPassword" useMocks:[self shouldUseMocks]];
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, BUYCustomerToken *token, NSError *error) {
XCTAssertNil(customer); XCTAssertNil(customer);
XCTAssertNotNil(error); XCTAssertNotNil(error);
...@@ -149,7 +149,7 @@ ...@@ -149,7 +149,7 @@
[OHHTTPStubs stubUsingResponseWithKey:@"testCustomerLogout" useMocks:[self shouldUseMocks]]; [OHHTTPStubs stubUsingResponseWithKey:@"testCustomerLogout" useMocks:[self shouldUseMocks]];
XCTestExpectation *expectation = [self expectationWithDescription:NSStringFromSelector(_cmd)]; XCTestExpectation *expectation = [self expectationWithDescription:NSStringFromSelector(_cmd)];
[self.client logoutCustomerID:self.customer.identifier.stringValue callback:^(BUYStatus status, NSError * _Nullable error) { [self.client logoutCustomerCallback:^(BUYStatus status, NSError * _Nullable error) {
XCTAssertNil(error); XCTAssertNil(error);
XCTAssertEqual(status, 204); XCTAssertEqual(status, 204);
...@@ -167,7 +167,7 @@ ...@@ -167,7 +167,7 @@
[OHHTTPStubs stubUsingResponseWithKey:@"testCustomerGetOrders" useMocks:[self shouldUseMocks]]; [OHHTTPStubs stubUsingResponseWithKey:@"testCustomerGetOrders" useMocks:[self shouldUseMocks]];
XCTestExpectation *expectation = [self expectationWithDescription:NSStringFromSelector(_cmd)]; XCTestExpectation *expectation = [self expectationWithDescription:NSStringFromSelector(_cmd)];
[self.client getOrdersForCustomerWithID:self.customer.identifier.stringValue callback:^(NSArray<BUYOrder *> * _Nullable orders, NSError * _Nullable error) { [self.client getOrdersForCustomerCallback:^(NSArray<BUYOrder *> * _Nullable orders, NSError * _Nullable error) {
XCTAssertNotNil(orders); XCTAssertNotNil(orders);
XCTAssertNil(error); XCTAssertNil(error);
...@@ -186,7 +186,7 @@ ...@@ -186,7 +186,7 @@
[OHHTTPStubs stubUsingResponseWithKey:@"testCustomerGetOrder" useMocks:[self shouldUseMocks]]; [OHHTTPStubs stubUsingResponseWithKey:@"testCustomerGetOrder" useMocks:[self shouldUseMocks]];
XCTestExpectation *expectation = [self expectationWithDescription:NSStringFromSelector(_cmd)]; XCTestExpectation *expectation = [self expectationWithDescription:NSStringFromSelector(_cmd)];
[self.client getOrderWithID:self.customerOrderIDs.firstObject customerID:self.customer.identifier.stringValue callback:^(BUYOrder * _Nullable order, NSError * _Nullable error) { [self.client getOrderWithID:self.customerOrderIDs.firstObject callback:^(BUYOrder * _Nullable order, NSError * _Nullable error) {
XCTAssertNil(error); XCTAssertNil(error);
XCTAssertTrue([order isKindOfClass:[BUYOrder class]]); XCTAssertTrue([order isKindOfClass:[BUYOrder class]]);
...@@ -208,7 +208,7 @@ ...@@ -208,7 +208,7 @@
BUYAccountCredentialItem *email = [BUYAccountCredentialItem itemWithEmail:self.customerEmail]; BUYAccountCredentialItem *email = [BUYAccountCredentialItem itemWithEmail:self.customerEmail];
BUYAccountCredentials *credentials = [BUYAccountCredentials credentialsWithItems:@[email]]; BUYAccountCredentials *credentials = [BUYAccountCredentials credentialsWithItems:@[email]];
[self.client updateCustomerWithCredentials:credentials customerID:self.customer.identifier.stringValue callback:^(BUYCustomer *customer, NSError *error) { [self.client updateCustomerWithCredentials:credentials callback:^(BUYCustomer *customer, NSError *error) {
XCTAssertNil(error); XCTAssertNil(error);
XCTAssertNotNil(customer); XCTAssertNotNil(customer);
...@@ -231,7 +231,7 @@ ...@@ -231,7 +231,7 @@
}]; }];
XCTestExpectation *expectation = [self expectationWithDescription:NSStringFromSelector(_cmd)]; XCTestExpectation *expectation = [self expectationWithDescription:NSStringFromSelector(_cmd)];
[self.client getAddressesForCustomerID:self.customer.identifier.stringValue callback:^(NSArray<BUYAddress *> * _Nullable addresses, NSError * _Nullable error) { [self.client getAddressesCallback:^(NSArray<BUYAddress *> * _Nullable addresses, NSError * _Nullable error) {
XCTAssertNotNil(addresses); XCTAssertNotNil(addresses);
XCTAssertTrue(addresses.count > 0); XCTAssertTrue(addresses.count > 0);
...@@ -264,7 +264,7 @@ ...@@ -264,7 +264,7 @@
BUYAddress *address = [self address]; BUYAddress *address = [self address];
[self.client createAddress:address customerID:self.customer.identifier.stringValue callback:^(BUYAddress * _Nullable returnedAddress, NSError * _Nullable error) { [self.client createAddress:address callback:^(BUYAddress * _Nullable returnedAddress, NSError * _Nullable error) {
[OHHTTPStubs stubUsingResponseWithKey:@"testCustomerLogin" useMocks:[self shouldUseMocks]]; [OHHTTPStubs stubUsingResponseWithKey:@"testCustomerLogin" useMocks:[self shouldUseMocks]];
...@@ -299,7 +299,7 @@ ...@@ -299,7 +299,7 @@
}]; }];
XCTestExpectation *expectation = [self expectationWithDescription:NSStringFromSelector(_cmd)]; XCTestExpectation *expectation = [self expectationWithDescription:NSStringFromSelector(_cmd)];
[self.client getAddressWithID:self.createdAddress.identifier customerID:self.customer.identifier.stringValue callback:^(BUYAddress * _Nullable address, NSError * _Nullable error) { [self.client getAddressWithID:self.createdAddress.identifier callback:^(BUYAddress * _Nullable address, NSError * _Nullable error) {
XCTAssertNotNil(address); XCTAssertNotNil(address);
XCTAssertNil(error); XCTAssertNil(error);
...@@ -323,7 +323,7 @@ ...@@ -323,7 +323,7 @@
BUYAddress *modifiedAddress = [self addressByModyfyingAddress:self.createdAddress]; BUYAddress *modifiedAddress = [self addressByModyfyingAddress:self.createdAddress];
[self.client updateAddress:modifiedAddress customerID:self.customer.identifier.stringValue callback:^(BUYAddress * _Nullable returnedAddress, NSError * _Nullable error) { [self.client updateAddress:modifiedAddress callback:^(BUYAddress * _Nullable returnedAddress, NSError * _Nullable error) {
XCTAssertNotNil(returnedAddress); XCTAssertNotNil(returnedAddress);
XCTAssertNil(error); XCTAssertNil(error);
...@@ -353,7 +353,7 @@ ...@@ -353,7 +353,7 @@
}]; }];
XCTestExpectation *expectation = [self expectationWithDescription:NSStringFromSelector(_cmd)]; XCTestExpectation *expectation = [self expectationWithDescription:NSStringFromSelector(_cmd)];
[self.client deleteAddressWithID:self.createdAddress.identifier customerID:self.customer.identifier.stringValue callback:^(BUYStatus status, NSError * _Nullable error) { [self.client deleteAddressWithID:self.createdAddress.identifier callback:^(BUYStatus status, NSError * _Nullable error) {
XCTAssertEqual(status, 204); XCTAssertEqual(status, 204);
XCTAssertNil(error); XCTAssertNil(error);
......
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
#import <XCTest/XCTest.h> #import <XCTest/XCTest.h>
#import "BUYClient+Routing.h" #import "BUYClient+Routing.h"
#import "BUYCustomerToken.h"
@interface BUYClient_RoutingTests : XCTestCase @interface BUYClient_RoutingTests : XCTestCase
...@@ -42,13 +43,14 @@ ...@@ -42,13 +43,14 @@
[super setUp]; [super setUp];
self.client = [[BUYClient alloc] initWithShopDomain:@"_DOMAIN_" apiKey:@"_API_KEY_" appId:@"_APP_ID_"]; self.client = [[BUYClient alloc] initWithShopDomain:@"_DOMAIN_" apiKey:@"_API_KEY_" appId:@"_APP_ID_"];
self.client.customerToken = [[BUYCustomerToken alloc] initWithCustomerID:@1 accessToken:@"token" expiry:[NSDate date]];
} }
#pragma mark - Test Routes - #pragma mark - Test Routes -
- (void)testRoutes - (void)testRoutes
{ {
NSString *identifier = @"_ID_"; NSString *identifier = @"1";
NSString *token = @"_TOKEN_"; NSString *token = @"_TOKEN_";
NSDictionary *parameters = @{ @"param" : @"value" }; NSDictionary *parameters = @{ @"param" : @"value" };
...@@ -122,41 +124,37 @@ ...@@ -122,41 +124,37 @@
@"https://_DOMAIN_/api/customers/recover.json" @"https://_DOMAIN_/api/customers/recover.json"
); );
XCTAssertEqualObjects( XCTAssertEqualObjects(
[self.client urlForCustomersOrdersWithID:identifier].absoluteString, [self.client urlForCustomersOrders].absoluteString,
@"https://_DOMAIN_/api/customers/_ID_/orders.json" @"https://_DOMAIN_/api/customers/1/orders.json"
); );
XCTAssertEqualObjects( XCTAssertEqualObjects(
[self.client urlForCustomersOrdersWithID:identifier orderID:@99].absoluteString, [self.client urlForCustomersOrdersWithOrderID:@99].absoluteString,
@"https://_DOMAIN_/api/customers/_ID_/orders/99.json" @"https://_DOMAIN_/api/customers/1/orders/99.json"
); );
XCTAssertEqualObjects( XCTAssertEqualObjects(
[self.client urlForCustomersWithID:identifier].absoluteString, [self.client urlForCustomersWithID:identifier].absoluteString,
@"https://_DOMAIN_/api/customers/_ID_.json" @"https://_DOMAIN_/api/customers/1.json"
); );
XCTAssertEqualObjects( XCTAssertEqualObjects(
[self.client urlForCustomersActivationWithID:identifier parameters:parameters].absoluteString, [self.client urlForCustomersActivationWithID:identifier parameters:parameters].absoluteString,
@"https://_DOMAIN_/api/customers/_ID_/activate.json?param=value" @"https://_DOMAIN_/api/customers/1/activate.json?param=value"
); );
XCTAssertEqualObjects( XCTAssertEqualObjects(
[self.client urlForCustomersTokenWithID:identifier].absoluteString, [self.client urlForCustomersTokenRenewal].absoluteString,
@"https://_DOMAIN_/api/customers/_ID_/customer_token.json" @"https://_DOMAIN_/api/customers/1/customer_token/renew.json"
);
XCTAssertEqualObjects(
[self.client urlForCustomersTokenRenewalWithID:identifier].absoluteString,
@"https://_DOMAIN_/api/customers/_ID_/customer_token/renew.json"
); );
XCTAssertEqualObjects( XCTAssertEqualObjects(
[self.client urlForCustomersPasswordResetWithID:identifier parameters:parameters].absoluteString, [self.client urlForCustomersPasswordResetWithID:identifier parameters:parameters].absoluteString,
@"https://_DOMAIN_/api/customers/_ID_/reset.json?param=value" @"https://_DOMAIN_/api/customers/1/reset.json?param=value"
); );
XCTAssertEqualObjects( XCTAssertEqualObjects(
[self.client urlForCustomersAddressesWithID:identifier].absoluteString, [self.client urlForCustomersAddresses].absoluteString,
@"https://_DOMAIN_/api/customers/_ID_/addresses.json" @"https://_DOMAIN_/api/customers/1/addresses.json"
); );
XCTAssertEqualObjects( XCTAssertEqualObjects(
[self.client urlForCustomersAddressWithID:identifier addressID:@999].absoluteString, [self.client urlForCustomersAddressWithAddressID:@999].absoluteString,
@"https://_DOMAIN_/api/customers/_ID_/addresses/999.json" @"https://_DOMAIN_/api/customers/1/addresses/999.json"
); );
} }
......
...@@ -38,8 +38,6 @@ ...@@ -38,8 +38,6 @@
#import "BUYApplePayTestToken.h" #import "BUYApplePayTestToken.h"
#import "BUYRequestOperation.h" #import "BUYRequestOperation.h"
NSString * const BUYFakeCustomerToken = @"dsfasdgafdg";
@interface BUYClient_Test : BUYClient @interface BUYClient_Test : BUYClient
@end @end
...@@ -58,6 +56,23 @@ NSString * const BUYFakeCustomerToken = @"dsfasdgafdg"; ...@@ -58,6 +56,23 @@ NSString * const BUYFakeCustomerToken = @"dsfasdgafdg";
@implementation BUYClientTest @implementation BUYClientTest
- (void)setUp
{
[super setUp];
self.client.customerToken = [self customerTokenForTesting];
}
- (void)tearDown
{
self.client.customerToken = nil;
[super tearDown];
}
- (BUYCustomerToken *)customerTokenForTesting
{
return [[BUYCustomerToken alloc] initWithCustomerID:@1 accessToken:@"" expiry:[NSDate dateWithTimeIntervalSinceNow:3600]];
}
- (void)setupClient - (void)setupClient
{ {
self.shopDomain = BUYShopDomain_Placeholder; self.shopDomain = BUYShopDomain_Placeholder;
...@@ -211,7 +226,7 @@ NSString * const BUYFakeCustomerToken = @"dsfasdgafdg"; ...@@ -211,7 +226,7 @@ NSString * const BUYFakeCustomerToken = @"dsfasdgafdg";
]; ];
BUYAccountCredentials *credentials = [BUYAccountCredentials credentialsWithItems:items]; BUYAccountCredentials *credentials = [BUYAccountCredentials credentialsWithItems:items];
BUYRequestOperation *task = (BUYRequestOperation *)[self.client createCustomerWithCredentials:credentials callback:^(BUYCustomer *customer, NSString *token, NSError *error) { BUYRequestOperation *task = (BUYRequestOperation *)[self.client createCustomerWithCredentials:credentials callback:^(BUYCustomer *customer, BUYCustomerToken *token, NSError *error) {
}]; }];
...@@ -239,7 +254,7 @@ NSString * const BUYFakeCustomerToken = @"dsfasdgafdg"; ...@@ -239,7 +254,7 @@ NSString * const BUYFakeCustomerToken = @"dsfasdgafdg";
[BUYAccountCredentialItem itemWithPassword:@"password"], [BUYAccountCredentialItem itemWithPassword:@"password"],
]; ];
BUYAccountCredentials *credentials = [BUYAccountCredentials credentialsWithItems:items]; BUYAccountCredentials *credentials = [BUYAccountCredentials credentialsWithItems:items];
BUYRequestOperation *task = (BUYRequestOperation *)[self.client loginCustomerWithCredentials:credentials callback:^(BUYCustomer *customer, NSString *token, NSError *error) { BUYRequestOperation *task = (BUYRequestOperation *)[self.client loginCustomerWithCredentials:credentials callback:^(BUYCustomer *customer, BUYCustomerToken *token, NSError *error) {
}]; }];
...@@ -260,28 +275,28 @@ NSString * const BUYFakeCustomerToken = @"dsfasdgafdg"; ...@@ -260,28 +275,28 @@ NSString * const BUYFakeCustomerToken = @"dsfasdgafdg";
- (void)testGetCustomerURL - (void)testGetCustomerURL
{ {
BUYRequestOperation *task = (BUYRequestOperation *)[self.client getCustomerWithID:@"" callback:^(BUYCustomer *customer, NSError *error) { BUYRequestOperation *task = (BUYRequestOperation *)[self.client getCustomerCallback:^(BUYCustomer *customer, NSError *error) {
}]; }];
XCTAssertEqualObjects(task.originalRequest.URL.scheme, @"https"); XCTAssertEqualObjects(task.originalRequest.URL.scheme, @"https");
XCTAssertEqualObjects(task.originalRequest.URL.path, @"/api/customers.json"); XCTAssertEqualObjects(task.originalRequest.URL.path, @"/api/customers/1.json");
XCTAssertEqualObjects(task.originalRequest.HTTPMethod, @"GET"); XCTAssertEqualObjects(task.originalRequest.HTTPMethod, @"GET");
XCTAssertEqualObjects(self.client.customerToken, task.originalRequest.allHTTPHeaderFields[BUYClientCustomerAccessToken]); XCTAssertEqualObjects(self.client.customerToken.accessToken, task.originalRequest.allHTTPHeaderFields[BUYClientCustomerAccessToken]);
} }
- (void)testGetOrdersForCustomerURL - (void)testGetOrdersForCustomerURL
{ {
BUYRequestOperation *task = (BUYRequestOperation *)[self.client getOrdersForCustomerWithID:@"99" callback:^(NSArray<BUYOrder *> *orders, NSError *error) { BUYRequestOperation *task = (BUYRequestOperation *)[self.client getOrdersForCustomerCallback:^(NSArray<BUYOrder *> *orders, NSError *error) {
}]; }];
XCTAssertEqualObjects(task.originalRequest.URL.scheme, @"https"); XCTAssertEqualObjects(task.originalRequest.URL.scheme, @"https");
XCTAssertEqualObjects(task.originalRequest.URL.path, @"/api/customers/99/orders.json"); XCTAssertEqualObjects(task.originalRequest.URL.path, @"/api/customers/1/orders.json");
XCTAssertEqualObjects(task.originalRequest.HTTPMethod, @"GET"); XCTAssertEqualObjects(task.originalRequest.HTTPMethod, @"GET");
XCTAssertEqualObjects(self.client.customerToken, task.originalRequest.allHTTPHeaderFields[BUYClientCustomerAccessToken]); XCTAssertEqualObjects(self.client.customerToken.accessToken, task.originalRequest.allHTTPHeaderFields[BUYClientCustomerAccessToken]);
} }
- (void)testCustomerRecovery - (void)testCustomerRecovery
...@@ -307,11 +322,12 @@ NSString * const BUYFakeCustomerToken = @"dsfasdgafdg"; ...@@ -307,11 +322,12 @@ NSString * const BUYFakeCustomerToken = @"dsfasdgafdg";
{ {
self.client.customerToken = nil; self.client.customerToken = nil;
BUYRequestOperation *task = (BUYRequestOperation *)[self.client renewCustomerTokenWithID:@"" callback:^(NSString *token, NSError *error) {}]; BUYRequestOperation *task = (BUYRequestOperation *)[self.client renewCustomerTokenCallback:^(NSString *token, NSError *error) {}];
XCTAssertNil(task); // task should be nil if no customer token was set on the client XCTAssertNil(task); // task should be nil if no customer token was set on the client
self.client.customerToken = BUYFakeCustomerToken;
task = (BUYRequestOperation *)[self.client renewCustomerTokenWithID:@"1" callback:^(NSString *token, NSError *error) { self.client.customerToken = [[BUYCustomerToken alloc] initWithCustomerID:@1 accessToken:@"fake_token" expiry:[NSDate dateWithTimeIntervalSinceNow:3600]];
task = (BUYRequestOperation *)[self.client renewCustomerTokenCallback:^(NSString *token, NSError *error) {
}]; }];
...@@ -328,7 +344,7 @@ NSString * const BUYFakeCustomerToken = @"dsfasdgafdg"; ...@@ -328,7 +344,7 @@ NSString * const BUYFakeCustomerToken = @"dsfasdgafdg";
BUYAccountCredentials *credentials = [BUYAccountCredentials credentialsWithItems:items]; BUYAccountCredentials *credentials = [BUYAccountCredentials credentialsWithItems:items];
NSString *customerID = @"12345"; NSString *customerID = @"12345";
NSString *token = @"12345"; NSString *token = @"12345";
BUYRequestOperation *task = (BUYRequestOperation *)[self.client activateCustomerWithCredentials:credentials customerID:customerID token:token callback:^(BUYCustomer *customer, NSString *token, NSError *error) { BUYRequestOperation *task = (BUYRequestOperation *)[self.client activateCustomerWithCredentials:credentials customerID:customerID token:token callback:^(BUYCustomer *customer, BUYCustomerToken *token, NSError *error) {
}]; }];
......
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