Basic integration test

This commit is contained in:
claudemiro
2016-01-18 00:41:06 -02:00
parent f81a365e0c
commit 1971da652f
2 changed files with 99 additions and 0 deletions
+24
View File
@@ -0,0 +1,24 @@
<html>
<head>
<meta charset="utf-8">
<title>Pusher Spec</title>
<link href="https://cdn.rawgit.com/mochajs/mocha/2.2.5/mocha.css" rel="stylesheet" />
</head>
<body>
<div id="mocha"></div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/mocha/2.3.4/mocha.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/chai/3.4.1/chai.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/pusher/3.0.0/pusher.js"></script>
<script>mocha.setup('bdd')</script>
<script src="test.pusher.js"></script>
<script>
mocha.checkLeaks();
mocha.globals(['jQuery', 'Pusher']);
mocha.run();
</script>
</body>
</html>
+75
View File
@@ -0,0 +1,75 @@
var assert = chai.assert;
var APP_KEY = "7324d55a5eeb8f554761";
var HOST = "localhost";
var PORT = 8080;
Pusher.log = function(msg) {
console.log(msg);
};
function getPusher() {
return new Pusher(APP_KEY, {
wsHost: HOST,
wsPort: PORT,
enabledTransports: ["ws"],
disabledTransports: ["flash"]
});
}
describe("Pusher", function() {
describe("connection", function() {
it("should connect sucessfully", function(done) {
var pusher = getPusher();
pusher.connection.bind('connected', function() {
assert.ok(true, "Connected");
done();
});
});
it("should not connect", function(done) {
var pusher = new Pusher("INVALID_APP_KEY", {
wsHost: HOST,
wsPort: PORT,
enabledTransports: ["ws"],
disabledTransports: ["flash"]
});
pusher.connection.bind('disconnected', function() {
assert.ok(true, "Not Connected");
done();
});
});
}); // connection
describe("subscription", function() {
it("should connect to a channel", function(done) {
var pusher = getPusher();
var channel = pusher.subscribe('public-channel');
channel.bind("pusher:subscription_succeeded", function(data) {
assert.ok(true, "Connected to the channel");
done();
});
});
}); // subscription
describe("events", function() {
it('should not allowed client events on public channels', function(done) {
var pusher = getPusher();
var channel = pusher.subscribe('public-channel');
channel.bind("pusher:subscription_succeeded", function(data) {
channel.trigger("client-message", "The message");
});
pusher.bind("pusher:error", function(data) {
assert.ok(true, "Expected error");
done();
});
});
}); // events
});