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

Converted tests to Swift 2 #25

Merged
merged 1 commit into from
Oct 13, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
12 changes: 6 additions & 6 deletions Podfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
pod 'SocketRocket', '~> 0.3.1-beta2'
pod 'SocketRocket', '~> 0.4.1'
#pod 'msgpack', '~> 0.1.3'

target 'ablySpec' do
platform :ios, '8.0'
use_frameworks!

pod 'Quick', '~> 0.3.0'
pod 'Nimble', '~> 1.0.0'
pod 'Quick', '~> 0.6.0'
pod 'Nimble', '~> 2.0.0'
# Helpers
pod 'Runes', '~> 2.0.0'
pod 'SwiftyJSON', '~> 2.2.1'
end
pod 'Runes', '~> 3.0.0'
pod 'SwiftyJSON', '~> 2.3.0'
end
30 changes: 15 additions & 15 deletions Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
PODS:
- Nimble (1.0.0)
- Quick (0.3.1)
- Runes (2.0.0)
- SocketRocket (0.3.1-beta2)
- SwiftyJSON (2.2.1)
- Nimble (2.0.0)
- Quick (0.6.0)
- Runes (3.0.0)
- SocketRocket (0.4.1)
- SwiftyJSON (2.3.0)

DEPENDENCIES:
- Nimble (~> 1.0.0)
- Quick (~> 0.3.0)
- Runes (~> 2.0.0)
- SocketRocket (~> 0.3.1-beta2)
- SwiftyJSON (~> 2.2.1)
- Nimble (~> 2.0.0)
- Quick (~> 0.6.0)
- Runes (~> 3.0.0)
- SocketRocket (~> 0.4.1)
- SwiftyJSON (~> 2.3.0)

SPEC CHECKSUMS:
Nimble: 8bee528e5fcc403653076545db562d2b5db7bb87
Quick: 824572d3d198d51e52cf4aa722cebf7e59952a35
Runes: 4fe81355f4620b76b02176222d264b33e60dba51
SocketRocket: 7284ab9370a06c99aba92b2fe3a32aedd0f9a6fa
SwiftyJSON: ae2d0a3d68025d136602a33c4ee215091ced3e33
Nimble: 472e75466819eb8c06299233e87c694a9b51328a
Quick: 563686dbcf0ae0f9f7401ac9cd2d786ee1b7f3d7
Runes: b0ffeed58b9577155e53571508b4309c904ef587
SocketRocket: ee0b5c34182d37bb4f1f8d628bbe737718126daa
SwiftyJSON: 8d6b61a70277ef2a5d710d372e06e7e2d87fb9e4

COCOAPODS: 0.38.2
10 changes: 0 additions & 10 deletions ably-ios.xcworkspace/contents.xcworkspacedata

This file was deleted.

53 changes: 0 additions & 53 deletions ably-ios.xcworkspace/xcshareddata/ably-ios.xccheckout

This file was deleted.

