-
-
Notifications
You must be signed in to change notification settings - Fork 872
/
ObjectBatchCommandTests.m
90 lines (75 loc) · 4.2 KB
/
ObjectBatchCommandTests.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
/**
* 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 "PFHTTPRequest.h"
#import "PFObjectState.h"
#import "PFRESTObjectBatchCommand.h"
#import "PFRESTObjectCommand.h"
#import "PFTestCase.h"
NS_ASSUME_NONNULL_BEGIN
@interface ObjectBatchCommandTests : PFTestCase
@end
@implementation ObjectBatchCommandTests
///--------------------------------------
#pragma mark - Helpers
///--------------------------------------
- (NSArray *)sampleObjectCommands {
NSMutableArray *array = [NSMutableArray arrayWithCapacity:25];
while (array.count < 25) {
PFObjectState *state = [PFObjectState stateWithParseClassName:@"a" objectId:nil isComplete:NO];
PFRESTCommand *createCommand = [PFRESTObjectCommand createObjectCommandForObjectState:state
changes:@{ @"k" : @"v" }
operationSetUUID:nil
sessionToken:nil];
[array addObject:createCommand];
state = [PFObjectState stateWithParseClassName:@"Capitan" objectId:@"yolo" isComplete:NO];
PFRESTCommand *updateCommand = [PFRESTObjectCommand updateObjectCommandForObjectState:state
changes:@{ @"k1" : @"v" }
operationSetUUID:@"asd"
sessionToken:nil];
[array addObject:updateCommand];
state = [PFObjectState stateWithParseClassName:@"Capitan" objectId:@"blah" isComplete:NO];
PFRESTCommand *deleteCommand = [PFRESTObjectCommand deleteObjectCommandForObjectState:state
withSessionToken:nil];
[array addObject:deleteCommand];
}
return array;
}
///--------------------------------------
#pragma mark - Tests
///--------------------------------------
- (void)testBatchCommand {
NSArray *commands = [self sampleObjectCommands];
PFRESTObjectBatchCommand *command = [PFRESTObjectBatchCommand batchCommandWithCommands:commands
sessionToken:@"yolo"
serverURL:[NSURL URLWithString:@"https://api.parse.com/1"]
error:nil];
XCTAssertNotNil(command);
XCTAssertEqualObjects(command.httpPath, @"batch");
XCTAssertEqualObjects(command.httpMethod, PFHTTPRequestMethodPOST);
XCTAssertEqual([command.parameters[@"requests"] count], commands.count);
XCTAssertNotNil([command.parameters[@"requests"] firstObject][@"method"]);
XCTAssertNotNil([command.parameters[@"requests"] firstObject][@"path"]);
XCTAssertEqualObjects([command.parameters[@"requests"] firstObject][@"path"], @"/1/classes/a");
XCTAssertEqualObjects(command.sessionToken, @"yolo");
}
- (void)testBatchCommandValidation {
XCTAssertNotEqual(PFRESTObjectBatchCommandSubcommandsLimit, 0);
NSMutableArray *array = [[self sampleObjectCommands] mutableCopy];
while (array.count < PFRESTObjectBatchCommandSubcommandsLimit) {
[array addObjectsFromArray:[self sampleObjectCommands]];
}
NSError *error;
PFAssertThrowsInvalidArgumentException([PFRESTObjectBatchCommand batchCommandWithCommands:array
sessionToken:@"a"
serverURL:[NSURL URLWithString:@"https://api.parse.com/1"]
error:&error]);
XCTAssertNil(error);
}
@end
NS_ASSUME_NONNULL_END