import * as HomeHubCore from '@bthlabs/homehub-core'; import * as UptimeService from 'src/services/uptime'; describe('src/services/uptime', () => { describe('UptimeService', () => { let fakeResult = null; beforeEach(() => { fakeResult = { data: 123, }; spyOn(HomeHubCore.API.Services, 'start').and.returnValue(fakeResult); spyOn(HomeHubCore.API.Services, 'stop').and.returnValue('ok'); }); describe('start', () => { it('notifies subscribers with the result of start service API call', async () => { // Given const service = new UptimeService.UptimeService({ instance: 'testing', characteristics: {}, }); spyOn(service, 'notify'); // When await service.start(); // Then expect(HomeHubCore.API.Services.start).toHaveBeenCalledWith( service.kind, 'testing', {} ); expect(service.notify).toHaveBeenCalledWith(fakeResult); }); }); describe('stop', () => { it('calls the stop service API method', async () => { // Given const service = new UptimeService.UptimeService({ instance: 'testing', characteristics: {}, }); // When await service.stop(); // Then expect(HomeHubCore.API.Services.stop).toHaveBeenCalledWith( service.kind, 'testing' ); }); }); }); });