homehub/packages/homehub_app/tests/services/uptime.spec.js

57 lines
1.4 KiB
JavaScript
Raw Permalink Normal View History

2021-08-26 10:33:15 +00:00
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'
);
});
});
});
});