forked from parse-community/Parse-SDK-iOS-OSX
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PushUnitTests.m
657 lines (490 loc) · 23.1 KB
/
PushUnitTests.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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
/**
* 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 <OCMock/OCMock.H>
@import Bolts.BFTask;
#import "PFCoreManager.h"
#import "PFCurrentInstallationController.h"
#import "PFMacros.h"
#import "PFMutablePushState.h"
#import "PFMutableQueryState.h"
#import "PFPush.h"
#import "PFPushChannelsController.h"
#import "PFPushController.h"
#import "PFPushManager.h"
#import "PFPushPrivate.h"
#import "PFUnitTestCase.h"
#import "Parse_Private.h"
@interface PushUnitTests : PFUnitTestCase
@property (nonatomic, strong) XCTestExpectation *expectationToFulfuill;
@property (nonatomic, copy) void (^validationBlock)(id);
@end
@implementation PushUnitTests
///--------------------------------------
#pragma mark - Helpers
///--------------------------------------
- (PFPushManager *)mockedPushManager {
PFPushManager *mockedManager = PFStrictClassMock([PFPushManager class]);
PFPushController *mockedController = PFStrictClassMock([PFPushController class]);
PFPushChannelsController *mockedChannelsController = PFStrictClassMock([PFPushChannelsController class]);
OCMStub(mockedManager.channelsController).andReturn(mockedChannelsController);
OCMStub(mockedManager.pushController).andReturn(mockedController);
return mockedManager;
}
- (void)validateObjectResults:(id)results error:(NSError *)error {
XCTAssertNil(error);
self.validationBlock(results);
[self.expectationToFulfuill fulfill];
}
///--------------------------------------
#pragma mark - XCTestCase
///--------------------------------------
- (void)setUp {
[super setUp];
[Parse _currentManager].pushManager = [self mockedPushManager];
}
///--------------------------------------
#pragma mark - Tests
///--------------------------------------
- (void)testConstructors {
PFPush *push = [PFPush push];
XCTAssertNotNil(push);
push = [[PFPush alloc] init];
XCTAssertNotNil(push);
}
- (void)testCopy {
PFPush *push = [PFPush push];
PFPush *copied = [push copy];
XCTAssertNotEqual(push, copied);
}
#pragma mark NSObject
- (void)testEqualityAndHash {
PFPush *pushA = [[PFPush alloc] init];
PFPush *pushB = [[PFPush alloc] init];
XCTAssertTrue([pushA isEqual:pushB]);
XCTAssertEqual([pushA hash], [pushB hash]);
PFQuery *query = [PFQuery queryWithClassName:@"aClass"];
[pushA setQuery:query];
XCTAssertFalse([pushA isEqual:pushB]);
[pushB setQuery:query];
XCTAssertTrue([pushA isEqual:pushB]);
XCTAssertEqual([pushA hash], [pushB hash]);
pushA = [[PFPush alloc] init];
pushB = [[PFPush alloc] init];
NSString *channelName = @"channel";
[pushA setChannel:channelName];
XCTAssertFalse([pushA isEqual:pushB]);
[pushB setChannel:channelName];
XCTAssertTrue([pushA isEqual:pushB]);
XCTAssertEqual([pushA hash], [pushB hash]);
NSString *message = @"Hello, World!";
[pushA setMessage:message];
XCTAssertFalse([pushA isEqual:pushB]);
[pushB setMessage:message];
XCTAssertTrue([pushA isEqual:pushB]);
XCTAssertEqual([pushA hash], [pushB hash]);
NSDate *date = [NSDate date];
[pushA expireAtDate:date];
XCTAssertFalse([pushA isEqual:pushB]);
[pushB expireAtDate:date];
XCTAssertTrue([pushA isEqual:pushB]);
XCTAssertEqual([pushA hash], [pushB hash]);
NSTimeInterval interval = 60;
[pushA expireAfterTimeInterval:interval];
XCTAssertFalse([pushA isEqual:pushB]);
[pushB expireAfterTimeInterval:interval];
XCTAssertTrue([pushA isEqual:pushB]);
XCTAssertEqual([pushA hash], [pushB hash]);
NSDictionary *payload = @{ @"foo" : @"bar" };
[pushA setData:payload];
XCTAssertFalse([pushA isEqual:pushB]);
[pushB setData:payload];
XCTAssertTrue([pushA isEqual:pushB]);
XCTAssertEqual([pushA hash], [pushB hash]);
}
- (void)testHash {
PFPush *pushA = [[PFPush alloc] init];
PFPush *pushB = [[PFPush alloc] init];
XCTAssertEqual([pushA hash], [pushB hash]);
PFQuery *query = [PFQuery queryWithClassName:@"aClass"];
[pushA setQuery:query];
[pushB setQuery:query];
XCTAssertEqual([pushA hash], [pushB hash]);
pushA = [[PFPush alloc] init];
pushB = [[PFPush alloc] init];
NSString *channelName = @"channel";
[pushA setChannel:channelName];
[pushB setChannel:channelName];
XCTAssertEqual([pushA hash], [pushB hash]);
NSString *message = @"Hello, World!";
[pushA setMessage:message];
[pushB setMessage:message];
XCTAssertEqual([pushA hash], [pushB hash]);
NSDate *date = [NSDate date];
[pushA expireAtDate:date];
[pushB expireAtDate:date];
XCTAssertEqual([pushA hash], [pushB hash]);
NSTimeInterval interval = 60;
[pushA expireAfterTimeInterval:interval];
[pushB expireAfterTimeInterval:interval];
XCTAssertEqual([pushA hash], [pushB hash]);
NSDictionary *payload = @{ @"foo" : @"bar" };
[pushA setData:payload];
[pushB setData:payload];
XCTAssertEqual([pushA hash], [pushB hash]);
}
- (void)testSendPush {
NSString *channelName = @"channel";
NSString *message = @"Hello, World!";
PFPushController *mockedPushController = [Parse _currentManager].pushManager.pushController;
PFPush *thePush = [PFPush push];
PFMutablePushState *expectedPushState = [[PFMutablePushState alloc] init];
[thePush setMessage:message];
[expectedPushState setPayloadWithMessage:message];
BFTask *mockedResult = [BFTask taskWithResult:@YES];
OCMStub([mockedPushController sendPushNotificationAsyncWithState:[OCMArg isEqual:expectedPushState]
sessionToken:nil]).andReturn(mockedResult);
XCTAssertTrue([thePush sendPush:NULL]);
[thePush setChannel:channelName];
[expectedPushState setChannels:PF_SET(channelName)];
XCTAssertTrue([thePush sendPush:NULL]);
[thePush setChannels:@[ channelName ]];
XCTAssertTrue([thePush sendPush:NULL]);
PFQuery *query = [PFQuery queryWithClassName:@"aClass"];
PFQueryState *queryState = [[PFMutableQueryState alloc] initWithParseClassName:@"aClass"];
thePush = [PFPush push];
[thePush setMessage:message];
[thePush setQuery:query];
[expectedPushState setChannels:nil];
[expectedPushState setQueryState:queryState];
XCTAssertTrue([thePush sendPush:NULL]);
NSDate *expiryDate = [NSDate dateWithTimeIntervalSinceNow:60 * 10];
[thePush expireAtDate:expiryDate];
[expectedPushState setExpirationDate:expiryDate];
XCTAssertTrue([thePush sendPush:NULL]);
[thePush expireAfterTimeInterval:60 * 10];
[expectedPushState setExpirationDate:nil];
[expectedPushState setExpirationTimeInterval:@(60 * 10)];
XCTAssertTrue([thePush sendPush:NULL]);
[thePush clearExpiration];
[expectedPushState setExpirationTimeInterval:nil];
XCTAssertTrue([thePush sendPush:NULL]);
XCTestExpectation *backgroundBlockExpectation = [self expectationWithDescription:@"backgroundBlock"];
XCTestExpectation *backgroundTargetSelectorExpectation = [self expectationWithDescription:@"backgroundTargetSel"];
[[[thePush sendPushInBackground] continueWithBlock:^id(BFTask *task) {
XCTAssertFalse(task.faulted);
XCTAssertTrue([task.result boolValue]);
return task;
}] waitUntilFinished];
[thePush sendPushInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
XCTAssertTrue(succeeded);
XCTAssertNil(error);
[backgroundBlockExpectation fulfill];
}];
@weakify(self);
self.validationBlock = ^(id success) {
@strongify(self);
XCTAssertTrue([success boolValue]);
};
self.expectationToFulfuill = backgroundTargetSelectorExpectation;
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
[thePush sendPushInBackgroundWithTarget:self selector:@selector(validateObjectResults:error:)];
#pragma clang diagnostic pop
[self waitForTestExpectations];
}
- (void)testStaticChannelPush {
NSString *channelName = @"channel";
NSString *message = @"Hello, World!";
PFPushController *mockedPushController = [Parse _currentManager].pushManager.pushController;
PFMutablePushState *expectedPushState = [[PFMutablePushState alloc] init];
[expectedPushState setPayloadWithMessage:message];
[expectedPushState setChannels:PF_SET(channelName)];
BFTask *mockedResult = [BFTask taskWithResult:@YES];
OCMStub([mockedPushController sendPushNotificationAsyncWithState:expectedPushState
sessionToken:nil]).andReturn(mockedResult);
XCTestExpectation *toChannelBlockExpectation = [self expectationWithDescription:@"toChannelBlock"];
XCTestExpectation *toChannelTargetSelectorExpectation = [self expectationWithDescription:@"toChannelTargetSel"];
[PFPush sendPushMessageToChannel:channelName withMessage:message error:NULL];
[[[PFPush sendPushMessageToChannelInBackground:channelName
withMessage:message] continueWithBlock:^id(BFTask *task) {
XCTAssertFalse(task.faulted);
XCTAssertTrue([task.result boolValue]);
return task;
}] waitUntilFinished];
[PFPush sendPushMessageToChannelInBackground:channelName
withMessage:message
block:^(BOOL succeeded, NSError *error) {
XCTAssertTrue(succeeded);
XCTAssertNil(error);
[toChannelBlockExpectation fulfill];
}];
@weakify(self);
self.validationBlock = ^(id success) {
@strongify(self);
XCTAssertTrue([success boolValue]);
};
self.expectationToFulfuill = toChannelTargetSelectorExpectation;
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
[PFPush sendPushMessageToChannelInBackground:channelName
withMessage:message
target:self
selector:@selector(validateObjectResults:error:)];
#pragma clang diagnostic pop
[self waitForTestExpectations];
}
- (void)testStaticChannelPushData {
NSString *channelName = @"channel";
NSDictionary *payload = @{ @"alert" : @"MyMessage",
@"customKey" : @"customValue" };
PFPushController *mockedPushController = [Parse _currentManager].pushManager.pushController;
PFMutablePushState *expectedPushState = [[PFMutablePushState alloc] init];
[expectedPushState setChannels:PF_SET(channelName)];
[expectedPushState setPayload:payload];
BFTask *mockedResult = [BFTask taskWithResult:@YES];
OCMStub([mockedPushController sendPushNotificationAsyncWithState:expectedPushState
sessionToken:nil]).andReturn(mockedResult);
XCTestExpectation *toChannelBlockExpectation = [self expectationWithDescription:@"toChannelBlock"];
XCTestExpectation *toChannelTargetSelectorExpectation = [self expectationWithDescription:@"toChannelTargetSel"];
[PFPush sendPushDataToChannel:channelName withData:payload error:NULL];
[PFPush sendPushDataToChannelInBackground:channelName withData:payload block:^(BOOL succeeded, NSError *error) {
XCTAssertTrue(succeeded);
XCTAssertNil(error);
[toChannelBlockExpectation fulfill];
}];
@weakify(self);
self.validationBlock = ^(id success) {
@strongify(self);
XCTAssertTrue([success boolValue]);
};
self.expectationToFulfuill = toChannelTargetSelectorExpectation;
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
[PFPush sendPushDataToChannelInBackground:channelName
withData:payload
target:self
selector:@selector(validateObjectResults:error:)];
#pragma clang diagnostic pop
[self waitForTestExpectations];
}
- (void)testStaticQueryPush {
PFQuery *query = [PFQuery queryWithClassName:@"SomeClass"];
NSString *message = @"Hello, World!";
PFPushController *mockedPushController = [Parse _currentManager].pushManager.pushController;
PFMutablePushState *expectedPushState = [[PFMutablePushState alloc] init];
[expectedPushState setPayloadWithMessage:message];
[expectedPushState setQueryState:[[PFMutableQueryState alloc] initWithParseClassName:@"SomeClass"]];
BFTask *mockedResult = [BFTask taskWithResult:@YES];
OCMStub([mockedPushController sendPushNotificationAsyncWithState:expectedPushState
sessionToken:nil]).andReturn(mockedResult);
XCTestExpectation *toQueryBlockExpectation = [self expectationWithDescription:@"toQueryBlock"];
[PFPush sendPushMessageToQuery:query withMessage:message error:NULL];
[[[PFPush sendPushMessageToQueryInBackground:query
withMessage:message] continueWithBlock:^id(BFTask *task) {
XCTAssertFalse(task.faulted);
XCTAssertTrue([task.result boolValue]);
return task;
}] waitUntilFinished];
[PFPush sendPushMessageToQueryInBackground:query
withMessage:message
block:^(BOOL succeeded, NSError *error) {
XCTAssertTrue(succeeded);
XCTAssertNil(error);
[toQueryBlockExpectation fulfill];
}];
[self waitForTestExpectations];
}
- (void)testStaticQueryPushData {
PFQuery *query = [PFQuery queryWithClassName:@"SomeClass"];
NSDictionary *payload = @{ @"alert" : @"MyMessage",
@"customKey" : @"customValue" };
PFPushController *mockedPushController = [Parse _currentManager].pushManager.pushController;
PFMutablePushState *expectedPushState = [[PFMutablePushState alloc] init];
[expectedPushState setPayload:payload];
[expectedPushState setQueryState:[[PFMutableQueryState alloc] initWithParseClassName:@"SomeClass"]];
BFTask *mockedResult = [BFTask taskWithResult:@YES];
OCMStub([mockedPushController sendPushNotificationAsyncWithState:expectedPushState
sessionToken:nil]).andReturn(mockedResult);
XCTestExpectation *toQueryBlockExpectation = [self expectationWithDescription:@"toQueryBlock"];
[PFPush sendPushDataToQuery:query withData:payload error:NULL];
[[[PFPush sendPushDataToQueryInBackground:query withData:payload] continueWithBlock:^id(BFTask *task) {
XCTAssertFalse(task.faulted);
XCTAssertTrue([task.result boolValue]);
return task;
}] waitUntilFinished];
[PFPush sendPushDataToQueryInBackground:query
withData:payload
block:^(BOOL succeeded, NSError *error) {
XCTAssertTrue(succeeded);
XCTAssertNil(error);
[toQueryBlockExpectation fulfill];
}];
[self waitForTestExpectations];
}
- (void)testGetSubscribedChannels {
NSString *channel = @"channel";
NSSet *channelsSet = PF_SET(channel);
PFPushChannelsController *mockedChannelsController = [Parse _currentManager].pushManager.channelsController;
BFTask *mockedResult = [BFTask taskWithResult:channelsSet];
OCMStub([mockedChannelsController getSubscribedChannelsAsync]).andReturn(mockedResult);
XCTestExpectation *subscribeBlockExpectation = [self expectationWithDescription:@"subscribeBlock"];
XCTestExpectation *subscribeTargetSelectorExpectation = [self expectationWithDescription:@"subscribeTargetSel"];
XCTAssertEqualObjects(channelsSet, [PFPush getSubscribedChannels:NULL]);
[[[PFPush getSubscribedChannelsInBackground] continueWithBlock:^id(BFTask *task) {
XCTAssertEqualObjects(channelsSet, task.result);
return task;
}] waitUntilFinished];
[PFPush getSubscribedChannelsInBackgroundWithBlock:^(NSSet *channels, NSError *error) {
XCTAssertEqualObjects(channelsSet, channels);
[subscribeBlockExpectation fulfill];
}];
@weakify(self);
self.validationBlock = ^(id result) {
@strongify(self);
XCTAssertEqualObjects(channelsSet, result);
};
self.expectationToFulfuill = subscribeTargetSelectorExpectation;
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
[PFPush getSubscribedChannelsInBackgroundWithTarget:self selector:@selector(validateObjectResults:error:)];
#pragma clang diagnostic pop
[self waitForTestExpectations];
}
- (void)testSubscribeToChannels {
NSString *channel = @"channel";
PFPushChannelsController *mockedChannelsController = [Parse _currentManager].pushManager.channelsController;
BFTask *mockedResult = [BFTask taskWithResult:@YES];
OCMStub([mockedChannelsController subscribeToChannelAsyncWithName:channel]).andReturn(mockedResult);
XCTestExpectation *subscribeBlockExpectation = [self expectationWithDescription:@"subscribeBlock"];
XCTestExpectation *subscribeTargetSelectorExpectation = [self expectationWithDescription:@"subscribeTargetSel"];
[PFPush subscribeToChannel:channel error:NULL];
[[[PFPush subscribeToChannelInBackground:channel] continueWithBlock:^id(BFTask *task) {
XCTAssertFalse(task.faulted);
XCTAssertTrue([task.result boolValue]);
return task;
}] waitUntilFinished];
[PFPush subscribeToChannelInBackground:channel block:^(BOOL succeeded, NSError *_Nullable error) {
XCTAssertTrue(succeeded);
XCTAssertNil(error);
[subscribeBlockExpectation fulfill];
}];
@weakify(self);
self.validationBlock = ^(id success) {
@strongify(self);
XCTAssertTrue([success boolValue]);
};
self.expectationToFulfuill = subscribeTargetSelectorExpectation;
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
[PFPush subscribeToChannelInBackground:channel
target:self
selector:@selector(validateObjectResults:error:)];
#pragma clang diagnostic pop
[self waitForTestExpectations];
}
- (void)testUnsubscribeFromChannels {
NSString *channel = @"channel";
PFPushChannelsController *mockedChannelsController = [Parse _currentManager].pushManager.channelsController;
BFTask *mockedResult = [BFTask taskWithResult:@YES];
OCMStub([mockedChannelsController unsubscribeFromChannelAsyncWithName:channel]).andReturn(mockedResult);
XCTestExpectation *unsubscribeBlockExpectation = [self expectationWithDescription:@"unsubscribeBlock"];
XCTestExpectation *unsubscribeTargetSelectorExpectation = [self expectationWithDescription:@"unsubscribeTargetSel"];
[PFPush unsubscribeFromChannel:channel error:NULL];
[[[PFPush unsubscribeFromChannelInBackground:channel] continueWithBlock:^id(BFTask *task) {
XCTAssertFalse(task.faulted);
XCTAssertTrue([task.result boolValue]);
return task;
}] waitUntilFinished];
[PFPush unsubscribeFromChannelInBackground:channel block:^(BOOL succeeded, NSError *_Nullable error) {
XCTAssertTrue(succeeded);
XCTAssertNil(error);
[unsubscribeBlockExpectation fulfill];
}];
@weakify(self);
self.validationBlock = ^(id success) {
@strongify(self);
XCTAssertTrue([success boolValue]);
};
self.expectationToFulfuill = unsubscribeTargetSelectorExpectation;
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
[PFPush unsubscribeFromChannelInBackground:channel
target:self
selector:@selector(validateObjectResults:error:)];
#pragma clang diagnostic pop
[self waitForTestExpectations];
}
- (void)testDeviceToken {
PFInstallation *installation = [[PFInstallation alloc] init];
BFTask *installationTask = [BFTask taskWithResult:installation];
PFCurrentInstallationController *mockedInstallationController = PFStrictClassMock([PFCurrentInstallationController class]);
OCMStub([mockedInstallationController getCurrentObjectAsync]).andReturn(installationTask);
[Parse _currentManager].coreManager.currentInstallationController = mockedInstallationController;
XCTAssertNil(installation.deviceToken);
[PFPush storeDeviceToken:@"token"];
XCTAssertEqualObjects(installation.deviceToken, @"token");
[[PFPush pushInternalUtilClass] clearDeviceToken];
XCTAssertNil(installation.deviceToken);
NSData *dataToken = [NSData dataWithBytes:(const char[]) { 0xFF, 0x7F, 0x00 } length:3];
NSString *expectedString = @"ff7f00";
[PFPush storeDeviceToken:dataToken];
XCTAssertEqualObjects(installation.deviceToken, expectedString);
[[PFPush pushInternalUtilClass] clearDeviceToken];
XCTAssertNil(installation.deviceToken);
}
- (void)testDeprecatedMethods {
PFPush *push = [PFPush push];
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
[push setPushToIOS:YES];
[push setPushToAndroid:YES];
#pragma clang diagnostic pop
}
- (void)testSetQueryAndChannelFails {
PFQuery *query = [PFInstallation query];
NSArray *channels = @[ @"foo", @"bar" ];
PFPush *push = [[PFPush alloc] init];
[push setQuery:query];
PFAssertThrowsInvalidArgumentException([push setChannel:@"foo"]);
push = [[PFPush alloc] init];
[push setQuery:query];
PFAssertThrowsInvalidArgumentException([push setChannels:channels]);
push = [[PFPush alloc] init];
[push setChannels:channels];
PFAssertThrowsInvalidArgumentException([push setQuery:query]);
push = [[PFPush alloc] init];
[push setChannel:@"foo"];
PFAssertThrowsInvalidArgumentException([push setQuery:query]);
}
- (void)testPushWithLimitQueryFails {
PFQuery *query = [PFInstallation query];
query.limit = 10;
PFPush *push = [[PFPush alloc] init];
[push setQuery:query];
[push setMessage:@"hello this is a test"];
PFAssertThrowsInvalidArgumentException([push sendPush:nil]);
}
- (void)testPushWithOrderQueryFails {
PFQuery *query = [PFInstallation query];
[query orderByAscending:@"deviceToken"];
PFPush *push = [[PFPush alloc] init];
[push setQuery:query];
[push setMessage:@"hello this is a test"];
PFAssertThrowsInvalidArgumentException([push sendPush:nil]);
}
- (void)testPushWithSkipQueryFails {
PFQuery *query = [PFInstallation query];
[query whereKey:@"deviceType" equalTo:@"ios"];
query.skip = 10;
PFPush *push = [[PFPush alloc] init];
[push setQuery:query];
[push setMessage:@"hello this is a test"];
PFAssertThrowsInvalidArgumentException([push sendPush:nil]);
}
@end