Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ObjC tests: Review #75

Merged
merged 34 commits into from
Nov 19, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
a818be6
Resolved bad response...
ricardopereira Nov 12, 2015
9a1f957
ARTPresence wasn't working. Fixed recursive cicle ...
ricardopereira Nov 12, 2015
e079c31
Optional debug info
ricardopereira Nov 13, 2015
026e1af
realtimeTransportFailed: missing error information
ricardopereira Nov 13, 2015
9d66764
TODO: Assign on requestToken - Key does not support requested capabi…
ricardopereira Nov 14, 2015
440e99d
Fixed: testPresenceEnterRestricted (forced capability)
ricardopereira Nov 16, 2015
03e0c20
ARTPaginatedResult.executePaginatedRequest doesn't have authenticatio…
ricardopereira Nov 14, 2015
0145c70
Fixed: ARTPaginatedResult request. The request must be executed by th…
ricardopereira Nov 14, 2015
d584d11
testRealtimeV2 description
ricardopereira Nov 17, 2015
3bef366
Fixed tests where the result of and were ignored and needed
ricardopereira Nov 14, 2015
4214653
Fixed: mismatched clientId
ricardopereira Nov 14, 2015
2653417
Fixed: instanciating a new RealtimeClient with Key
ricardopereira Nov 14, 2015
de363fd
testInitWithKey: Single key string works
ricardopereira Nov 17, 2015
a5be2d7
Fixed: history tests with query dates were assigning an invalid time …
ricardopereira Nov 14, 2015
42106af
Fixed bug: Presence#get has no query argument
ricardopereira Nov 15, 2015
9b4cfe9
Presence#enterClient only works on anonymous connection
ricardopereira Nov 15, 2015
40c828a
Fixed: testWithNoClientIdUpdateLeaveEnterAnotherClient (empty content)
ricardopereira Nov 15, 2015
de779dc
Fixed: test250ClientsEnter (no clientId for enterClient)
ricardopereira Nov 15, 2015
ba511a2
Fixed: testSyncResumes (no clientId for enterClient)
ricardopereira Nov 15, 2015
ceea895
Fixed: testPresenceNoSideEffects(connection can not have a clientId u…
ricardopereira Nov 15, 2015
fece74d
testEnterClient: no data
ricardopereira Nov 17, 2015
208652a
Fixed: testSimple (missing [expectation fulfill])
ricardopereira Nov 15, 2015
0c218e5
Fixed: testSimple (expect last message)
ricardopereira Nov 17, 2015
e3556c3
Updated Realtime with RTN15c (Resuming...)
ricardopereira Nov 17, 2015
f237706
Fixed: testRecoverDisconnected (the can be different because it enc…
ricardopereira Nov 15, 2015
35cf7ba
Fixed: testRecoverFails (should check ARTRealtimeFailed event)
ricardopereira Nov 15, 2015
5579578
Fixed: testPublishRestricted (check error)
ricardopereira Nov 15, 2015
ec6672a
Use restricted capabilities
ricardopereira Nov 16, 2015
e2d9db6
Fixed: testInitWithKey (check invalid credentials)
ricardopereira Nov 15, 2015
ac1d9f5
Fixed: testInitWithOptionsBad (check invalid ClientOptions)
ricardopereira Nov 15, 2015
140109a
Fixed: ARTRestChannel was missing the ARTRestPresence
ricardopereira Nov 16, 2015
29f063a
Fixed: testTTLDefaultOneHour (missing auth.tokenDetails) and testAuth…
ricardopereira Nov 16, 2015
fa5464d
Bug: isAuthBasic (testDefaultAuthType)
ricardopereira Nov 16, 2015
a266630
publishMessages with array of ARTMessage
ricardopereira Nov 16, 2015
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ably-ios/ARTAuth.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ ART_ASSUME_NONNULL_BEGIN

@interface ARTAuth : NSObject

@property (nonatomic, readonly, strong) ARTAuthOptions *options;
@property (nonatomic, readonly, weak) ARTAuthOptions *options;
@property (nonatomic, readonly, assign) ARTAuthMethod method;

@property (nonatomic, weak) ARTLog *logger;
Expand Down
17 changes: 14 additions & 3 deletions ably-ios/ARTAuthOptions.m
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,16 @@ - (NSString *)description {
}

- (NSString *)token {
return self.tokenDetails.token;
if (self.tokenDetails) {
return self.tokenDetails.token;
}
return nil;
}

- (void)setToken:(NSString *)token {
self.tokenDetails = [[ARTAuthTokenDetails alloc] initWithToken:token];
if (token && ![token isEqualToString:@""]) {
self.tokenDetails = [[ARTAuthTokenDetails alloc] initWithToken:token];
}
}

- (void)setAuthMethod:(NSString *)authMethod {
Expand Down Expand Up @@ -108,7 +113,13 @@ - (ARTAuthOptions *)mergeWith:(ARTAuthOptions *)precedenceOptions {
}

- (BOOL)isBasicAuth {
return self.useTokenAuth == false && self.key != nil && self.clientId == nil;
return self.useTokenAuth == false &&
self.key != nil &&
self.clientId == nil &&
self.token == nil &&
self.tokenDetails == nil &&
self.authUrl == nil &&
self.authCallback == nil;
}

- (BOOL)isMethodPOST {
Expand Down
5 changes: 1 addition & 4 deletions ably-ios/ARTChannel+Private.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@

ART_ASSUME_NONNULL_BEGIN

@interface ARTChannel() {
@public
id<ARTPayloadEncoder> _payloadEncoder;
}
@interface ARTChannel()

@property (nonatomic, strong, art_null_resettable) ARTChannelOptions *options;

Expand Down
7 changes: 4 additions & 3 deletions ably-ios/ARTChannel.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#import <Foundation/Foundation.h>
#import "ARTTypes.h"

@protocol ARTPayloadEncoder;

@class ARTChannelOptions;
@class ARTMessage;
@class ARTPaginatedResult;
Expand All @@ -20,6 +22,8 @@ ART_ASSUME_NONNULL_BEGIN

@property (nonatomic, strong, readonly) NSString *name;

@property (readonly, strong, nonatomic) id<ARTPayloadEncoder> payloadEncoder;

- (instancetype)initWithName:(NSString *)name andOptions:(ARTChannelOptions *)options;

- (void)publish:(art_nullable id)payload callback:(art_nullable ARTErrorCallback)callback;
Expand All @@ -30,9 +34,6 @@ ART_ASSUME_NONNULL_BEGIN

- (void)history:(art_nullable ARTDataQuery *)query callback:(void(^)(ARTPaginatedResult /* <ARTMessage *> */ *__art_nullable result, NSError *__art_nullable error))callback;

// TODO:
//- (void)presence

@end

ART_ASSUME_NONNULL_END
5 changes: 3 additions & 2 deletions ably-ios/ARTChannel.m
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ - (instancetype)initWithName:(NSString *)name andOptions:(ARTChannelOptions *)op
if (self = [super init]) {
_name = name;
_options = options;
_payloadEncoder = [ARTPayload defaultPayloadEncoder:options.cipherParams];
}
return self;
}
Expand All @@ -42,14 +43,14 @@ - (void)publish:(id)data name:(NSString *)name callback:(ARTErrorCallback)callba

- (void)publishMessages:(NSArray *)messages callback:(ARTErrorCallback)callback {
messages = [messages artMap:^(ARTMessage *message) {
return [message encode:_payloadEncoder];
return [message encode:self.payloadEncoder];
}];

[self internalPostMessages:messages callback:callback];
}

- (void)publishMessage:(ARTMessage *)message callback:(ARTErrorCallback)callback {
[self internalPostMessages:[message encode:_payloadEncoder] callback:callback];
[self internalPostMessages:[message encode:self.payloadEncoder] callback:callback];
}

- (void)history:(ARTDataQuery *)query callback:(void (^)(ARTPaginatedResult *, NSError *))callback {
Expand Down
10 changes: 5 additions & 5 deletions ably-ios/ARTChannelCollection.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@
#import "CompatibilityMacros.h"

@class ARTRest;
@class ARTChannel;
@class ARTRestChannel;
@class ARTChannelOptions;

@interface ARTChannelCollection : NSObject<NSFastEnumeration>

@property (nonatomic, readonly) __GENERIC(NSMutableDictionary, NSString *, ARTChannel *) *channels;
@property (nonatomic, readonly) __GENERIC(NSMutableDictionary, NSString *, ARTRestChannel *) *channels;

- (instancetype)initWithRest:(ARTRest *)rest;

- (BOOL)exists:(NSString *)channelName;
- (ARTChannel *)get:(NSString *)channelName;
- (ARTChannel *)get:(NSString *)channelName options:(ARTChannelOptions *)options;
- (void)releaseChannel:(ARTChannel *)channel;
- (ARTRestChannel *)get:(NSString *)channelName;
- (ARTRestChannel *)get:(NSString *)channelName options:(ARTChannelOptions *)options;
- (void)releaseChannel:(ARTRestChannel *)channel;

@end
9 changes: 4 additions & 5 deletions ably-ios/ARTChannelCollection.m
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
#import "ARTRestChannel.h"
#import "ARTChannel+Private.h"
#import "ARTChannelOptions.h"
#import "ARTPresence.h"

@interface ARTChannelCollection() {
__weak ARTRest *_rest;
Expand Down Expand Up @@ -44,20 +43,20 @@ - (BOOL)exists:(NSString *)channelName {
return self->_channels[channelName] != nil;
}

- (ARTChannel *)get:(NSString *)channelName {
- (ARTRestChannel *)get:(NSString *)channelName {
return [self _getChannel:channelName options:nil];
}

- (ARTChannel *)get:(NSString *)channelName options:(ARTChannelOptions *)options {
- (ARTRestChannel *)get:(NSString *)channelName options:(ARTChannelOptions *)options {
return [self _getChannel:channelName options:options];
}

- (void)releaseChannel:(ARTChannel *)channel {
[self->_channels removeObjectForKey:channel.name];
}

- (ARTChannel *)_getChannel:(NSString *)channelName options:(ARTChannelOptions *)options {
ARTChannel *channel = self->_channels[channelName];
- (ARTRestChannel *)_getChannel:(NSString *)channelName options:(ARTChannelOptions *)options {
ARTRestChannel *channel = self->_channels[channelName];
if (!channel) {
channel = [[_rest.channelClass alloc] initWithName:channelName withOptions:options andRest:_rest];
[self->_channels setObject:channel forKey:channelName];
Expand Down
8 changes: 0 additions & 8 deletions ably-ios/ARTClientOptions.m
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,6 @@ - (instancetype)initDefaults;

@implementation ARTClientOptions

- (instancetype)initWithKey:(NSString *)key {
self = [super initWithKey:key];
if (self) {
self = [self initDefaults];
}
return self;
}

- (instancetype)initDefaults {
self = [super initDefaults];
_restPort = [ARTDefault TLSPort];
Expand Down
4 changes: 4 additions & 0 deletions ably-ios/ARTHttp.m
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,10 @@ - (void)executeRequest:(NSMutableURLRequest *)request completion:(ARTHttpRequest
} else {
[self.logger debug:@"%@ %@: statusCode %ld", request.HTTPMethod, request.URL.absoluteString, (long)httpResponse.statusCode];
[self.logger verbose:@"Headers %@", httpResponse.allHeaderFields];
NSString *headerErrorMessage = httpResponse.allHeaderFields[@"X-Ably-ErrorMessage"];
if (headerErrorMessage && ![headerErrorMessage isEqualToString:@""]) {
[self.logger warn:@"%@", headerErrorMessage];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am going to merge, but could we also log the X-Ably-ErrorCode, if present?

}
}
callback(httpResponse, data, error);
});
Expand Down
1 change: 0 additions & 1 deletion ably-ios/ARTJsonEncoder.m
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,6 @@ - (void)writePayload:(ARTPayload *)payload toDictionary:(NSMutableDictionary *)o
[self.logger error:@"ARTJsonEncoder failed to encode payload"];
}
NSAssert(status.state == ARTStateOk, @"Error encoding payload");
NSAssert([payload.payload isKindOfClass:[NSString class]], @"Only string payloads are accepted");

if (encoded.encoding.length) {
output[@"encoding"] = encoded.encoding;
Expand Down
2 changes: 1 addition & 1 deletion ably-ios/ARTMessage.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ ART_ASSUME_NONNULL_BEGIN
/// The event name, if available
@property (readwrite, strong, nonatomic) NSString *name;

- (instancetype)initWithData:(id)data name:(NSString *)name;
- (instancetype)initWithData:(id)data name:(art_nullable NSString *)name;

+ (ARTMessage *)messageWithPayload:(id)payload name:(art_nullable NSString *)name;
+ (NSArray *)messagesWithPayloads:(NSArray *)payloads;
Expand Down
14 changes: 9 additions & 5 deletions ably-ios/ARTPaginatedResult+Private.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,18 @@

#import "ARTPaginatedResult.h"

@protocol ARTHTTPExecutor;
@class ARTRest;

ART_ASSUME_NONNULL_BEGIN

@interface ARTPaginatedResult ()

typedef NSArray *(^ARTPaginatedResultResponseProcessor)(NSHTTPURLResponse *, NSData *);
typedef NSArray *__art_nullable(^ARTPaginatedResultResponseProcessor)(NSHTTPURLResponse *__art_nullable, NSData *__art_nullable);

+ (void)executePaginatedRequest:(NSMutableURLRequest *)request executor:(id<ARTHTTPExecutor>)executor
responseProcessor:(ARTPaginatedResultResponseProcessor)responseProcessor
+ (void)executePaginated:(ARTRest *)rest withRequest:(NSMutableURLRequest *)request
andResponseProcessor:(ARTPaginatedResultResponseProcessor)responseProcessor
callback:(ARTPaginatedResultCallback)callback;

@end
@end

ART_ASSUME_NONNULL_END
29 changes: 14 additions & 15 deletions ably-ios/ARTPaginatedResult.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,19 @@
#import "ARTPaginatedResult+Private.h"

#import "ARTHttp.h"
#import "ARTAuth.h"
#import "ARTRest+Private.h"

@implementation ARTPaginatedResult {
id<ARTHTTPExecutor> _executor;
__weak ARTRest *_rest;
NSMutableURLRequest *_relFirst;
NSMutableURLRequest *_relCurrent;
NSMutableURLRequest *_relNext;
ARTPaginatedResultResponseProcessor _responseProcessor;
}

- (instancetype)initWithItems:(NSArray *)items
executor:(id<ARTHTTPExecutor>)executor
rest:(ARTRest *)rest
relFirst:(NSMutableURLRequest *)relFirst
relCurrent:(NSMutableURLRequest *)relCurrent
relNext:(NSMutableURLRequest *)relNext
Expand All @@ -37,23 +39,23 @@ - (instancetype)initWithItems:(NSArray *)items
_hasNext = !!relNext;
_isLast = !_hasNext;

_executor = executor;
_rest = rest;
_responseProcessor = responseProcessor;
}

return self;
}

- (void)first:(ARTPaginatedResultCallback)callback {
[self.class executePaginatedRequest:_relFirst executor:_executor responseProcessor:_responseProcessor callback:callback];
[self.class executePaginated:_rest withRequest:_relFirst andResponseProcessor:_responseProcessor callback:callback];
}

- (void)current:(ARTPaginatedResultCallback)callback {
[self.class executePaginatedRequest:_relCurrent executor:_executor responseProcessor:_responseProcessor callback:callback];
[self.class executePaginated:_rest withRequest:_relCurrent andResponseProcessor:_responseProcessor callback:callback];
}

- (void)next:(ARTPaginatedResultCallback)callback {
[self.class executePaginatedRequest:_relNext executor:_executor responseProcessor:_responseProcessor callback:callback];
[self.class executePaginated:_rest withRequest:_relNext andResponseProcessor:_responseProcessor callback:callback];
}

static NSDictionary *extractLinks(NSHTTPURLResponse *response) {
Expand Down Expand Up @@ -96,30 +98,27 @@ - (void)next:(ARTPaginatedResultCallback)callback {
return [NSMutableURLRequest requestWithURL:url];
}

+ (void)executePaginatedRequest:(NSMutableURLRequest *)request executor:(id<ARTHTTPExecutor>)executor
responseProcessor:(ARTPaginatedResultResponseProcessor)responseProcessor
callback:(ARTPaginatedResultCallback)callback {
+ (void)executePaginated:(ARTRest *)rest withRequest:(NSMutableURLRequest *)request andResponseProcessor:(ARTPaginatedResultResponseProcessor)responseProcessor callback:(ARTPaginatedResultCallback)callback {

// FIXME: review (no auth?!)
[executor executeRequest:request completion:^(NSHTTPURLResponse *response, NSData *data, NSError *error) {
[rest executeRequest:request withAuthOption:ARTAuthenticationOn completion:^(NSHTTPURLResponse *response, NSData *data, NSError *error) {
if (error) {
callback(nil, error);
} else {
NSArray *items = responseProcessor(response, data);

NSDictionary *links = extractLinks(response);

NSMutableURLRequest *firstRel = requestRelativeTo(request, links[@"first"]);
NSMutableURLRequest *currentRel = requestRelativeTo(request, links[@"current"]);;
NSMutableURLRequest *nextRel = requestRelativeTo(request, links[@"next"]);;

ARTPaginatedResult *result = [[ARTPaginatedResult alloc] initWithItems:items
executor:executor
rest:rest
relFirst:firstRel
relCurrent:currentRel
relNext:nextRel
responseProcessor:responseProcessor];

callback(result, nil);
}
}];
Expand Down
19 changes: 3 additions & 16 deletions ably-ios/ARTPresence.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
@protocol ARTSubscription;

@class ARTChannel;
@class ARTRealtimeChannel;
@class ARTPaginatedResult;
@class ARTDataQuery;

Expand All @@ -24,7 +23,9 @@ ART_ASSUME_NONNULL_BEGIN
*/
@interface ARTPresence : NSObject

- (instancetype)initWithChannel:(ARTRealtimeChannel *)channel;
@property (readonly, getter=getChannel) ARTChannel *channel;

- (instancetype)initWithChannel:(ARTChannel *)channel;

/**
Get the presence state for one channel
Expand All @@ -36,20 +37,6 @@ ART_ASSUME_NONNULL_BEGIN
*/
- (void)history:(art_nullable ARTDataQuery *)query callback:(void (^)(ARTPaginatedResult /* <ARTPresenceMessage *> */ *__art_nullable result, NSError *__art_nullable error))callback;

- (void)enter:(id)data cb:(ARTStatusCallback)cb;
- (void)update:(id)data cb:(ARTStatusCallback)cb;
- (void)leave:(id) data cb:(ARTStatusCallback)cb;

- (void)enterClient:(NSString *) clientId data:(id) data cb:(ARTStatusCallback) cb;
- (void)updateClient:(NSString *) clientId data:(id) data cb:(ARTStatusCallback) cb;
- (void)leaveClient:(NSString *) clientId data:(id) data cb:(ARTStatusCallback) cb;
- (BOOL)isSyncComplete;

- (id<ARTSubscription>)subscribe:(ARTRealtimeChannelPresenceCb)cb;
- (id<ARTSubscription>)subscribe:(ARTPresenceAction)action cb:(ARTRealtimeChannelPresenceCb)cb;
- (void)unsubscribe:(id<ARTSubscription>)subscription;
- (void)unsubscribe:(id<ARTSubscription>)subscription action:(ARTPresenceAction)action;

@end

ART_ASSUME_NONNULL_END
Loading