forked from parse-community/Parse-SDK-iOS-OSX
-
Notifications
You must be signed in to change notification settings - Fork 0
/
FieldOperationDecoderTests.m
161 lines (135 loc) · 7.81 KB
/
FieldOperationDecoderTests.m
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
/**
* Copyright (c) 2015-present, Parse, LLC.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
#import "PFDecoder.h"
#import "PFFieldOperation.h"
#import "PFFieldOperationDecoder.h"
#import "PFObject.h"
#import "PFTestCase.h"
@interface FieldOperationDecoderTests : PFTestCase
@end
@implementation FieldOperationDecoderTests
- (void)testConstructors {
PFFieldOperationDecoder *decoder = [[PFFieldOperationDecoder alloc] init];
XCTAssertNotNil(decoder);
}
- (void)testDefaultDecoder {
XCTAssertNotNil([PFFieldOperationDecoder defaultDecoder]);
XCTAssertEqual([PFFieldOperationDecoder defaultDecoder], [PFFieldOperationDecoder defaultDecoder]);
}
- (void)testDecodingUnknownOperation {
XCTAssertThrows([[PFFieldOperationDecoder defaultDecoder] decode:@{ @"__op" : @"Yarr" }
withDecoder:[PFDecoder objectDecoder]]);
}
- (void)testDecodingIncrementOperations {
PFFieldOperationDecoder *decoder = [[PFFieldOperationDecoder alloc] init];
NSDictionary *dictionary = @{ @"__op" : @"Increment",
@"amount" : @100500 };
PFIncrementOperation *operation = (PFIncrementOperation *)[decoder decode:dictionary
withDecoder:[PFDecoder objectDecoder]];
XCTAssertNotNil(operation);
PFAssertIsKindOfClass(operation, [PFIncrementOperation class]);
XCTAssertEqualObjects(operation.amount, @100500);
}
- (void)testDecodingAddOperations {
PFFieldOperationDecoder *decoder = [[PFFieldOperationDecoder alloc] init];
NSDictionary *dictionary = @{ @"__op" : @"Add",
@"objects" : @[ [PFObject objectWithClassName:@"Yolo"] ] };
PFAddOperation *operation = (PFAddOperation *)[decoder decode:dictionary
withDecoder:[PFDecoder objectDecoder]];
XCTAssertNotNil(operation);
PFAssertIsKindOfClass(operation, [PFAddOperation class]);
XCTAssertEqualObjects([[operation.objects firstObject] parseClassName], @"Yolo");
}
- (void)testDecodingAddUniqueOperations {
PFFieldOperationDecoder *decoder = [[PFFieldOperationDecoder alloc] init];
NSDictionary *dictionary = @{ @"__op" : @"AddUnique",
@"objects" : @[ [PFObject objectWithClassName:@"Yolo"] ] };
PFAddUniqueOperation *operation = (PFAddUniqueOperation *)[decoder decode:dictionary
withDecoder:[PFDecoder objectDecoder]];
XCTAssertNotNil(operation);
PFAssertIsKindOfClass(operation, [PFAddUniqueOperation class]);
XCTAssertEqualObjects([[operation.objects firstObject] parseClassName], @"Yolo");
}
- (void)testDecodingRemoveOperations {
PFFieldOperationDecoder *decoder = [[PFFieldOperationDecoder alloc] init];
NSDictionary *dictionary = @{ @"__op" : @"Remove",
@"objects" : @[ [PFObject objectWithClassName:@"Yolo"] ] };
PFRemoveOperation *operation = (PFRemoveOperation *)[decoder decode:dictionary
withDecoder:[PFDecoder objectDecoder]];
XCTAssertNotNil(operation);
PFAssertIsKindOfClass(operation, [PFRemoveOperation class]);
XCTAssertEqualObjects([[operation.objects firstObject] parseClassName], @"Yolo");
}
- (void)testDecodingDeleteOperations {
PFFieldOperationDecoder *decoder = [[PFFieldOperationDecoder alloc] init];
NSDictionary *dictionary = @{ @"__op" : @"Delete" };
PFDeleteOperation *operation = (PFDeleteOperation *)[decoder decode:dictionary
withDecoder:[PFDecoder objectDecoder]];
XCTAssertNotNil(operation);
PFAssertIsKindOfClass(operation, [PFDeleteOperation class]);
}
- (void)testDecodingBatchOperations {
PFFieldOperationDecoder *decoder = [[PFFieldOperationDecoder alloc] init];
NSDictionary *dictionary = @{ @"__op" : @"Batch",
@"ops" : @[ @{@"__op" : @"AddRelation",
@"objects" : @[ [PFObject objectWithClassName:@"Yolo"] ]},
@{@"__op" : @"RemoveRelation",
@"objects" : @[ [PFObject objectWithClassName:@"Yolo"] ]} ]
};
PFRelationOperation *operation = (PFRelationOperation *)[decoder decode:dictionary
withDecoder:[PFDecoder objectDecoder]];
XCTAssertNotNil(operation);
PFAssertIsKindOfClass(operation, [PFRelationOperation class]);
XCTAssertEqualObjects(operation.targetClass, @"Yolo");
XCTAssertEqualObjects([[operation.relationsToAdd anyObject] parseClassName], @"Yolo");
XCTAssertEqual(operation.relationsToAdd.count, 1);
XCTAssertEqualObjects([[operation.relationsToRemove anyObject] parseClassName], @"Yolo");
XCTAssertEqual(operation.relationsToRemove.count, 1);
}
- (void)testDecodingDecodedBatchOperations {
PFFieldOperationDecoder *decoder = [[PFFieldOperationDecoder alloc] init];
NSDictionary *dictionary = @{ @"__op" : @"Batch",
@"ops" : @[ [PFRelationOperation addRelationToObjects:@[ [PFObject objectWithClassName:@"Yolo"] ]],
[PFRelationOperation removeRelationToObjects:@[ [PFObject objectWithClassName:@"Yolo"] ]] ]
};
PFRelationOperation *operation = (PFRelationOperation *)[decoder decode:dictionary
withDecoder:[PFDecoder objectDecoder]];
XCTAssertNotNil(operation);
PFAssertIsKindOfClass(operation, [PFRelationOperation class]);
XCTAssertEqualObjects(operation.targetClass, @"Yolo");
XCTAssertEqualObjects([[operation.relationsToAdd anyObject] parseClassName], @"Yolo");
XCTAssertEqual(operation.relationsToAdd.count, 1);
XCTAssertEqualObjects([[operation.relationsToRemove anyObject] parseClassName], @"Yolo");
XCTAssertEqual(operation.relationsToRemove.count, 1);
}
- (void)testDecodingAddRelationOperations {
PFFieldOperationDecoder *decoder = [[PFFieldOperationDecoder alloc] init];
NSDictionary *dictionary = @{ @"__op" : @"AddRelation",
@"objects" : @[ [PFObject objectWithClassName:@"Yolo"] ] };
PFRelationOperation *operation = (PFRelationOperation *)[decoder decode:dictionary
withDecoder:[PFDecoder objectDecoder]];
XCTAssertNotNil(operation);
PFAssertIsKindOfClass(operation, [PFRelationOperation class]);
XCTAssertEqualObjects(operation.targetClass, @"Yolo");
XCTAssertEqual(operation.relationsToAdd.count, 1);
XCTAssertEqualObjects([[operation.relationsToAdd anyObject] parseClassName], @"Yolo");
}
- (void)testDecodingRemoveRelationOperations {
PFFieldOperationDecoder *decoder = [[PFFieldOperationDecoder alloc] init];
NSDictionary *dictionary = @{ @"__op" : @"RemoveRelation",
@"objects" : @[ [PFObject objectWithClassName:@"Yolo"] ] };
PFRelationOperation *operation = (PFRelationOperation *)[decoder decode:dictionary
withDecoder:[PFDecoder objectDecoder]];
XCTAssertNotNil(operation);
PFAssertIsKindOfClass(operation, [PFRelationOperation class]);
XCTAssertEqualObjects(operation.targetClass, @"Yolo");
XCTAssertEqual(operation.relationsToRemove.count, 1);
XCTAssertEqualObjects([[operation.relationsToRemove anyObject] parseClassName], @"Yolo");
}
@end