BUYOptionValueTests.m 2.81 KB
Newer Older
Dima Bart committed
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 29 30 31 32 33
//
//  BUYOptionValueTests.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 "BUYOptionValue.h"

@interface BUYOptionValueTests : XCTestCase

@end

34 35 36 37 38 39 40 41 42 43 44 45
@implementation BUYOptionValueTests {
	BUYModelManager *_modelManager;
}

- (instancetype)initWithInvocation:(NSInvocation *)invocation
{
	self = [super initWithInvocation:invocation];
	if (self) {
		_modelManager = [BUYModelManager modelManager];
	}
	return self;
}
Dima Bart committed
46

Dima Bart committed
47 48
- (void)testInitWithValidData
{
49 50
	NSDictionary *json    = [self jsonWithOptionID:@749];
	BUYOptionValue *value = [self optionValueWithOptionID:@749];
Dima Bart committed
51 52 53 54 55 56 57
	
	XCTAssertNotNil(value);
	XCTAssertEqualObjects(value.name,       json[@"name"]);
	XCTAssertEqualObjects(value.value,      json[@"value"]);
	XCTAssertEqualObjects(value.optionId,   json[@"option_id"]);
}

Dima Bart committed
58 59
- (void)testEqualOptions
{
60 61
	BUYOptionValue *value1 = [self optionValueWithOptionID:@321];
	BUYOptionValue *value2 = [self optionValueWithOptionID:@321];
Dima Bart committed
62 63 64 65 66 67
	
	XCTAssertNotEqual(value1, value2); // Pointer comparison, different objects
	XCTAssertEqualObjects(value1, value2);
	XCTAssertEqual(value1.hash, value2.hash);
}

Dima Bart committed
68 69
- (void)testIdenticalOptions
{
70
	BUYOptionValue *value1 = [self optionValueWithOptionID:@321];
Dima Bart committed
71 72 73 74 75 76 77
	BUYOptionValue *value2 = value1;
	
	XCTAssertEqual(value1, value2);
	XCTAssertTrue([value1 isEqual:value2]);
}

#pragma mark - Convenience -
Dima Bart committed
78

79
- (BUYOptionValue *)optionValueWithOptionID:(NSNumber *)optionID
Dima Bart committed
80
{
81
	return [_modelManager buy_objectWithEntityName:[BUYOptionValue entityName] JSONDictionary:[self jsonWithOptionID:optionID]];
Dima Bart committed
82 83
}

84
- (NSDictionary *)jsonWithOptionID:(NSNumber *)optionID
Dima Bart committed
85
{
Dima Bart committed
86 87 88 89 90 91 92 93
	return @{
			 @"name"      : @"option1",
			 @"value"     : @"value1",
			 @"option_id" : @543,
			 };
}

@end