afrokick d46628067b Merge branch 'master' into refactoring/ts
# Conflicts:
#	src/models/realm.js
#	test/services/checkBrokenConnections/index.ts
2019-12-15 13:09:49 +03:00

50 lines
1.4 KiB
TypeScript

import { expect } from 'chai';
import { Realm } from '../../src/models/realm';
import { Client } from '../../src/models/client';
describe('Realm', () => {
describe('#generateClientId', () => {
it('should generate a 36-character UUID', () => {
const realm = new Realm();
expect(realm.generateClientId().length).to.eq(36);
});
});
describe('#setClient', () => {
it('should add client to realm', () => {
const realm = new Realm();
const client = new Client({ id: 'id', token: '' });
realm.setClient(client, 'id');
expect(realm.getClientsIds()).to.deep.eq(['id']);
});
});
describe('#removeClientById', () => {
it('should remove client from realm', () => {
const realm = new Realm();
const client = new Client({ id: 'id', token: '' });
realm.setClient(client, 'id');
realm.removeClientById('id');
expect(realm.getClientById('id')).to.be.undefined;
});
});
describe('#getClientsIds', () => {
it('should reflects on add/remove childs', () => {
const realm = new Realm();
const client = new Client({ id: 'id', token: '' });
realm.setClient(client, 'id');
expect(realm.getClientsIds()).to.deep.eq(['id']);
expect(realm.getClientById('id')).to.eq(client);
realm.removeClientById('id');
expect(realm.getClientsIds()).to.deep.eq([]);
});
});
});