aboutsummaryrefslogtreecommitdiffhomepage
path: root/Example/Messaging
diff options
context:
space:
mode:
authorGravatar Chen Liang <chliang@google.com>2018-03-30 11:41:38 -0700
committerGravatar GitHub <noreply@github.com>2018-03-30 11:41:38 -0700
commit653aea7b50247bb0f6a7e8e1b4ab782553849f74 (patch)
tree0e2b9d8d660aee63a9a4659203e5ca9c1b692c61 /Example/Messaging
parentcdd855423a79ed0191b37b7dcac2df9fb342c9a5 (diff)
Adding a new topic subscription/unsubcription with completion handler method (#1001)
* add new topic subscription/unsubscription method with handler
Diffstat (limited to 'Example/Messaging')
-rw-r--r--Example/Messaging/Tests/FIRMessagingPendingTopicsListTest.m11
-rw-r--r--Example/Messaging/Tests/FIRMessagingRegistrarTest.m41
-rw-r--r--Example/Messaging/Tests/FIRMessagingServiceTest.m37
3 files changed, 39 insertions, 50 deletions
diff --git a/Example/Messaging/Tests/FIRMessagingPendingTopicsListTest.m b/Example/Messaging/Tests/FIRMessagingPendingTopicsListTest.m
index 2033cb4..9c30388 100644
--- a/Example/Messaging/Tests/FIRMessagingPendingTopicsListTest.m
+++ b/Example/Messaging/Tests/FIRMessagingPendingTopicsListTest.m
@@ -164,7 +164,7 @@ typedef void (^MockDelegateSubscriptionHandler)(NSString *topic,
XCTAssertEqual(pendingTopics.numberOfBatches, 1);
[batchSizeReductionExpectation fulfill];
}
- completion(FIRMessagingTopicOperationResultSucceeded, nil);
+ completion(nil);
});
};
@@ -197,7 +197,7 @@ typedef void (^MockDelegateSubscriptionHandler)(NSString *topic,
FIRMessagingTopicOperationCompletion completion) {
// Typically, our callbacks happen asynchronously, but to ensure resilience,
// call back the operation on the same thread it was called in.
- completion(FIRMessagingTopicOperationResultSucceeded, nil);
+ completion(nil);
};
self.alwaysReadyDelegate.updateHandler = ^{
@@ -238,10 +238,9 @@ typedef void (^MockDelegateSubscriptionHandler)(NSString *topic,
// Add a 0.5 second delay to the completion, to give time to add a straggler before the batch
// is completed
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)),
- dispatch_get_main_queue(),
- ^{
- completion(FIRMessagingTopicOperationResultSucceeded, nil);
- });
+ dispatch_get_main_queue(), ^{
+ completion(nil);
+ });
};
// This is a normal topic, which should start fairly soon, but take a while to complete
diff --git a/Example/Messaging/Tests/FIRMessagingRegistrarTest.m b/Example/Messaging/Tests/FIRMessagingRegistrarTest.m
index 863ba4b..f3e66fd 100644
--- a/Example/Messaging/Tests/FIRMessagingRegistrarTest.m
+++ b/Example/Messaging/Tests/FIRMessagingRegistrarTest.m
@@ -70,9 +70,8 @@ static NSString *const kSubscriptionID = @"sample-subscription-id-xyz";
withToken:kFIRMessagingAppIDToken
options:nil
shouldDelete:NO
- handler:
- ^(FIRMessagingTopicOperationResult result, NSError *error) {
- }];
+ handler:^(NSError *error){
+ }];
OCMVerify([self.mockPubsubRegistrar updateSubscriptionToTopic:[OCMArg isEqual:kTopicToSubscribeTo]
withToken:[OCMArg isEqual:kFIRMessagingAppIDToken]
@@ -85,27 +84,23 @@ static NSString *const kSubscriptionID = @"sample-subscription-id-xyz";
[self stubCheckinService];
__block FIRMessagingTopicOperationCompletion pubsubCompletion;
- [[[self.mockPubsubRegistrar stub]
- andDo:^(NSInvocation *invocation) {
- pubsubCompletion(FIRMessagingTopicOperationResultSucceeded, nil);
- }]
- updateSubscriptionToTopic:kTopicToSubscribeTo
- withToken:kFIRMessagingAppIDToken
- options:nil
- shouldDelete:NO
- handler:[OCMArg checkWithBlock:^BOOL(id obj) {
- return (pubsubCompletion = obj) != nil;
- }]];
+ [[[self.mockPubsubRegistrar stub] andDo:^(NSInvocation *invocation) {
+ pubsubCompletion(nil);
+ }] updateSubscriptionToTopic:kTopicToSubscribeTo
+ withToken:kFIRMessagingAppIDToken
+ options:nil
+ shouldDelete:NO
+ handler:[OCMArg checkWithBlock:^BOOL(id obj) {
+ return (pubsubCompletion = obj) != nil;
+ }]];
[self.registrar updateSubscriptionToTopic:kTopicToSubscribeTo
withToken:kFIRMessagingAppIDToken
options:nil
shouldDelete:NO
- handler:
- ^(FIRMessagingTopicOperationResult result, NSError *error) {
- XCTAssertNil(error);
- XCTAssertEqual(result, FIRMessagingTopicOperationResultSucceeded);
- }];
+ handler:^(NSError *error) {
+ XCTAssertNil(error);
+ }];
}
- (void)testFailedUpdateSubscriptionWithNoCheckin {
@@ -116,11 +111,9 @@ static NSString *const kSubscriptionID = @"sample-subscription-id-xyz";
withToken:kFIRMessagingAppIDToken
options:nil
shouldDelete:NO
- handler:
- ^(FIRMessagingTopicOperationResult result, NSError *error) {
- XCTAssertNotNil(error);
- XCTAssertEqual(result, FIRMessagingTopicOperationResultError);
- }];
+ handler:^(NSError *error) {
+ XCTAssertNotNil(error);
+ }];
}
#pragma mark - Private Helpers
diff --git a/Example/Messaging/Tests/FIRMessagingServiceTest.m b/Example/Messaging/Tests/FIRMessagingServiceTest.m
index 0a41314..9afdced 100644
--- a/Example/Messaging/Tests/FIRMessagingServiceTest.m
+++ b/Example/Messaging/Tests/FIRMessagingServiceTest.m
@@ -71,8 +71,8 @@
[service.pubsub subscribeWithToken:token
topic:topic
options:nil
- handler:^(FIRMessagingTopicOperationResult result, NSError *error) {
- // not a nil block
+ handler:^(NSError *error){
+ // not a nil block
}];
// should call updateSubscription
@@ -112,7 +112,7 @@
[messaging.pubsub unsubscribeWithToken:token
topic:topic
options:nil
- handler:^(FIRMessagingTopicOperationResult result, NSError *error){
+ handler:^(NSError *error){
}];
@@ -128,15 +128,14 @@
* Test using PubSub without explicitly starting FIRMessagingService.
*/
- (void)testSubscribeWithoutStart {
- [[[FIRMessaging messaging] pubsub] subscribeWithToken:@"abcdef1234"
- topic:@"/topics/hello-world"
- options:nil
- handler:
- ^(FIRMessagingTopicOperationResult result, NSError *error) {
- XCTAssertNil(error);
- XCTAssertEqual(kFIRMessagingErrorCodePubSubFIRMessagingNotSetup,
- error.code);
- }];
+ [[[FIRMessaging messaging] pubsub]
+ subscribeWithToken:@"abcdef1234"
+ topic:@"/topics/hello-world"
+ options:nil
+ handler:^(NSError *error) {
+ XCTAssertNil(error);
+ XCTAssertEqual(kFIRMessagingErrorCodePubSubFIRMessagingNotSetup, error.code);
+ }];
}
// TODO(chliangGoogle) Investigate why invalid token can't throw assertion but the rest can under
@@ -150,10 +149,9 @@
[messaging.pubsub subscribeWithToken:@"abcdef1234"
topic:nil
options:nil
- handler:
- ^(FIRMessagingTopicOperationResult result, NSError *error) {
- XCTFail(@"Should not invoke the handler");
- }];
+ handler:^(NSError *error) {
+ XCTFail(@"Should not invoke the handler");
+ }];
}
@catch (NSException *exception) {
[exceptionExpectation fulfill];
@@ -174,10 +172,9 @@
[messaging.pubsub unsubscribeWithToken:@"abcdef1234"
topic:nil
options:nil
- handler:
- ^(FIRMessagingTopicOperationResult result, NSError *error) {
- XCTFail(@"Should not invoke the handler");
- }];
+ handler:^(NSError *error) {
+ XCTFail(@"Should not invoke the handler");
+ }];
}
@catch (NSException *exception) {
[exceptionExpectation fulfill];