Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/jsxc/jsxc.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorsualko <klaus@jsxc.org>2018-01-11 15:17:52 +0300
committersualko <klaus@jsxc.org>2018-01-11 15:17:52 +0300
commit72478add041e6e887a263eb83270d4ea8a50e372 (patch)
tree74d2729c74e2c6cdc15a2cfd76d7c690070e67ed /test
parent0e29b6f3e47392c7b9d3c159814fd90418515c5d (diff)
beautify tests
Diffstat (limited to 'test')
-rw-r--r--test/AccountStub.ts30
-rw-r--r--test/Client.ts50
-rw-r--r--test/DiscoInfo.sp2ec.ts17
-rw-r--r--test/HookRepository.spec.ts146
-rw-r--r--test/JID.spec.ts160
-rw-r--r--test/Pipe.spec.ts170
-rw-r--r--test/Storage.spec.ts82
-rw-r--r--test/connection/xmpp/handlers/presence.spec.ts60
8 files changed, 366 insertions, 349 deletions
diff --git a/test/AccountStub.ts b/test/AccountStub.ts
index b1d33165..2510455c 100644
--- a/test/AccountStub.ts
+++ b/test/AccountStub.ts
@@ -2,21 +2,21 @@ import JID from '../src/JID'
export default class Account {
- public getJID():JID {
- return new JID('foo@bar')
- }
+ public getJID(): JID {
+ return new JID('foo@bar')
+ }
- public getContact() {
- return {
- setStatus: (status) => {},
- setPresence: (resource, status) => {},
- setResource: (resource) => {}
- }
- }
+ public getContact() {
+ return {
+ setStatus: (status) => { },
+ setPresence: (resource, status) => { },
+ setResource: (resource) => { }
+ }
+ }
- public getConnection() {
- return {
- sendSubscriptionAnswer: (jid, response) => {}
- }
- }
+ public getConnection() {
+ return {
+ sendSubscriptionAnswer: (jid, response) => { }
+ }
+ }
}
diff --git a/test/Client.ts b/test/Client.ts
index 92371f41..303fe89b 100644
--- a/test/Client.ts
+++ b/test/Client.ts
@@ -1,41 +1,41 @@
import JID from '../src/JID'
-import Account from './Account'
-import {PluginInterface} from '../src/PluginInterface'
+import Account from './AccountStub'
+import { IPlugin as PluginInterface } from '../src/plugin/AbstractPlugin'
export default class Client {
- private static account = new Account();
+ private static account = new Account();
- public static init() {}
+ public static init() { }
- public static addConnectionPlugin(plugin:PluginInterface) {}
+ public static addConnectionPlugin(plugin: PluginInterface) { }
- public static addPreSendMessageHook(hook:(Message, Builder)=>void, position?:number) {}
+ public static addPreSendMessageHook(hook: (Message, Builder) => void, position?: number) { }
- public static hasFocus() {}
+ public static hasFocus() { }
- public static isExtraSmallDevice():boolean {
- return false;
- }
+ public static isExtraSmallDevice(): boolean {
+ return false;
+ }
- public static isDebugMode():boolean {
- return false;
- }
+ public static isDebugMode(): boolean {
+ return false;
+ }
- public static getStorage() {}
+ public static getStorage() { }
- public static getAccout(jid:JID):Account;
- public static getAccout(uid?:string):Account;
- public static getAccout():Account {
- return Client.account;
- }
+ public static getAccout(jid: JID): Account;
+ public static getAccout(uid?: string): Account;
+ public static getAccout(): Account {
+ return Client.account;
+ }
- public static createAccount(boshUrl: string, jid: string, sid: string, rid:string);
- public static createAccount(boshUrl: string, jid: string, password: string);
- public static createAccount() {
+ public static createAccount(boshUrl: string, jid: string, sid: string, rid: string);
+ public static createAccount(boshUrl: string, jid: string, password: string);
+ public static createAccount() {
- }
+ }
- public static removeAccount(account:Account) {
+ public static removeAccount(account: Account) {
- }
+ }
}
diff --git a/test/DiscoInfo.sp2ec.ts b/test/DiscoInfo.sp2ec.ts
new file mode 100644
index 00000000..470fc5c8
--- /dev/null
+++ b/test/DiscoInfo.sp2ec.ts
@@ -0,0 +1,17 @@
+import { expect } from 'chai';
+import * as sinon from 'sinon';
+import 'mocha';
+
+import DiscoInfo from '../src/DiscoInfo'
+
+describe('JID', function() {
+ it('should', function() {
+ let di = new DiscoInfo([{
+ category: 'client',
+ name: 'Exodus 0.9.1',
+ type: 'pc'
+ }], ['http://jabber.org/protocol/caps', 'http://jabber.org/protocol/disco#info', 'http://jabber.org/protocol/disco#items', 'http://jabber.org/protocol/muc']);
+
+ console.log('caps version', 'QgayPKawpkPSDYmwT/WM94uAlu0=', di.getCapsVersion());
+ })
+});
diff --git a/test/HookRepository.spec.ts b/test/HookRepository.spec.ts
index 0cb542da..d8d25835 100644
--- a/test/HookRepository.spec.ts
+++ b/test/HookRepository.spec.ts
@@ -1,112 +1,112 @@
-import {expect} from 'chai';
+import { expect } from 'chai';
import * as sinon from 'sinon';
import 'mocha';
-import HookRepository from '../src/HookRepository'
+import HookRepository from '../src/util/HookRepository'
const NOT_EXPECTED_TO_BE_CALLED = 1000;
describe('HookRepository', () => {
- let hookRepository;
+ let hookRepository;
- beforeEach(() => {
- this.hookRepository = new HookRepository();
- });
+ beforeEach(() => {
+ this.hookRepository = new HookRepository();
+ });
- it('should fire one matching hook', () => {
- let count = 0;
+ it('should fire one matching hook', () => {
+ let count = 0;
- this.hookRepository.registerHook('foo', () => {
- count++;
- })
+ this.hookRepository.registerHook('foo', () => {
+ count++;
+ })
- this.hookRepository.registerHook('bar', () => {
- count+=NOT_EXPECTED_TO_BE_CALLED;
- })
+ this.hookRepository.registerHook('bar', () => {
+ count += NOT_EXPECTED_TO_BE_CALLED;
+ })
- this.hookRepository.trigger('foo');
+ this.hookRepository.trigger('foo');
- expect(count).equals(1);
- })
+ expect(count).equals(1);
+ })
- it('should fire multiple matching hooks', () => {
- let count = 0;
+ it('should fire multiple matching hooks', () => {
+ let count = 0;
- this.hookRepository.registerHook('foo', () => {
- count++;
- })
+ this.hookRepository.registerHook('foo', () => {
+ count++;
+ })
- this.hookRepository.registerHook('foo', () => {
- count++;
- })
+ this.hookRepository.registerHook('foo', () => {
+ count++;
+ })
- this.hookRepository.registerHook('bar', () => {
- count+=NOT_EXPECTED_TO_BE_CALLED;
- })
+ this.hookRepository.registerHook('bar', () => {
+ count += NOT_EXPECTED_TO_BE_CALLED;
+ })
- this.hookRepository.trigger('foo');
+ this.hookRepository.trigger('foo');
- expect(count).equals(2);
- })
+ expect(count).equals(2);
+ })
- it('should fire only hooks with matching prefix', () => {
- let count = 0;
+ it('should fire only hooks with matching prefix', () => {
+ let count = 0;
- this.hookRepository.registerHook('foo:bar', () => {
- count++;
- })
+ this.hookRepository.registerHook('foo:bar', () => {
+ count++;
+ })
- this.hookRepository.registerHook('foo', () => {
- count++;
- })
+ this.hookRepository.registerHook('foo', () => {
+ count++;
+ })
- this.hookRepository.registerHook('fo', () => {
- count+=NOT_EXPECTED_TO_BE_CALLED;
- })
+ this.hookRepository.registerHook('fo', () => {
+ count += NOT_EXPECTED_TO_BE_CALLED;
+ })
- this.hookRepository.registerHook('foo:', () => {
- count+=NOT_EXPECTED_TO_BE_CALLED;
- })
+ this.hookRepository.registerHook('foo:', () => {
+ count += NOT_EXPECTED_TO_BE_CALLED;
+ })
- this.hookRepository.registerHook('bar', () => {
- count+=NOT_EXPECTED_TO_BE_CALLED;
- })
+ this.hookRepository.registerHook('bar', () => {
+ count += NOT_EXPECTED_TO_BE_CALLED;
+ })
- this.hookRepository.trigger('foo:bar');
+ this.hookRepository.trigger('foo:bar');
- expect(count).equals(2);
- })
+ expect(count).equals(2);
+ })
- it('should not fire removed hooks', () => {
- let count = 0;
+ it('should not fire removed hooks', () => {
+ let count = 0;
- let func1 = () => {
- count++;
- }
+ let func1 = () => {
+ count++;
+ }
- let func2 = () => {
- count+=10;
- }
+ let func2 = () => {
+ count += 10;
+ }
- this.hookRepository.registerHook('foo', func1)
- this.hookRepository.registerHook('foo', func2)
+ this.hookRepository.registerHook('foo', func1)
+ this.hookRepository.registerHook('foo', func2)
- this.hookRepository.trigger('foo')
+ this.hookRepository.trigger('foo')
- this.hookRepository.removeHook('foo', func2);
+ this.hookRepository.removeHook('foo', func2);
- this.hookRepository.trigger('foo')
+ this.hookRepository.trigger('foo')
- expect(count).equals(12);
- })
+ expect(count).equals(12);
+ })
- it('should not crash if you remove hooks for unexisting event names', () => {
- this.hookRepository.removeHook('dummy', ()=>{})
- })
+ it('should not crash if you remove hooks for unexisting event names', () => {
+ this.hookRepository.removeHook('dummy', () => { })
+ })
- it('should not crash if you remove unregistered hooks', () => {
- this.hookRepository.registerHook('foo', () => {return 1;})
+ it('should not crash if you remove unregistered hooks', () => {
+ this.hookRepository.registerHook('foo', () => { return 1; })
- this.hookRepository.removeHook('foo', () => {return 2;})
- })
+ this.hookRepository.removeHook('foo', () => { return 2; })
+ })
});
diff --git a/test/JID.spec.ts b/test/JID.spec.ts
index c578cd89..eb3d1274 100644
--- a/test/JID.spec.ts
+++ b/test/JID.spec.ts
@@ -1,91 +1,91 @@
-import {expect} from 'chai';
+import { expect } from 'chai';
import * as sinon from 'sinon';
import 'mocha';
import JID from '../src/JID'
class JIDDummy {
- constructor(public node:string, public domain:string, public resource?:string) {
-
- }
-
- public toEscapedString() {
- let node = this.node.replace(/^\s+|\s+$/g, '')
- .replace(/\\/g, "\\5c")
- .replace(/ /g, "\\20")
- .replace(/\"/g, "\\22")
- .replace(/\&/g, "\\26")
- .replace(/\'/g, "\\27")
- .replace(/\//g, "\\2f")
- .replace(/:/g, "\\3a")
- .replace(/</g, "\\3c")
- .replace(/>/g, "\\3e")
- .replace(/@/g, "\\40");
-
- return node + '@' + this.domain + ((this.resource) ? '/' + this.resource : '');
- }
-
- public toUnescapedString() {
- return this.node + '@' + this.domain + ((this.resource) ? '/' + this.resource : '');
- }
+ constructor(public node: string, public domain: string, public resource?: string) {
+
+ }
+
+ public toEscapedString() {
+ let node = this.node.replace(/^\s+|\s+$/g, '')
+ .replace(/\\/g, "\\5c")
+ .replace(/ /g, "\\20")
+ .replace(/\"/g, "\\22")
+ .replace(/\&/g, "\\26")
+ .replace(/\'/g, "\\27")
+ .replace(/\//g, "\\2f")
+ .replace(/:/g, "\\3a")
+ .replace(/</g, "\\3c")
+ .replace(/>/g, "\\3e")
+ .replace(/@/g, "\\40");
+
+ return node + '@' + this.domain + ((this.resource) ? '/' + this.resource : '');
+ }
+
+ public toUnescapedString() {
+ return this.node + '@' + this.domain + ((this.resource) ? '/' + this.resource : '');
+ }
}
describe('JID', function() {
- let jids = [
- new JIDDummy('foo', 'localhost'),
- new JIDDummy('foo.bar', 'localhost'),
- new JIDDummy('foo', 'bar.local'),
- new JIDDummy('foo.bar', 'local.host'),
- new JIDDummy('foo.bar', 'localhost', 'res'),
- new JIDDummy('foo.bar', 'local.host', 'random'),
- new JIDDummy('foo.bar', 'local.host', 'rand/om'),
- new JIDDummy('äöüßᚹᛦᛚᚳᚢᛗணோம்', 'local.host', '私はガラス'),
- new JIDDummy('foo bar', 'local.host', 'rand om'),
- new JIDDummy('foo "&\'":<>@bar', 'your.local.host')
- ];
-
- it('should split a JID in its components', function() {
- jids.forEach((dummy) => {
- let jid = new JID(dummy.toEscapedString());
-
- expect(jid.node).equals(dummy.node);
- expect(jid.domain).equals(dummy.domain);
- expect(jid.resource).equals(dummy.resource);
- });
- });
-
- it('should escape a JID', function() {
- jids.forEach((dummy) => {
- let jid = new JID(dummy.toEscapedString());
-
- expect(jid.toEscapedString()).equals(dummy.toEscapedString());
- });
- });
-
- it('should unescape a JID', function() {
- jids.forEach((dummy) => {
- let jid = new JID(dummy.toEscapedString());
-
- expect(jid.toString()).equals(dummy.toUnescapedString());
- });
- });
-
- it('should lower-case node and domain part', function() {
- let jid1 = new JID('Foo.Bar@Local.Host/Random');
- let jid2 = new JID('fOo.baR@loCAL.HOST/Random');
-
- expect(jid1.node).equals(jid2.node);
- expect(jid1.domain).equals(jid2.domain);
-
- expect(jid1.toString()).equals(jid2.toString());
- });
-
- it('should not lower-case resource part', function() {
- let jid1 = new JID('Foo.Bar@Local.Host/RanDom');
- let jid2 = new JID('fOo.baR@loCAL.HOST/RANDOM');
-
- expect(jid1.resource).not.equals(jid2.resource);
- expect(jid1.toString()).not.equal(jid2.toString());
- });
+ let jids = [
+ new JIDDummy('foo', 'localhost'),
+ new JIDDummy('foo.bar', 'localhost'),
+ new JIDDummy('foo', 'bar.local'),
+ new JIDDummy('foo.bar', 'local.host'),
+ new JIDDummy('foo.bar', 'localhost', 'res'),
+ new JIDDummy('foo.bar', 'local.host', 'random'),
+ new JIDDummy('foo.bar', 'local.host', 'rand/om'),
+ new JIDDummy('äöüßᚹᛦᛚᚳᚢᛗணோம்', 'local.host', '私はガラス'),
+ new JIDDummy('foo bar', 'local.host', 'rand om'),
+ new JIDDummy('foo "&\'":<>@bar', 'your.local.host')
+ ];
+
+ it('should split a JID in its components', function() {
+ jids.forEach((dummy) => {
+ let jid = new JID(dummy.toEscapedString());
+
+ expect(jid.node).equals(dummy.node);
+ expect(jid.domain).equals(dummy.domain);
+ expect(jid.resource).equals(dummy.resource);
+ });
+ });
+
+ it('should escape a JID', function() {
+ jids.forEach((dummy) => {
+ let jid = new JID(dummy.toEscapedString());
+
+ expect(jid.toEscapedString()).equals(dummy.toEscapedString());
+ });
+ });
+
+ it('should unescape a JID', function() {
+ jids.forEach((dummy) => {
+ let jid = new JID(dummy.toEscapedString());
+
+ expect(jid.toString()).equals(dummy.toUnescapedString());
+ });
+ });
+
+ it('should lower-case node and domain part', function() {
+ let jid1 = new JID('Foo.Bar@Local.Host/Random');
+ let jid2 = new JID('fOo.baR@loCAL.HOST/Random');
+
+ expect(jid1.node).equals(jid2.node);
+ expect(jid1.domain).equals(jid2.domain);
+
+ expect(jid1.toString()).equals(jid2.toString());
+ });
+
+ it('should not lower-case resource part', function() {
+ let jid1 = new JID('Foo.Bar@Local.Host/RanDom');
+ let jid2 = new JID('fOo.baR@loCAL.HOST/RANDOM');
+
+ expect(jid1.resource).not.equals(jid2.resource);
+ expect(jid1.toString()).not.equal(jid2.toString());
+ });
});
diff --git a/test/Pipe.spec.ts b/test/Pipe.spec.ts
index a767a5ec..17fa034c 100644
--- a/test/Pipe.spec.ts
+++ b/test/Pipe.spec.ts
@@ -1,91 +1,91 @@
-import {expect} from 'chai';
+import { expect } from 'chai';
import * as sinon from 'sinon';
import 'mocha';
-import Pipe from '../src/Pipe'
+import Pipe from '../src/util/Pipe'
describe('Pipe', () => {
- it('should return the same pipe for the same name', () => {
- let pipeA = Pipe.get('dummy');
- let pipeB = Pipe.get('dummy');
-
- expect(pipeA).equals(pipeB);
- })
-
- it('should return different pipes for different names', () => {
- let pipeA = Pipe.get('dummyA');
- let pipeB = Pipe.get('dummyB');
-
- expect(pipeA).not.equals(pipeB);
- })
-
- it('should run an empty pipe', () => {
- let pipeA = Pipe.get('dummy_empty');
-
- return pipeA.run('A', 'B', 1234).then(([arg1, arg2, arg3]) => {
- expect(arg1).equals('A');
- expect(arg2).equals('B');
- expect(arg3).equals(1234);
- });
- })
-
- it('should progress in order with distinct priority', () => {
- let pipeA = Pipe.get('dummy_distinct');
-
- pipeA.addProcessor(function(a, b, c) {
- return Promise.resolve([a + 'a', b + 'b', c * 2]);
- }, 20);
-
- pipeA.addProcessor(function(a, b, c) {
- return Promise.resolve([a + 'c', b + 'd', c + 1]);
- }, 30);
-
- pipeA.addProcessor(function(a, b, c){
- return Promise.resolve([a + 'e', b + 'f', c * 3]);
- }, 80);
-
- return pipeA.run('A', 'B', 1234).then(([arg1, arg2, arg3]) => {
- expect(arg1).equals('Aace');
- expect(arg2).equals('Bbdf');
- expect(arg3).equals(7407);
- });
- })
-
- it('should progress in order with multiple priority', () => {
- let pipeA = Pipe.get('dummy_multiple');
-
- pipeA.addProcessor(function(a, b, c){
- return [a + 'a', b + 'b', c * 2];
- }, 20);
-
- pipeA.addProcessor(function(a, b, c){
- return Promise.resolve([a + 'c', b + 'd', c + 1]);
- }, 20);
-
- pipeA.addProcessor(function(a, b, c){
- return Promise.resolve([a + 'e', b + 'f', c * 3]);
- }, 20);
-
- return pipeA.run('A', 'B', 1234).then(([arg1, arg2, arg3]) => {
- expect(arg1).equals('Aace');
- expect(arg2).equals('Bbdf');
- expect(arg3).equals(7407);
- });
- })
-
- it('should reject processor with invalid priority', () => {
- let pipeA = Pipe.get('dummy_invalid');
-
- expect(() => {
- pipeA.addProcessor(function(...args){return Promise.resolve();}, -1);
- }).to.throw();
-
- expect(() => {
- pipeA.addProcessor(function(...args){return Promise.resolve();}, 101);
- }).to.throw();
-
- expect(() => {
- pipeA.addProcessor(function(...args){return Promise.resolve();}, 'abc');
- }).to.throw();
- })
+ it('should return the same pipe for the same name', () => {
+ let pipeA = Pipe.get('dummy');
+ let pipeB = Pipe.get('dummy');
+
+ expect(pipeA).equals(pipeB);
+ })
+
+ it('should return different pipes for different names', () => {
+ let pipeA = Pipe.get('dummyA');
+ let pipeB = Pipe.get('dummyB');
+
+ expect(pipeA).not.equals(pipeB);
+ })
+
+ it('should run an empty pipe', () => {
+ let pipeA = Pipe.get('dummy_empty');
+
+ return pipeA.run('A', 'B', 1234).then(([arg1, arg2, arg3]) => {
+ expect(arg1).equals('A');
+ expect(arg2).equals('B');
+ expect(arg3).equals(1234);
+ });
+ })
+
+ it('should progress in order with distinct priority', () => {
+ let pipeA = Pipe.get('dummy_distinct');
+
+ pipeA.addProcessor(function(a, b, c) {
+ return Promise.resolve([a + 'a', b + 'b', c * 2]);
+ }, 20);
+
+ pipeA.addProcessor(function(a, b, c) {
+ return Promise.resolve([a + 'c', b + 'd', c + 1]);
+ }, 30);
+
+ pipeA.addProcessor(function(a, b, c) {
+ return Promise.resolve([a + 'e', b + 'f', c * 3]);
+ }, 80);
+
+ return pipeA.run('A', 'B', 1234).then(([arg1, arg2, arg3]) => {
+ expect(arg1).equals('Aace');
+ expect(arg2).equals('Bbdf');
+ expect(arg3).equals(7407);
+ });
+ })
+
+ it('should progress in order with multiple priority', () => {
+ let pipeA = Pipe.get('dummy_multiple');
+
+ pipeA.addProcessor(function(a, b, c) {
+ return [a + 'a', b + 'b', c * 2];
+ }, 20);
+
+ pipeA.addProcessor(function(a, b, c) {
+ return Promise.resolve([a + 'c', b + 'd', c + 1]);
+ }, 20);
+
+ pipeA.addProcessor(function(a, b, c) {
+ return Promise.resolve([a + 'e', b + 'f', c * 3]);
+ }, 20);
+
+ return pipeA.run('A', 'B', 1234).then(([arg1, arg2, arg3]) => {
+ expect(arg1).equals('Aace');
+ expect(arg2).equals('Bbdf');
+ expect(arg3).equals(7407);
+ });
+ })
+
+ it('should reject processor with invalid priority', () => {
+ let pipeA = Pipe.get('dummy_invalid');
+
+ expect(() => {
+ pipeA.addProcessor(function(...args) { return Promise.resolve(); }, -1);
+ }).to.throw();
+
+ expect(() => {
+ pipeA.addProcessor(function(...args) { return Promise.resolve(); }, 101);
+ }).to.throw();
+
+ expect(() => {
+ pipeA.addProcessor(function(...args) { return Promise.resolve(); }, 'abc');
+ }).to.throw();
+ })
});
diff --git a/test/Storage.spec.ts b/test/Storage.spec.ts
index 6c4c8d07..0c4c9bc8 100644
--- a/test/Storage.spec.ts
+++ b/test/Storage.spec.ts
@@ -1,64 +1,64 @@
-import {expect} from 'chai';
+import { expect } from 'chai';
import * as sinon from 'sinon';
import 'mocha';
import Storage from '../src/Storage'
describe('Storage', function() {
- let storage;
+ let storage;
- before(function() {
- storage = new Storage();
- })
+ before(function() {
+ storage = new Storage();
+ })
- after(function() {
- storage.getBackend().clear();
- })
+ after(function() {
+ storage.getBackend().clear();
+ })
- it('should mark storage as not conform');
+ it('should mark storage as not conform');
- it('should mark storage as conform');
+ it('should mark storage as conform');
- it('should return the right prefix', function() {
- expect(storage.getPrefix()).equals('jsxc2:');
- })
+ it('should return the right prefix', function() {
+ expect(storage.getPrefix()).equals('jsxc2:');
+ })
- it('should properly generate keys', function() {
- expect(storage.generateKey('foo')).equals('foo');
- expect(storage.generateKey('foo', 'bar')).equals('foo:bar');
- expect(storage.generateKey('foo', 'bar', '1')).equals('foo:bar:1');
- expect(storage.generateKey('foo', 'bar', '1', '2')).equals('foo:bar:1:2');
- })
+ it('should properly generate keys', function() {
+ expect(storage.generateKey('foo')).equals('foo');
+ expect(storage.generateKey('foo', 'bar')).equals('foo:bar');
+ expect(storage.generateKey('foo', 'bar', '1')).equals('foo:bar:1');
+ expect(storage.generateKey('foo', 'bar', '1', '2')).equals('foo:bar:1:2');
+ })
- it('should save key/value pairs', function() {
- let data = [
- { foo: 'bar' },
- { foo: true },
- { foo: { foo: 'bar' } }
- ];
+ it('should save key/value pairs', function() {
+ let data = [
+ { foo: 'bar' },
+ { foo: true },
+ { foo: { foo: 'bar' } }
+ ];
- let spy = sinon.spy(storage.getBackend(), 'setItem');
+ let spy = sinon.spy(storage.getBackend(), 'setItem');
- data.forEach(function(pair, index) {
- let key = Object.keys(pair)[0];
- let value = pair[key];
+ data.forEach(function(pair, index) {
+ let key = Object.keys(pair)[0];
+ let value = pair[key];
- storage.setItem(key, value);
+ storage.setItem(key, value);
- let expectedStoredValue = value;
+ let expectedStoredValue = value;
- if (typeof value === 'object') {
- expectedStoredValue = JSON.stringify(value);
- }
+ if (typeof value === 'object') {
+ expectedStoredValue = JSON.stringify(value);
+ }
- expect(spy.args[index][0]).equals('jsxc2:' + key);
- expect(spy.args[index][1]).equals(expectedStoredValue);
- });
- })
+ expect(spy.args[index][0]).equals('jsxc2:' + key);
+ expect(spy.args[index][1]).equals(expectedStoredValue);
+ });
+ })
- it('should save key/value pairs of a specific type')
+ it('should save key/value pairs of a specific type')
- it('should properly retrieve key/value pairs')
+ it('should properly retrieve key/value pairs')
- it('should properly retrieve key/value pairs of a specific type')
+ it('should properly retrieve key/value pairs of a specific type')
});
diff --git a/test/connection/xmpp/handlers/presence.spec.ts b/test/connection/xmpp/handlers/presence.spec.ts
index f3f2abaa..87e44a7b 100644
--- a/test/connection/xmpp/handlers/presence.spec.ts
+++ b/test/connection/xmpp/handlers/presence.spec.ts
@@ -1,51 +1,51 @@
-import {expect} from 'chai';
+import { expect } from 'chai';
import * as sinon from 'sinon';
import 'mocha';
-import onPresence from '../../../../src/connection/xmpp/handlers/presence'
+import PresenceHandler from '../../../../src/connection/xmpp/handlers/presence'
import Client from '../../../../src/Client'
import AccountStub from '../../../AccountStub'
import Log from '../../../../src/util/Log'
describe('Presence handler', () => {
- before(function() {
- let account = new AccountStub;
- let getAccountStub = sinon.stub(Client, 'getAccout').returns(account);
+ before(function() {
+ let account = new AccountStub;
+ let getAccountStub = sinon.stub(Client, 'getAccout').returns(account);
- // let logStub = sinon.stub(Log, 'log').callsFake(function(level, message:string, data?:any){
- //
- // });
- });
+ // let logStub = sinon.stub(Log, 'log').callsFake(function(level, message:string, data?:any){
+ //
+ // });
+ });
- it('should ignore own presence notification', function() {
- let pres = $pres({
- type: '',
- from: Client.getAccout().getJID().bare
- });
+ it('should ignore own presence notification', function() {
+ let pres = $pres({
+ type: '',
+ from: Client.getAccout().getJID().bare
+ });
- let presenceHandlerReturn = onPresence(pres.tree());
+ let presenceHandlerReturn = onPresence(pres.tree());
- expect(presenceHandlerReturn).equals(1);
- });
+ expect(presenceHandlerReturn).to.be.true;
+ });
- it('should abort if stanza is of type "error"', function() {
- let pres = $pres({
- type: 'error',
- from: 'foo2@bar'
- });
+ it('should abort if stanza is of type "error"', function() {
+ let pres = $pres({
+ type: 'error',
+ from: 'foo2@bar'
+ });
- let presenceHandlerReturn = onPresence(pres.tree());
+ let presenceHandlerReturn = onPresence(pres.tree());
- expect(presenceHandlerReturn).equals(2);
- })
+ expect(presenceHandlerReturn).to.be.true;
+ })
- it('should process a subscription request');
+ it('should process a subscription request');
- it('should set text status for contact');
+ it('should set text status for contact');
- it('should set presence for resource and not change contact presence');
+ it('should set presence for resource and not change contact presence');
- it('should set presence for resource and change contact presence');
+ it('should set presence for resource and change contact presence');
- it('should reset ressource');
+ it('should reset ressource');
});