123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- import { describe, expect, it } from "@jest/globals";
- import { Realm } from '../../src/models/realm';
- import { Client } from '../../src/models/client';
- describe('Realm', () => {
- describe('#generateClientId', () => {
- it('should generate a 36-character UUID, or return function value', () => {
- const realm = new Realm();
- expect(realm.generateClientId().length).toBe(36);
- expect(realm.generateClientId(() => 'abcd')).toBe('abcd');
- });
- });
- 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()).toEqual(['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')).toBeUndefined();
- });
- });
- 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()).toEqual(['id']);
- expect(realm.getClientById('id')).toBe(client);
- realm.removeClientById('id');
- expect(realm.getClientsIds()).toEqual([]);
- });
- });
- });
|