Skip to content

Commit

Permalink
Port legacy tests to Swift (#629)
Browse files Browse the repository at this point in the history
* RSC14a

* RSL2a

* RTP10d

* RTP14d

* Disable legacy tests

* Update CocoaPods.

* Ordering fix in RTP14d test.

* Get rit od AblyTests.
  • Loading branch information
ricardopereira authored and tcard committed Aug 30, 2017
1 parent 1921b42 commit 2a9f75d
Show file tree
Hide file tree
Showing 9 changed files with 205 additions and 346 deletions.
252 changes: 24 additions & 228 deletions Ably.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

24 changes: 14 additions & 10 deletions Ably.xcodeproj/xcshareddata/xcschemes/Ably.xcscheme
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,20 @@
ReferencedContainer = "container:Ably.xcodeproj">
</BuildableReference>
</BuildActionEntry>
<BuildActionEntry
buildForTesting = "NO"
buildForRunning = "NO"
buildForProfiling = "NO"
buildForArchiving = "NO"
buildForAnalyzing = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "96BF613B1A35B2AB004CF2B3"
BuildableName = "AblyTests.xctest"
BlueprintName = "AblyTests"
ReferencedContainer = "container:Ably.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
Expand All @@ -28,16 +42,6 @@
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "NO">
<Testables>
<TestableReference
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "96BF613B1A35B2AB004CF2B3"
BuildableName = "AblyTests.xctest"
BlueprintName = "AblyTests"
ReferencedContainer = "container:Ably.xcodeproj">
</BuildableReference>
</TestableReference>
<TestableReference
skipped = "NO">
<BuildableReference
Expand Down
97 changes: 0 additions & 97 deletions Ably.xcodeproj/xcshareddata/xcschemes/AblyTests.xcscheme

This file was deleted.

4 changes: 0 additions & 4 deletions Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,3 @@ end
target 'AblySpec' do
test_pods
end

target 'AblyTests' do
test_pods
end
4 changes: 2 additions & 2 deletions Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,6 @@ SPEC CHECKSUMS:
SocketRocket: d57c7159b83c3c6655745cd15302aa24b6bae531
SwiftyJSON: c2842d878f95482ffceec5709abc3d05680c0220

PODFILE CHECKSUM: 51df8c07c1f9b8c5dc1c7d7b7c47457ddfc72d30
PODFILE CHECKSUM: 803f8969b4a606dfb2d42f997c1542238c37ab5b

COCOAPODS: 1.2.1
COCOAPODS: 1.3.1
5 changes: 0 additions & 5 deletions Source/ARTRealtimePresence.m
Original file line number Diff line number Diff line change
Expand Up @@ -315,11 +315,6 @@ - (void)leaveClient:(NSString *)clientId data:(id)data callback:(void (^)(ARTErr

- (void)leaveAfterChecks:(NSString *__art_nullable)clientId data:(id)data callback:(void (^)(ARTErrorInfo *))cb {
ART_TRY_OR_MOVE_TO_FAILED_START(_channel.realtime) {
if (!clientId || [clientId isEqualToString:_channel.clientId_nosync]) {
if(_channel.lastPresenceAction != ARTPresenceEnter && _channel.lastPresenceAction != ARTPresenceUpdate) {
[ARTException raise:@"Cannot leave a channel before you've entered it" format:@""];
}
}
ARTPresenceMessage *msg = [[ARTPresenceMessage alloc] init];
msg.action = ARTPresenceLeave;
msg.data = data;
Expand Down
71 changes: 71 additions & 0 deletions Spec/RealtimeClientPresence.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2451,6 +2451,36 @@ class RealtimeClientPresence: QuickSpec {
expect(received.clientId).to(equal("john"))
}

// RTP10d
it("if the client is not currently ENTERED, Ably will respond with an ACK and the request will succeed") {
let options = AblyTests.commonAppSetup()
options.clientId = "john"

let client = ARTRealtime(options: options)
defer { client.dispose(); client.close() }
let channel = client.channels.get("foo")

waitUntil(timeout: testTimeout) { done in
channel.presence.leave(nil) { error in
expect(error).to(beNil())
done()
}
}

waitUntil(timeout: testTimeout) { done in
channel.presence.enter("online") { error in
expect(error).to(beNil())
channel.presence.leave(nil) { error in
expect(error).to(beNil())
channel.presence.leave(nil) { error in
expect(error).to(beNil())
done()
}
}
}
}
}

}

// RTP8
Expand Down Expand Up @@ -3814,6 +3844,47 @@ class RealtimeClientPresence: QuickSpec {
expect(decodeNumberOfCalls).to(equal(1))
}

// RTP14d
it("should be present all the registered members on a presence channel") {
let client = ARTRealtime(options: AblyTests.commonAppSetup())
defer { client.dispose(); client.close() }
let channel = client.channels.get("foo")

let john = "john"
let max = "max"

waitUntil(timeout: testTimeout) { done in
let partialDone = AblyTests.splitDone(4, done: done)
channel.presence.subscribe { message in
expect(message.clientId).to(satisfyAnyOf(equal(john), equal(max)))
partialDone()
}
channel.presence.enterClient(john, data: nil) { error in
expect(error).to(beNil())
partialDone()
}
channel.presence.enterClient(max, data: nil) { error in
expect(error).to(beNil())
partialDone()
}
}

waitUntil(timeout: testTimeout) { done in
channel.presence.get { members, error in
expect(error).to(beNil())
guard let members = members else {
fail("Members is nil"); done(); return
}
expect(members).to(haveCount(2))
let clientIds = members.map({ $0.clientId })
// Cannot guarantee the order
expect(clientIds).to(equal([john, max]) || equal([max, john]))
done()
}
}

}

}

}
Expand Down
19 changes: 19 additions & 0 deletions Spec/RestClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,25 @@ class RestClient: QuickSpec {
// RSC14
context("Authentication") {

// RSC14a
it("should support basic authentication when an API key is provided with the key option") {
let options = AblyTests.commonAppSetup()
guard let components = options.key?.components(separatedBy: ":"), let keyName = components.first, let keySecret = components.last else {
fail("Invalid API key: \(options.key ?? "nil")"); return
}
ARTClientOptions.setDefaultEnvironment("sandbox")
defer {
ARTClientOptions.setDefaultEnvironment(nil)
}
let rest = ARTRest(key: "\(keyName):\(keySecret)")
waitUntil(timeout: testTimeout) { done in
rest.channels.get("foo").publish(nil, data: "testing") { error in
expect(error).to(beNil())
done()
}
}
}

// RSC14b
context("basic authentication flag") {
it("should be true when key is set") {
Expand Down
75 changes: 75 additions & 0 deletions Spec/RestClientChannel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,81 @@ class RestClientChannel: QuickSpec {
// RSL2
describe("history") {

// RSL2a
it("should return a PaginatedResult page containing the first page of messages") {
let client = ARTRest(options: AblyTests.commonAppSetup())
let channel = client.channels.get("foo")

waitUntil(timeout: testTimeout) { done in
channel.publish([
.init(name: nil, data: "m1"),
.init(name: nil, data: "m2"),
.init(name: nil, data: "m3"),
.init(name: nil, data: "m4"),
.init(name: nil, data: "m5"),
],
callback: { error in
expect(error).to(beNil())
done()
})
}

let query = ARTDataQuery()
query.direction = .forwards
query.limit = 2

try! channel.history(query) { result, error in
guard let result = result else {
fail("Result is empty"); return
}
expect(error).to(beNil())
expect(result.hasNext).to(beTrue())
expect(result.isLast).to(beFalse())
expect(result.items).to(haveCount(2))
let items = result.items.flatMap({ $0.data as? String })
expect(items.first).to(equal("m1"))
expect(items.last).to(equal("m2"))

result.next { result, error in
guard let result = result else {
fail("Result is empty"); return
}
expect(error).to(beNil())
expect(result.hasNext).to(beTrue())
expect(result.isLast).to(beFalse())
expect(result.items).to(haveCount(2))
let items = result.items.flatMap({ $0.data as? String })
expect(items.first).to(equal("m3"))
expect(items.last).to(equal("m4"))

result.next { result, error in
guard let result = result else {
fail("Result is empty"); return
}
expect(error).to(beNil())
expect(result.hasNext).to(beFalse())
expect(result.isLast).to(beTrue())
expect(result.items).to(haveCount(1))
let items = result.items.flatMap({ $0.data as? String })
expect(items.first).to(equal("m5"))

result.first { result, error in
guard let result = result else {
fail("Result is empty"); return
}
expect(error).to(beNil())
expect(result.hasNext).to(beTrue())
expect(result.isLast).to(beFalse())
expect(result.items).to(haveCount(2))
let items = result.items.flatMap({ $0.data as? String })
expect(items.first).to(equal("m1"))
expect(items.last).to(equal("m2"))
}
}
}
}
}

// RSL2b
context("query arguments") {

Expand Down

0 comments on commit 2a9f75d

Please sign in to comment.