spec/javascripts/faye-extension_spec.js in faye-authentication-1.11.0 vs spec/javascripts/faye-extension_spec.js in faye-authentication-1.12
- old
+ new
@@ -1,24 +1,27 @@
describe('Faye extension', function() {
beforeEach(function() {
+ Faye.logger = {error: function() {}};
this.client = new Faye.Client('http://localhost:9296/faye');
jasmine.Ajax.install();
});
afterEach(function() {
jasmine.Ajax.uninstall();
});
describe('Without extension', function() {
it('fails to subscribe', function(done) {
- this.client.subscribe('/foobar').then(undefined, function() {
+ this.client.subscribe('/foobar').then(undefined, function(e) {
+ expect(e.message).toBe('Invalid signature')
done();
});
});
it('fails to publish', function(done) {
- this.client.publish('/foobar', {text: 'whatever'}).then(undefined, function() {
+ this.client.publish('/foobar', {text: 'whatever'}).then(undefined, function(e) {
+ expect(e.message).toBe('Invalid signature')
done();
});
});
});
@@ -69,11 +72,10 @@
});
this.dispatcher = {connectionType: "fake", clientId: '1234', sendMessage: function() {}, selectTransport: function() { }};
spyOn(this.dispatcher, 'sendMessage');
spyOn(this.dispatcher, 'selectTransport');
- Faye.extend(this.dispatcher, Faye.Publisher)
});
it('should add the signature to subscribe message', function(done) {
var self = this;
@@ -314,9 +316,48 @@
'responseText': '{"signatures": [{"channel": "/foo", "clientId": "'+ params['messages[0][clientId]'] +'", "signature": "' + signature_good + '"}]}'
});
}, 1000);
+ });
+
+ it('does not retry if the error is unrelated to authentication', function(done) {
+ other_client = new Faye.Client('http://localhost:9296/faye');
+ auth_extension = new FayeAuthentication(other_client, null, { retry_delay: 100 });
+ tweak_extension = {
+ incoming: function(message, callback) {
+ console.log('message',message)
+ if (message.error) {
+ message.error = 'Not an Authentication error';
+ }
+ callback(message);
+ }
+ }
+ other_client.addExtension(tweak_extension);
+ other_client.addExtension(this.extension);
+
+ jasmine.Ajax.stubRequest('/faye/auth').andReturn({
+ 'responseText': '{"signature": "bad"}'
+ });
+
+ var finished = false;
+ other_client.subscribe('/toto').then(undefined, function() {
+ finished = true;
+ });
+
+ setTimeout(function() {
+
+ // Initial 200ms batching delay
+
+ setTimeout(function() {
+ expect(finished).toBe(true);
+ }, 200 + 80); // 2nd Batching delay + 80 ms
+
+ setTimeout(function() {
+ expect(finished).toBe(true);
+ done();
+ }, 200 + 200); // 2nd Batching delay + 200 ms
+ }, 200);
});
});
});