All files / rpc-server/src/__tests__/json-crdt-server util.ts

100% Statements 27/27
100% Branches 0/0
100% Functions 9/9
100% Lines 26/26

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59    1x 1x   1x 1x 1x 1x 1x 1x 1x       1x 1x 1x 1x 1x 1x     1x 1x 1x 1x 1x       1x 1x 1x 1x 1x                                   1x          
import type {ApiTestSetup, JsonCrdtTestSetup} from '../../__demos__/json-crdt-server/__tests__/setup';
 
export const runUtilTests = (_setup: ApiTestSetup) => {
  const setup = _setup as JsonCrdtTestSetup;
 
  describe('util.*', () => {
    describe('util.ping', () => {
      test('returns pong', async () => {
        const {call, stop} = await setup();
        const res = await call('util.ping', undefined);
        expect(res).toBe('pong');
        stop();
      });
    });
 
    describe('util.echo', () => {
      test('returns strings', async () => {
        const {call, stop} = await setup();
        const res = await call('util.echo', 'hello world');
        expect(res).toBe('hello world');
        stop();
      });
 
      test('returns objects', async () => {
        const {call, stop} = await setup();
        const res = await call('util.echo', {foo: 'bar'});
        expect(res).toEqual({foo: 'bar'});
        stop();
      });
    });
 
    describe('util.info', () => {
      test('returns stats object', async () => {
        const {call, stop} = await setup();
        const res = await call('util.info', {});
        expect(res).toMatchObject({
          now: expect.any(Number),
          stats: {
            pubsub: {
              channels: expect.any(Number),
              observers: expect.any(Number),
            },
            presence: {
              rooms: expect.any(Number),
              entries: expect.any(Number),
              observers: expect.any(Number),
            },
            blocks: {
              blocks: expect.any(Number),
              batches: expect.any(Number),
            },
          },
        });
        stop();
      });
    });
  });
};