BUYClient+RoutingTests.m 5.84 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
//
//  BUYClient+RoutingTests.m
//  Mobile Buy SDK
//
//  Created by Shopify.
//  Copyright (c) 2015 Shopify Inc. All rights reserved.
//
//  Permission is hereby granted, free of charge, to any person obtaining a copy
//  of this software and associated documentation files (the "Software"), to deal
//  in the Software without restriction, including without limitation the rights
//  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
//  copies of the Software, and to permit persons to whom the Software is
//  furnished to do so, subject to the following conditions:
//
//  The above copyright notice and this permission notice shall be included in
//  all copies or substantial portions of the Software.
//
//  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
//  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
//  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
//  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
//  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
//  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
//  THE SOFTWARE.
//

#import <XCTest/XCTest.h>
#import "BUYClient+Routing.h"
29
#import "BUYCustomerToken.h"
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45

@interface BUYClient_RoutingTests : XCTestCase

@property (strong, nonatomic) BUYClient *client;

@end

@implementation BUYClient_RoutingTests

#pragma mark - Setup -

- (void)setUp
{
    [super setUp];
	
	self.client = [[BUYClient alloc] initWithShopDomain:@"_DOMAIN_" apiKey:@"_API_KEY_" appId:@"_APP_ID_"];
46
	self.client.customerToken = [[BUYCustomerToken alloc] initWithCustomerID:@1 accessToken:@"token" expiry:[NSDate date]];
47 48 49 50 51 52
}

#pragma mark - Test Routes -

- (void)testRoutes
{
53
	NSString *identifier     = @"1";
54 55 56 57
	NSString *token          = @"_TOKEN_";
	NSDictionary *parameters = @{ @"param" : @"value" };
	
	XCTAssertEqualObjects(
Dima Bart committed
58
						  [self.client urlForAPI].absoluteString,
59 60 61 62
						  @"https://_DOMAIN_/api"
						  );
	
	XCTAssertEqualObjects(
Dima Bart committed
63
						  [self.client urlForApps].absoluteString,
64 65 66 67
						  @"https://_DOMAIN_/api/apps/_APP_ID_"
						  );
	
	XCTAssertEqualObjects(
Dima Bart committed
68
						  [self.client urlForShop].absoluteString,
69 70 71
						  @"https://_DOMAIN_/meta.json"
						  );
	XCTAssertEqualObjects(
Dima Bart committed
72
						  [self.client urlForProductListingsWithParameters:parameters].absoluteString,
73 74 75
						  @"https://_DOMAIN_/api/apps/_APP_ID_/product_listings.json?param=value"
						  );
	XCTAssertEqualObjects(
Dima Bart committed
76
						  [self.client urlForCollectionListingsWithParameters:parameters].absoluteString,
77 78 79 80
						  @"https://_DOMAIN_/api/apps/_APP_ID_/collection_listings.json?param=value"
						  );
	
	XCTAssertEqualObjects(
Dima Bart committed
81
						  [self.client urlForCheckouts].absoluteString,
82 83 84
						  @"https://_DOMAIN_/api/checkouts.json"
						  );
	XCTAssertEqualObjects(
Dima Bart committed
85
						  [self.client urlForCheckoutsWithToken:token].absoluteString,
86 87 88
						  @"https://_DOMAIN_/api/checkouts/_TOKEN_.json"
						  );
	XCTAssertEqualObjects(
Dima Bart committed
89
						  [self.client urlForCheckoutsProcessingWithToken:token].absoluteString,
90 91 92
						  @"https://_DOMAIN_/api/checkouts/_TOKEN_/processing.json"
						  );
	XCTAssertEqualObjects(
Dima Bart committed
93
						  [self.client urlForCheckoutsCompletionWithToken:token].absoluteString,
94 95 96
						  @"https://_DOMAIN_/api/checkouts/_TOKEN_/complete.json"
						  );
	XCTAssertEqualObjects(
Dima Bart committed
97
						  [self.client urlForCheckoutsShippingRatesWithToken:token parameters:parameters].absoluteString,
98 99 100 101
						  @"https://_DOMAIN_/api/checkouts/_TOKEN_/shipping_rates.json?param=value"
						  );
	
	XCTAssertEqualObjects(
Dima Bart committed
102
						  [self.client urlForCheckoutsUsingGiftCard].absoluteString,
103 104 105
						  @"https://_DOMAIN_/api/checkouts/gift_cards.json"
						  );
	XCTAssertEqualObjects(
Dima Bart committed
106
						  [self.client urlForCheckoutsUsingGiftCardWithToken:token].absoluteString,
107 108 109
						  @"https://_DOMAIN_/api/checkouts/_TOKEN_/gift_cards.json"
						  );
	XCTAssertEqualObjects(
Dima Bart committed
110
						  [self.client urlForCheckoutsUsingGiftCard:@999 token:token].absoluteString,
111 112 113 114
						  @"https://_DOMAIN_/api/checkouts/_TOKEN_/gift_cards/999.json"
						  );
	
	XCTAssertEqualObjects(
Dima Bart committed
115
						  [self.client urlForCustomers].absoluteString,
116 117
						  @"https://_DOMAIN_/api/customers.json"
						  );
118 119 120 121 122 123 124 125
	XCTAssertEqualObjects(
						  [self.client urlForCustomersToken].absoluteString,
						  @"https://_DOMAIN_/api/customers/customer_token.json"
						  );
	XCTAssertEqualObjects(
						  [self.client urlForCustomersPasswordRecovery].absoluteString,
						  @"https://_DOMAIN_/api/customers/recover.json"
						  );
126
	XCTAssertEqualObjects(
127 128
						  [self.client urlForCustomersOrders].absoluteString,
						  @"https://_DOMAIN_/api/customers/1/orders.json"
129 130
						  );
	XCTAssertEqualObjects(
131 132
						  [self.client urlForCustomersOrdersWithOrderID:@99].absoluteString,
						  @"https://_DOMAIN_/api/customers/1/orders/99.json"
133
						  );
134
	XCTAssertEqualObjects(
Dima Bart committed
135
						  [self.client urlForCustomersWithID:identifier].absoluteString,
136
						  @"https://_DOMAIN_/api/customers/1.json"
137 138
						  );
	XCTAssertEqualObjects(
Dima Bart committed
139
						  [self.client urlForCustomersActivationWithID:identifier parameters:parameters].absoluteString,
140
						  @"https://_DOMAIN_/api/customers/1/activate.json?param=value"
141
						  );
142
	XCTAssertEqualObjects(
143 144
						  [self.client urlForCustomersTokenRenewal].absoluteString,
						  @"https://_DOMAIN_/api/customers/1/customer_token/renew.json"
145 146
						  );
	XCTAssertEqualObjects(
Dima Bart committed
147
						  [self.client urlForCustomersPasswordResetWithID:identifier parameters:parameters].absoluteString,
148
						  @"https://_DOMAIN_/api/customers/1/reset.json?param=value"
149
						  );
150 151
	
	XCTAssertEqualObjects(
152 153
						  [self.client urlForCustomersAddresses].absoluteString,
						  @"https://_DOMAIN_/api/customers/1/addresses.json"
154 155
						  );
	XCTAssertEqualObjects(
156 157
						  [self.client urlForCustomersAddressWithAddressID:@999].absoluteString,
						  @"https://_DOMAIN_/api/customers/1/addresses/999.json"
158
						  );
159 160 161
}

@end