realm.js 1.4 KB

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