forked from parse-community/Parse-SDK-iOS-OSX
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPushCommandTests.m
116 lines (94 loc) · 4.74 KB
/
PushCommandTests.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
/**
* 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 "PFMutablePushState.h"
#import "PFMutableQueryState.h"
#import "PFRESTPushCommand.h"
#import "PFTestCase.h"
@interface PushCommandTests : PFTestCase
@end
NS_ASSUME_NONNULL_BEGIN
@implementation PushCommandTests
- (void)testEmptyPushCommand {
PFMutablePushState *state = [[PFMutablePushState alloc] init];
PFRESTPushCommand *command = [PFRESTPushCommand sendPushCommandWithPushState:state sessionToken:@"yarr" error:nil];
XCTAssertNotNil(command);
XCTAssertEqualObjects(command.httpPath, @"push");
XCTAssertEqualObjects(command.httpMethod, PFHTTPRequestMethodPOST);
XCTAssertEqualObjects(command.parameters[@"where"], @{});
XCTAssertEqualObjects(command.sessionToken, @"yarr");
}
- (void)testPushCommandChannels {
PFMutablePushState *state = [[PFMutablePushState alloc] init];
state.channels = [NSSet setWithObject:@"El Capitan!"];
PFRESTPushCommand *command = [PFRESTPushCommand sendPushCommandWithPushState:state sessionToken:@"yarr" error:nil];
XCTAssertNotNil(command);
XCTAssertEqualObjects(command.httpPath, @"push");
XCTAssertEqualObjects(command.httpMethod, PFHTTPRequestMethodPOST);
XCTAssertEqualObjects(command.parameters[@"channels"], @[ @"El Capitan!" ]);
XCTAssertEqualObjects(command.sessionToken, @"yarr");
}
- (void)testPushCommandQuery {
PFMutablePushState *state = [[PFMutablePushState alloc] init];
PFMutableQueryState *queryState = [PFMutableQueryState stateWithParseClassName:@"_Installation"];
[queryState setEqualityConditionWithObject:@"value" forKey:@"key"];
state.queryState = queryState;
PFRESTPushCommand *command = [PFRESTPushCommand sendPushCommandWithPushState:state sessionToken:@"yarr" error:nil];
XCTAssertNotNil(command);
XCTAssertEqualObjects(command.httpPath, @"push");
XCTAssertEqualObjects(command.httpMethod, PFHTTPRequestMethodPOST);
XCTAssertEqualObjects(command.parameters[@"where"], @{ @"key" : @"value" });
XCTAssertEqualObjects(command.sessionToken, @"yarr");
}
- (void)testPushCommandExpirationDate {
PFMutablePushState *state = [[PFMutablePushState alloc] init];
state.expirationDate = [NSDate date];
PFRESTPushCommand *command = [PFRESTPushCommand sendPushCommandWithPushState:state sessionToken:@"yarr" error:nil];
XCTAssertNotNil(command);
XCTAssertEqualObjects(command.httpPath, @"push");
XCTAssertEqualObjects(command.httpMethod, PFHTTPRequestMethodPOST);
XCTAssertNotNil(command.parameters[@"expiration_time"]);
XCTAssertNil(command.parameters[@"expiration_interval"]);
XCTAssertEqualObjects(command.sessionToken, @"yarr");
}
- (void)testPushCommandExpirationTimeInterval {
PFMutablePushState *state = [[PFMutablePushState alloc] init];
state.expirationTimeInterval = @100500;
PFRESTPushCommand *command = [PFRESTPushCommand sendPushCommandWithPushState:state sessionToken:@"yarr" error:nil];
XCTAssertNotNil(command);
XCTAssertEqualObjects(command.httpPath, @"push");
XCTAssertEqualObjects(command.httpMethod, PFHTTPRequestMethodPOST);
XCTAssertNil(command.parameters[@"expiration_time"]);
XCTAssertNotNil(command.parameters[@"expiration_interval"]);
XCTAssertEqualObjects(command.sessionToken, @"yarr");
}
- (void)testPushCommandPushDate {
PFMutablePushState *state = [[PFMutablePushState alloc] init];
state.pushDate = [NSDate dateWithTimeIntervalSinceNow:1.0];
PFRESTPushCommand *command = [PFRESTPushCommand sendPushCommandWithPushState:state sessionToken:@"yarr" error:nil];
XCTAssertNotNil(command);
XCTAssertEqualObjects(command.httpPath, @"push");
XCTAssertEqualObjects(command.httpMethod, PFHTTPRequestMethodPOST);
XCTAssertNil(command.parameters[@"expiration_time"]);
XCTAssertNil(command.parameters[@"expiration_interval"]);
XCTAssertNotNil(command.parameters[@"push_time"]);
XCTAssertEqualObjects(command.sessionToken, @"yarr");
}
- (void)testPushCommandPayload {
PFMutablePushState *state = [[PFMutablePushState alloc] init];
state.payload = @{ @"alert" : @"yolo" };
PFRESTPushCommand *command = [PFRESTPushCommand sendPushCommandWithPushState:state sessionToken:@"yarr" error:nil];
XCTAssertNotNil(command);
XCTAssertEqualObjects(command.httpPath, @"push");
XCTAssertEqualObjects(command.httpMethod, PFHTTPRequestMethodPOST);
XCTAssertEqualObjects(command.parameters[@"data"], state.payload);
XCTAssertEqualObjects(command.sessionToken, @"yarr");
}
@end
NS_ASSUME_NONNULL_END