homehub/packages/homehub_core/tests/api/services.spec.js

52 lines
1.4 KiB
JavaScript
Raw Normal View History

2021-08-26 10:33:15 +00:00
import * as Services from 'src/api/services';
import * as RPC from 'src/lib/rpc';
describe('src/api/services', () => {
beforeEach(() => {
spyOn(RPC, 'callMethod').and.resolveTo('ok');
});
describe('start', () => {
it('calls and RPC method to start a service', async () => {
// When
const result = await Services.start('FakeService', 'fake_instance', {
'spam': true,
});
// Then
expect(result).toEqual('ok');
expect(RPC.callMethod).toHaveBeenCalledWith('services.start', [
'FakeService', 'fake_instance', {'spam': true},
]);
});
});
describe('stop', () => {
it('calls and RPC method to stop a service', async () => {
// When
const result = await Services.stop('FakeService', 'fake_instance');
// Then
expect(result).toEqual('ok');
expect(RPC.callMethod).toHaveBeenCalledWith('services.stop', [
'FakeService', 'fake_instance',
]);
});
});
describe('use', () => {
it('calls and RPC method to use a service capability', async () => {
// When
const result = await Services.use(
'FakeService', 'fake_instance', 'testing', ['spam'],
);
// Then
expect(result).toEqual('ok');
expect(RPC.callMethod).toHaveBeenCalledWith('services.use', [
'FakeService', 'fake_instance', 'testing', ['spam'],
]);
});
});
});