Commands.test.ts 1.79 KB
Newer Older
yogevbd's avatar
yogevbd committed
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
import * as _ from 'lodash';
import { mock, verify, instance, deepEqual, when, anything, anyString } from 'ts-mockito';

import { Commands } from './Commands';
import { NativeCommandsSender } from '../adapters/NativeCommandsSender';
import { Notification } from '../interfaces/Notification';

describe('Commands', () => {
  let uut: Commands;
  let mockedNativeCommandsSender: NativeCommandsSender;

  beforeEach(() => {
    mockedNativeCommandsSender = mock(NativeCommandsSender);

    uut = new Commands(
      instance(mockedNativeCommandsSender)
    );
  });

  describe('getInitialNotification', () => {
    it('sends getInitialNotification to native', () => {
      uut.getInitialNotification();
      verify(mockedNativeCommandsSender.getInitialNotification()).called();
    });

    it('returns a promise with the initial notification', async () => {
      when(mockedNativeCommandsSender.getInitialNotification()).thenResolve(
        {data: {}}
      );
      const result = await uut.getInitialNotification();
      expect(result).toEqual({data: {}});
    });
  });

  describe('requestPermissions', () => {
    it('sends requestPermissions to native', () => {
      uut.requestPermissions();
      verify(mockedNativeCommandsSender.requestPermissions()).called();
    });
  });

  describe('abandonPermissions', () => {
    it('sends abandonPermissions to native', () => {
      uut.abandonPermissions();
      verify(mockedNativeCommandsSender.abandonPermissions()).called();
    });
  });

  describe('sendLocalNotification', () => {
    it('sends sendLocalNotification to native', () => {
      const notification: Notification = {data: {}, alert: 'alert'};
      uut.sendLocalNotification(notification);
      verify(mockedNativeCommandsSender.sendLocalNotification(notification, 'id')).called();
    });
  });
});