realm.ts 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import { expect } from 'chai';
  2. import { Realm } from '../../src/models/realm';
  3. import { Client } from '../../src/models/client';
  4. describe('Realm', () => {
  5. describe('#generateClientId', () => {
  6. it('should generate a 36-character UUID, or return function value', () => {
  7. const realm = new Realm();
  8. expect(realm.generateClientId().length).to.eq(36);
  9. expect(realm.generateClientId(() => 'abcd')).to.eq('abcd');
  10. });
  11. });
  12. describe('#setClient', () => {
  13. it('should add client to realm', () => {
  14. const realm = new Realm();
  15. const client = new Client({ id: 'id', token: '' });
  16. realm.setClient(client, 'id');
  17. expect(realm.getClientsIds()).to.deep.eq(['id']);
  18. });
  19. });
  20. describe('#removeClientById', () => {
  21. it('should remove client from realm', () => {
  22. const realm = new Realm();
  23. const client = new Client({ id: 'id', token: '' });
  24. realm.setClient(client, 'id');
  25. realm.removeClientById('id');
  26. expect(realm.getClientById('id')).to.be.undefined;
  27. });
  28. });
  29. describe('#getClientsIds', () => {
  30. it('should reflects on add/remove childs', () => {
  31. const realm = new Realm();
  32. const client = new Client({ id: 'id', token: '' });
  33. realm.setClient(client, 'id');
  34. expect(realm.getClientsIds()).to.deep.eq(['id']);
  35. expect(realm.getClientById('id')).to.eq(client);
  36. realm.removeClientById('id');
  37. expect(realm.getClientsIds()).to.deep.eq([]);
  38. });
  39. });
  40. });