4 changes: 0 additions & 4 deletions ably-ios/ARTRest+Private.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,6 @@ typedef NS_ENUM(NSUInteger, ARTAuthentication) {

- (id<ARTCancellable>)post:(NSString *)relUrl headers:(NSDictionary *)headers body:(NSData *)body authenticated:(ARTAuthentication)authenticated cb:(ARTHttpCb)cb;

- (id<ARTCancellable>)withAuthHeadersUseBasic:(BOOL)useBasic cb:(id<ARTCancellable>(^)(NSDictionary *))cb;
- (id<ARTCancellable>)withAuthHeaders:(id<ARTCancellable>(^)(NSDictionary *authHeaders))cb;
- (id<ARTCancellable>)withAuthParams:(id<ARTCancellable>(^)(NSDictionary *authParams))cb;

- (void)executeRequest:(NSMutableURLRequest *)request callback:(void (^)(NSHTTPURLResponse *, NSData *, NSError *))callback;

- (id<ARTCancellable>)postTestStats:(NSArray *)stats cb:(void(^)(ARTStatus * status)) cb;
Expand Down
6 changes: 6 additions & 0 deletions ably-ios/ARTWebSocketTransport.m
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ - (instancetype)initWithRest:(ARTRest *)rest options:(ARTClientOptions *)options
_closing = NO;
_encoder = rest.defaultEncoder;

/*
__weak ARTWebSocketTransport *wSelf = self;
__weak ARTRest *wRest = rest;
_logger = rest.logger;
Expand All @@ -62,7 +63,11 @@ - (instancetype)initWithRest:(ARTRest *)rest options:(ARTClientOptions *)options

NSString *realtimeHost = options.realtimeHost;
int realtimePort = options.realtimePort;
*/

NSAssert(false, @"WIP: Realtime sould be extending from RestClient");

/*
[rest withAuthParams:^id<ARTCancellable>(NSDictionary *authParams) {
ARTWebSocketTransport *sSelf = wSelf;
ARTRest *sRest = wRest;
Expand Down Expand Up @@ -105,6 +110,7 @@ - (instancetype)initWithRest:(ARTRest *)rest options:(ARTClientOptions *)options
[sSelf.websocket setDelegateDispatchQueue:sSelf.q];
return nil;
}];
*/
}
return self;
}
Expand Down
4 changes: 0 additions & 4 deletions ably.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@
D746AE541BBD85C5003ECEF8 /* ARTChannelCollection.m in Sources */ = {isa = PBXBuildFile; fileRef = D746AE521BBD85C5003ECEF8 /* ARTChannelCollection.m */; };
D7C1B8771BBEA81A0087B55F /* Auth.swift in Sources */ = {isa = PBXBuildFile; fileRef = D7C1B8761BBEA81A0087B55F /* Auth.swift */; };
D7C1B8791BBF5F810087B55F /* ARTAuth+Private.h in Headers */ = {isa = PBXBuildFile; fileRef = D7C1B8781BBF5F460087B55F /* ARTAuth+Private.h */; settings = {ATTRIBUTES = (Private, ); }; };
D7D8F81E1BC28FF0009718F2 /* Helpers.swift in Sources */ = {isa = PBXBuildFile; fileRef = D7D8F81D1BC28FF0009718F2 /* Helpers.swift */; };
D7D8F8211BC2BE16009718F2 /* ARTAuthOptions.h in Headers */ = {isa = PBXBuildFile; fileRef = D7D8F81F1BC2BE15009718F2 /* ARTAuthOptions.h */; settings = {ATTRIBUTES = (Public, ); }; };
D7D8F8221BC2BE16009718F2 /* ARTAuthOptions.m in Sources */ = {isa = PBXBuildFile; fileRef = D7D8F8201BC2BE15009718F2 /* ARTAuthOptions.m */; };
D7D8F8251BC2C691009718F2 /* ARTAuthTokenDetails.h in Headers */ = {isa = PBXBuildFile; fileRef = D7D8F8231BC2C691009718F2 /* ARTAuthTokenDetails.h */; settings = {ATTRIBUTES = (Public, ); }; };
Expand Down Expand Up @@ -315,7 +314,6 @@
D746AE551BBD8622003ECEF8 /* ARTChannelCollection+Private.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "ARTChannelCollection+Private.h"; sourceTree = "<group>"; };
D7C1B8761BBEA81A0087B55F /* Auth.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Auth.swift; sourceTree = "<group>"; };
D7C1B8781BBF5F460087B55F /* ARTAuth+Private.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "ARTAuth+Private.h"; sourceTree = "<group>"; };
D7D8F81D1BC28FF0009718F2 /* Helpers.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Helpers.swift; sourceTree = "<group>"; };
D7D8F81F1BC2BE15009718F2 /* ARTAuthOptions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ARTAuthOptions.h; sourceTree = "<group>"; };
D7D8F8201BC2BE15009718F2 /* ARTAuthOptions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ARTAuthOptions.m; sourceTree = "<group>"; };
D7D8F8231BC2C691009718F2 /* ARTAuthTokenDetails.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ARTAuthTokenDetails.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -407,7 +405,6 @@
D746AE2B1BBB625E003ECEF8 /* RestClient.channels.swift */,
D723046F1BB72CED00F1ABDA /* RealtimeClient.swift */,
851674EE1B7BA5CD00D35169 /* Stats.swift */,
D7D8F81D1BC28FF0009718F2 /* Helpers.swift */,
);
path = ablySpec;
sourceTree = "<group>";
Expand Down Expand Up @@ -912,7 +909,6 @@
D746AE2C1BBB625E003ECEF8 /* RestChannel.swift in Sources */,
856AAC971B6E30C800B07119 /* TestUtilities.swift in Sources */,
853ED7C41B7A1A3C006F1C6F /* RestClient.stats.swift in Sources */,
D7D8F81E1BC28FF0009718F2 /* Helpers.swift in Sources */,
851674EF1B7BA5CD00D35169 /* Stats.swift in Sources */,
D72304701BB72CED00F1ABDA /* RealtimeClient.swift in Sources */,
D746AE2D1BBB625E003ECEF8 /* RestClient.channels.swift in Sources */,
Expand Down
43 changes: 26 additions & 17 deletions ablySpec/Auth.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

