Skip to content

Commit

Permalink
RSP5 (#418)
Browse files Browse the repository at this point in the history
  • Loading branch information
ricardopereira authored and tcard committed Apr 28, 2016
1 parent 2564fb1 commit b5b611d
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions Spec/RestClientPresence.swift
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,50 @@ class RestClientPresence: QuickSpec {

}

// RSP5
it("presence messages retrieved are decoded in the same way that messages are decoded") {
let options = AblyTests.commonAppSetup()
let client = ARTRest(options: options)
let channel = client.channels.get("test")

let expectedData = ["test":1]
var decodeNumberOfCalls = 0
let hook = ARTBaseMessage.testSuite_injectIntoClassMethod(#selector(ARTBaseMessage.decodeWithEncoder(_:error:))) {
decodeNumberOfCalls += 1
}
defer { hook?.remove() }

waitUntil(timeout: testTimeout) { done in
channel.publish(nil, data: expectedData) { _ in done() }
}

var realtime = ARTRealtime(options: options)
defer { realtime.close() }
waitUntil(timeout: testTimeout) { done in
realtime.channels.get("test").presence.enterClient("john", data: expectedData) { _ in done() }
}

typealias Done = () -> Void
func checkReceivedMessage(done: Done) -> (ARTPaginatedResult?, ARTErrorInfo?) -> Void {
return { membersPage, error in
expect(error).to(beNil())
let member = membersPage!.items[0] as! ARTBaseMessage
expect(member.data as? NSDictionary).to(equal(expectedData))
done()
}
}

waitUntil(timeout: testTimeout) { done in
channel.history(checkReceivedMessage(done))
}

waitUntil(timeout: testTimeout) { done in
channel.presence.history(checkReceivedMessage(done))
}

expect(decodeNumberOfCalls).to(equal(2))
}

}
}
}

0 comments on commit b5b611d

Please sign in to comment.