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

RTP10e #338

Merged
merged 3 commits into from
Apr 5, 2016
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
4 changes: 2 additions & 2 deletions Source/ARTAuth.m
Original file line number Diff line number Diff line change
Expand Up @@ -336,10 +336,10 @@ - (NSString *)getClientId {
if ([self.tokenDetails.clientId isEqual:@"*"])
// Any client
return nil;
else
else if (self.tokenDetails.clientId)
return self.tokenDetails.clientId;
}
else if (self.options) {
if (self.options) {
return self.options.clientId;
}
else {
Expand Down
100 changes: 100 additions & 0 deletions Spec/RealtimeClientPresence.swift
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,106 @@ class RealtimeClientPresence: QuickSpec {

}

// RTP10
context("leave") {

// RTP10e
it("should result in an error immediately if the client is anonymous") {
let client = ARTRealtime(options: AblyTests.commonAppSetup())
defer { client.close() }
let channel = client.channels.get("test")

waitUntil(timeout: testTimeout) { done in
channel.presence.leave(nil) { error in
expect(error!.message).to(contain("attempted to publish presence message without clientId"))
done()
}
}
}

// RTP10e
it("should result in an error immediately if the channel is DETACHED") {
let options = AblyTests.commonAppSetup()
options.clientId = "john"
let client = ARTRealtime(options: options)
defer { client.close() }
let channel = client.channels.get("test")

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

channel.detach()

waitUntil(timeout: testTimeout) { done in
channel.presence.leave(nil) { error in
expect(error!.message).to(contain("invalid channel state"))
done()
}
}
}

// RTP10e
it("should result in an error immediately if the channel is FAILED") {
let options = AblyTests.commonAppSetup()
options.clientId = "john"
let client = ARTRealtime(options: options)
defer { client.close() }
let channel = client.channels.get("test")

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

channel.onError(AblyTests.newErrorProtocolMessage())

waitUntil(timeout: testTimeout) { done in
channel.presence.leave(nil) { error in
expect(error!.message).to(contain("invalid channel state"))
done()
}
}
}

// RTP10e
it("should result in an error if the client does not have required presence permission") {
let options = AblyTests.clientOptions()
options.token = getTestToken(capability: "{ \"cannotpresence:other\":[\"publish\"] }")
options.clientId = "john"
let client = ARTRealtime(options: options)
defer { client.close() }
let channel = client.channels.get("cannotpresence")

waitUntil(timeout: testTimeout) { done in
channel.presence.leaveClient("other", data: nil) { error in
expect(error!.message).to(contain("Channel denied access based on given capability"))
done()
}
}
}

// RTP10e
it("should result in an error if Ably service determines that the client is unidentified") {
let client = ARTRealtime(options: AblyTests.commonAppSetup())
defer { client.close() }
let channel = client.channels.get("test")

waitUntil(timeout: testTimeout) { done in
channel.presence.leave(nil) { error in
expect(error!.message).to(contain("presence message without clientId"))
done()
}
}
}

}

// RTP15e
let cases: [String:(ARTRealtimePresence, Optional<(ARTErrorInfo?)->Void>)->()] = [
"enterClient": { $0.enterClient("john", data: nil, callback: $1) },
Expand Down