import Nimble
import Quick
import Runes

import ably
import ably.Private
Expand Down Expand Up @@ -39,8 +38,6 @@ class Auth : QuickSpec {

publishTestMessage(client, failOnError: false)

expect(client.options.key).toNot(beNil())

let key64 = NSString(string: "\(client.options.key!)")
.dataUsingEncoding(NSUTF8StringEncoding)?
.base64EncodedStringWithOptions(NSDataBase64EncodingOptions(rawValue: 0))
Expand All @@ -49,7 +46,7 @@ class Auth : QuickSpec {

expect(mockExecutor.requests.first).toNot(beNil())

let authorization = mockExecutor.requests.first?.allHTTPHeaderFields?["Authorization"] as? String ?? ""
let authorization = mockExecutor.requests.first?.allHTTPHeaderFields?["Authorization"] ?? ""

expect(authorization).to(equal(expectedAuthorization))
}
Expand All @@ -69,20 +66,32 @@ class Auth : QuickSpec {
let options = ARTClientOptions()
options.token = getTestToken()

expect(options.token!.isEmpty) == false

let client = ARTRest(options: options)
// Check HTTP
options.tls = false
let clientHTTP = ARTRest(options: options)
clientHTTP.httpExecutor = mockExecutor

client.httpExecutor = mockExecutor

publishTestMessage(client, failOnError: false)
publishTestMessage(clientHTTP, failOnError: false)

expect(mockExecutor.requests.first).toNot(beNil())
expect(mockExecutor.requests.first?.URL).toNot(beNil())
expect(mockExecutor.requests.first).toNot(beNil(), description: "No request found")
expect(mockExecutor.requests.first?.URL).toNot(beNil(), description: "Request is invalid")

if let request = mockExecutor.requests.first, let url = request.URL {
expect(url.scheme).to(equal("http"))
expect(url.scheme).to(equal("http"), description: "No HTTP support")
}

// Check HTTPS
options.tls = true
let clientHTTPS = ARTRest(options: options)
clientHTTPS.httpExecutor = mockExecutor

publishTestMessage(clientHTTPS, failOnError: false)

expect(mockExecutor.requests.last).toNot(beNil(), description: "No request found")
expect(mockExecutor.requests.last?.URL).toNot(beNil(), description: "Request is invalid")

if let request = mockExecutor.requests.last, let url = request.URL {
expect(url.scheme).to(equal("https"), description: "No HTTPS support")
}
}

Expand All @@ -105,7 +114,7 @@ class Auth : QuickSpec {

expect(mockExecutor.requests.first).toNot(beNil())

let authorization = mockExecutor.requests.first?.allHTTPHeaderFields?["Authorization"] as? String ?? ""
let authorization = mockExecutor.requests.first?.allHTTPHeaderFields?["Authorization"] ?? ""

expect(authorization).to(equal(expectedAuthorization))
}
Expand Down Expand Up @@ -187,10 +196,10 @@ class Auth : QuickSpec {

let request = rest.auth.buildRequest(clientOptions, withParams: tokenParams)

let httpBodyJSON = request.HTTPBody >>- JSONToDictionary
let httpBodyJSON = try! NSJSONSerialization.JSONObjectWithData(request.HTTPBody ?? NSData(), options: .MutableLeaves) as? NSDictionary

expect(httpBodyJSON).toNot(beNil())
expect(httpBodyJSON!["timestamp"]).toNot(beNil())
expect(httpBodyJSON).toNot(beNil(), description: "HTTPBody is empty")
expect(httpBodyJSON!["timestamp"]).toNot(beNil(), description: "HTTPBody has no timestamp")

let expectedJSON = ["ttl":NSString(format: "%f", CGFloat(60*60)), "capability":"{ \"*\": [ \"*\" ] }", "timestamp":httpBodyJSON!["timestamp"]!]

Expand Down
22 changes: 5 additions & 17 deletions ablySpec/Helpers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,34 +10,22 @@ import Foundation
import Runes


// MARK: - Global Functions

/**
**Public function** – Load JSON from a file
*/
func JSONFromFile(fileName: String) -> AnyObject? {
return NSBundle.mainBundle().pathForResource(fileName, ofType: "json")
>>- { NSData(contentsOfFile: $0) }
>>- { NSJSONSerialization.JSONObjectWithData($0, options: NSJSONReadingOptions(0), error: nil) }
}


// MARK: - Monads

let arrayToJSONData: NSArray -> NSData? = {
NSJSONSerialization.dataWithJSONObject($0, options: NSJSONWritingOptions.allZeros, error: nil)
try? NSJSONSerialization.dataWithJSONObject($0, options: NSJSONWritingOptions.allZeros)
}

let dictionaryToJSONData: NSDictionary -> NSData? = {
NSJSONSerialization.dataWithJSONObject($0, options: NSJSONWritingOptions.allZeros, error: nil)
try? NSJSONSerialization.dataWithJSONObject($0, options: NSJSONWritingOptions.allZeros)
}

let arrayToPrettyJSONData: NSArray -> NSData? = {
NSJSONSerialization.dataWithJSONObject($0, options: NSJSONWritingOptions.PrettyPrinted, error: nil)
try? NSJSONSerialization.dataWithJSONObject($0, options: NSJSONWritingOptions.PrettyPrinted)
}

let dictionaryToPrettyJSONData: NSDictionary -> NSData? = {
NSJSONSerialization.dataWithJSONObject($0, options: NSJSONWritingOptions.PrettyPrinted, error: nil)
try? NSJSONSerialization.dataWithJSONObject($0, options: NSJSONWritingOptions.PrettyPrinted)
}

let dataToJSONString: NSData -> NSString? = {
Expand All @@ -49,7 +37,7 @@ let JSONStringToData: String -> NSData? = {
}

let JSONDataToAny: NSData -> AnyObject? = {
NSJSONSerialization.JSONObjectWithData($0, options: .MutableLeaves, error: nil)
try? NSJSONSerialization.JSONObjectWithData($0, options: .MutableLeaves)
}

/**
Expand Down
9 changes: 5 additions & 4 deletions ablySpec/RestChannel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ class RestChannel: QuickSpec {
publishError = error
channel.history(nil) { result, _ in
if let items = result?.items as? [ARTMessage] {
publishedMessages.extend(items)
publishedMessages.appendContentsOf(items)
}
}
}
Expand All @@ -185,15 +185,16 @@ class RestChannel: QuickSpec {

channel.presence.get() { result, _ in
if let items = result?.items as? [ARTPresenceMessage] {
presenceMessages.extend(items)
presenceMessages.appendContentsOf(items)
}
}

expect(presenceMessages.count).toEventually(equal(presenceFixtures.count), timeout: testTimeout)
for message in presenceMessages {
let fixtureMessage = filter(presenceFixtures) { (key, value) in

let fixtureMessage = presenceFixtures.filter({ (key, value) -> Bool in
return message.clientId == value["clientId"].stringValue
}.first!.1
}).first!.1

expect(message.content()).toNot(beNil())
expect(message.action).to(equal(ARTPresenceAction.Present))
Expand Down
Loading