diff --git a/PubNub/Network/Responses/Subscribe/PNSubscribeCursorData.m b/PubNub/Network/Responses/Subscribe/PNSubscribeCursorData.m index 6a6024068..8d0ca5535 100644 --- a/PubNub/Network/Responses/Subscribe/PNSubscribeCursorData.m +++ b/PubNub/Network/Responses/Subscribe/PNSubscribeCursorData.m @@ -32,6 +32,10 @@ @implementation PNSubscribeCursorData }; } ++ (NSArray *)optionalKeys { + return @[@"region"]; +} + #pragma mark - diff --git a/PubNub/Network/Responses/Subscribe/PNSubscribeEventData.m b/PubNub/Network/Responses/Subscribe/PNSubscribeEventData.m index 88aed2be1..989e228b6 100644 --- a/PubNub/Network/Responses/Subscribe/PNSubscribeEventData.m +++ b/PubNub/Network/Responses/Subscribe/PNSubscribeEventData.m @@ -65,7 +65,7 @@ @implementation PNSubscribeEventData } + (NSArray *)ignoredKeys { - return @[@"timetoken"]; + return @[@"timetoken", @"region"]; } - (NSString *)subscription { diff --git a/Tests/Support Files/Fixtures/PNSubscribeIntegrationTest.bundle/ItShouldSubscribeToSingleChannelAndReceiveMessageWithUserTimetokenWhenPublished.json b/Tests/Support Files/Fixtures/PNSubscribeIntegrationTest.bundle/ItShouldSubscribeToSingleChannelAndReceiveMessageWithUserTimetokenWhenPublished.json new file mode 100644 index 000000000..c3509bdfd --- /dev/null +++ b/Tests/Support Files/Fixtures/PNSubscribeIntegrationTest.bundle/ItShouldSubscribeToSingleChannelAndReceiveMessageWithUserTimetokenWhenPublished.json @@ -0,0 +1,244 @@ +[ + { + "id" : "6D9CF0BE-C72E-451C-BD56-ADC3759E4917", + "data" : { + "method" : "get", + "cls" : "NSURLRequest", + "cellular" : true, + "cache" : 1, + "timeout" : 60, + "cookies" : true, + "headers" : { + "User-Agent" : "iPhone; CPU iPhone OS 12.4.0 Version", + "Accept" : "*\/*", + "Connection" : "keep-alive", + "Accept-Encoding" : "gzip,deflate" + }, + "pipeline" : false, + "network" : 0, + "url" : "https:\/\/ps.pndsn.com\/v2\/subscribe\/demo\/test-channel1\/0?pnsdk=PubNub-ObjC-iOS\/4.x.x&uuid=Serhii&tt=0&heartbeat=20" + }, + "type" : 0 + }, + { + "id" : "6D9CF0BE-C72E-451C-BD56-ADC3759E4917", + "data" : { + "status" : 200, + "cls" : "NSHTTPURLResponse", + "url" : "https:\/\/ps.pndsn.com\/v2\/subscribe\/demo\/test-channel1\/0?pnsdk=PubNub-ObjC-iOS\/4.x.x&uuid=Serhii&tt=0&heartbeat=20", + "headers" : { + "Access-Control-Allow-Methods" : "GET", + "Content-Type" : "text\/javascript; charset=\"UTF-8\"", + "Access-Control-Allow-Origin" : "*", + "Date" : "Tue, 04 Feb 2020 13:10:11 GMT", + "Content-Length" : "45", + "Cache-Control" : "no-cache", + "Connection" : "keep-alive" + } + }, + "type" : 1 + }, + { + "id" : "6D9CF0BE-C72E-451C-BD56-ADC3759E4917", + "data" : { + "cls" : "NSData", + "base64" : "eyJ0Ijp7InQiOiIxNTgwODIxODExNDczMDU1OSIsInIiOjEyfSwibSI6W119" + }, + "type" : 2 + }, + { + "id" : "6D9CF0BE-C72E-451C-BD56-ADC3759E4917", + "type" : 4 + }, + { + "id" : "56380FEF-3510-4D26-8D88-22A028B35217", + "data" : { + "method" : "get", + "cls" : "NSURLRequest", + "cellular" : true, + "cache" : 1, + "timeout" : 60, + "cookies" : true, + "headers" : { + "User-Agent" : "iPhone; CPU iPhone OS 12.4.0 Version", + "Accept" : "*\/*", + "Connection" : "keep-alive", + "Accept-Encoding" : "gzip,deflate" + }, + "pipeline" : false, + "network" : 0, + "url" : "https:\/\/ps.pndsn.com\/v2\/subscribe\/demo\/test-channel1\/0?uuid=Serhii&pnsdk=PubNub-ObjC-iOS\/4.x.x&tt=15808218114730559&heartbeat=20&tr=12" + }, + "type" : 0 + }, + { + "id" : "9060F768-F824-4970-93AC-4BF1FA1121D5", + "data" : { + "method" : "get", + "cls" : "NSURLRequest", + "cellular" : true, + "cache" : 1, + "timeout" : 60, + "cookies" : true, + "headers" : { + "User-Agent" : "iPhone; CPU iPhone OS 12.4.0 Version", + "Accept" : "*\/*", + "Connection" : "keep-alive", + "Accept-Encoding" : "gzip,deflate" + }, + "pipeline" : false, + "network" : 0, + "url" : "https:\/\/ps.pndsn.com\/publish\/demo\/demo\/0\/test-channel1\/0\/%7B%22test-message%22:%5B%22message%22%5D%7D?uuid=Serhii&pnsdk=PubNub-ObjC-iOS\/4.x.x&seqn=1" + }, + "type" : 0 + }, + { + "id" : "9060F768-F824-4970-93AC-4BF1FA1121D5", + "data" : { + "status" : 200, + "cls" : "NSHTTPURLResponse", + "url" : "https:\/\/ps.pndsn.com\/publish\/demo\/demo\/0\/test-channel1\/0\/%7B%22test-message%22:%5B%22message%22%5D%7D?pnsdk=PubNub-ObjC-iOS\/4.x.x&seqn=1&uuid=Serhii", + "headers" : { + "Access-Control-Allow-Methods" : "GET", + "Content-Type" : "text\/javascript; charset=\"UTF-8\"", + "Access-Control-Allow-Origin" : "*", + "Date" : "Tue, 04 Feb 2020 13:10:14 GMT", + "Content-Length" : "30", + "Cache-Control" : "no-cache", + "Connection" : "keep-alive" + } + }, + "type" : 1 + }, + { + "id" : "9060F768-F824-4970-93AC-4BF1FA1121D5", + "data" : { + "cls" : "NSData", + "base64" : "WzEsIlNlbnQiLCIxNTgwODIxODE0ODc5NTIwMCJd" + }, + "type" : 2 + }, + { + "id" : "9060F768-F824-4970-93AC-4BF1FA1121D5", + "type" : 4 + }, + { + "id" : "56380FEF-3510-4D26-8D88-22A028B35217", + "data" : { + "status" : 200, + "cls" : "NSHTTPURLResponse", + "url" : "https:\/\/ps.pndsn.com\/v2\/subscribe\/demo\/test-channel1\/0?uuid=Serhii&pnsdk=PubNub-ObjC-iOS\/4.x.x&tt=15808218114730559&heartbeat=20&tr=12", + "headers" : { + "Access-Control-Allow-Methods" : "GET", + "Content-Type" : "text\/javascript; charset=\"UTF-8\"", + "Access-Control-Allow-Origin" : "*", + "Date" : "Tue, 04 Feb 2020 13:10:14 GMT", + "Content-Length" : "291", + "Cache-Control" : "no-cache", + "Connection" : "keep-alive" + } + }, + "type" : 1 + }, + { + "id" : "56380FEF-3510-4D26-8D88-22A028B35217", + "data" : { + "cls" : "NSData", + "base64" : "eyJ0Ijp7InQiOiIxNTgwODIxODE0ODgwNDc4NyIsInIiOjEyfSwibSI6W3siYSI6IjUiLCJmIjowLCJpIjoiU2VyaGlpIiwicyI6MTAsInAiOnsidCI6IjE1ODA4MjE4MTQ4Nzk1MjAwIiwiciI6MTJ9LCJvIjp7InQiOiIxNTgwODIxODE0ODc5NTE5OSJ9LCJrIjoiZGVtbyIsImMiOiJ0ZXN0LWNoYW5uZWwxIiwiZCI6eyJ0ZXN0LW1lc3NhZ2UiOlsibWVzc2FnZSJdfX1dfQ==" + }, + "type" : 2 + }, + { + "id" : "56380FEF-3510-4D26-8D88-22A028B35217", + "type" : 4 + }, + { + "id" : "8166D76F-F897-4ABB-934A-13726D856948", + "data" : { + "method" : "get", + "cls" : "NSURLRequest", + "cellular" : true, + "cache" : 1, + "timeout" : 60, + "cookies" : true, + "headers" : { + "User-Agent" : "iPhone; CPU iPhone OS 12.4.0 Version", + "Accept" : "*\/*", + "Connection" : "keep-alive", + "Accept-Encoding" : "gzip,deflate" + }, + "pipeline" : false, + "network" : 0, + "url" : "https:\/\/ps.pndsn.com\/v2\/subscribe\/demo\/test-channel1\/0?uuid=Serhii&pnsdk=PubNub-ObjC-iOS\/4.x.x&tt=15808218148804787&heartbeat=20&tr=12" + }, + "type" : 0 + }, + { + "id" : "8166D76F-F897-4ABB-934A-13726D856948", + "data" : { + "code" : -999, + "info" : { + "NSErrorFailingURLStringKey" : "https:\/\/ps.pndsn.com\/v2\/subscribe\/demo\/test-channel1\/0?uuid=Serhii&pnsdk=PubNub-ObjC-iOS\/4.x.x&tt=15808218148804787&heartbeat=20&tr=12", + "NSLocalizedDescription" : "cancelled", + "NSErrorFailingURLKey" : "https:\/\/ps.pndsn.com\/v2\/subscribe\/demo\/test-channel1\/0?uuid=Serhii&pnsdk=PubNub-ObjC-iOS\/4.x.x&tt=15808218148804787&heartbeat=20&tr=12" + }, + "cls" : "NSError", + "domain" : "NSURLErrorDomain" + }, + "type" : 3 + }, + { + "id" : "1966F67F-1E40-41C0-B669-9A9607D9514C", + "data" : { + "method" : "get", + "cls" : "NSURLRequest", + "cellular" : true, + "cache" : 1, + "timeout" : 60, + "cookies" : true, + "headers" : { + "User-Agent" : "iPhone; CPU iPhone OS 12.4.0 Version", + "Accept" : "*\/*", + "Connection" : "keep-alive", + "Accept-Encoding" : "gzip,deflate" + }, + "pipeline" : false, + "network" : 0, + "url" : "https:\/\/ps.pndsn.com\/v2\/presence\/sub_key\/demo\/channel\/test-channel1\/leave?uuid=Serhii&pnsdk=PubNub-ObjC-iOS\/4.x.x" + }, + "type" : 0 + }, + { + "id" : "1966F67F-1E40-41C0-B669-9A9607D9514C", + "data" : { + "status" : 200, + "cls" : "NSHTTPURLResponse", + "url" : "https:\/\/ps.pndsn.com\/v2\/presence\/sub_key\/demo\/channel\/test-channel1\/leave?uuid=Serhii&pnsdk=PubNub-ObjC-iOS\/4.x.x", + "headers" : { + "Access-Control-Allow-Methods" : "OPTIONS, GET, POST", + "Content-Type" : "text\/javascript; charset=\"UTF-8\"", + "Server" : "Pubnub Presence", + "Access-Control-Allow-Origin" : "*", + "Age" : "0", + "Date" : "Tue, 04 Feb 2020 13:10:15 GMT", + "Accept-Ranges" : "bytes", + "Content-Length" : "74", + "Cache-Control" : "no-cache", + "Connection" : "keep-alive" + } + }, + "type" : 1 + }, + { + "id" : "1966F67F-1E40-41C0-B669-9A9607D9514C", + "data" : { + "cls" : "NSData", + "base64" : "eyJzdGF0dXMiOiAyMDAsICJtZXNzYWdlIjogIk9LIiwgImFjdGlvbiI6ICJsZWF2ZSIsICJzZXJ2aWNlIjogIlByZXNlbmNlIn0=" + }, + "type" : 2 + }, + { + "id" : "1966F67F-1E40-41C0-B669-9A9607D9514C", + "type" : 4 + } +] diff --git a/Tests/Tests/Integration/PNSubscribeIntegrationTest.m b/Tests/Tests/Integration/PNSubscribeIntegrationTest.m index 2c0d8f39a..a32b452b8 100644 --- a/Tests/Tests/Integration/PNSubscribeIntegrationTest.m +++ b/Tests/Tests/Integration/PNSubscribeIntegrationTest.m @@ -3,6 +3,7 @@ * @copyright © 2010-2020 PubNub, Inc. */ #import "PNRecordableTestCase.h" +#import "PNSubscribeEventData+Private.h" #import "NSString+PNTest.h" @@ -1387,6 +1388,39 @@ - (void)testItShouldSubscribeToSingleChannelAndReceiveMessageWhenPublished { }]; } +- (void)testItShouldSubscribeToSingleChannelAndReceiveMessageWithUserTimetokenWhenPublished { + NSDictionary *publishedMessage = @{ @"test-message": [self randomizedValuesWithValues:@[@"message"]] }; + NSString *channel = [self channelWithName:@"test-channel1"]; + + + [self subscribeClient:self.client toChannels:@[channel] withPresence:NO]; + [self waitTask:@"waitForDistribution" completionFor:(YHVVCR.cassette.isNewCassette ? 3.f : 0.f)]; + + + [self waitToCompleteIn:self.testCompletionDelay codeBlock:^(dispatch_block_t handler) { + [self addMessageHandlerForClient:self.client + withBlock:^(PubNub *client, PNMessageResult *message, BOOL *remove) { + + if ([message.data.publisher isEqualToString:self.client.currentConfiguration.userID]) { + XCTAssertEqualObjects(message.data.message, publishedMessage); + XCTAssertEqualObjects(message.data.subscription, channel); + XCTAssertEqualObjects(message.data.channel, channel); + XCTAssertEqualObjects(message.data.userTimetoken.timetoken, + @(message.data.timetoken.unsignedIntegerValue - 1)); + XCTAssertNil(message.data.userTimetoken.region); + XCTAssertNotNil(message.data.userTimetoken); + *remove = YES; + + handler(); + } + }]; + + [self.client publish:publishedMessage toChannel:channel withCompletion:^(PNPublishStatus *status) { + XCTAssertFalse(status.isError); + }]; + }]; +} + /** * @brief Follow instructions to simulate server response with "broken" payload. *