mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-21 23:19:09 +00:00
feat: automation service
This commit is contained in:
committed by
Carlos Valente
parent
a8fe4c8e68
commit
05e61e7bf8
@@ -0,0 +1,92 @@
|
||||
import { TimerLifeCycle } from 'ontime-types';
|
||||
|
||||
import { deleteAllAutomations, addAutomation, addBlueprint } from '../automation.dao.js';
|
||||
import { triggerAction } from '../automation.service.js';
|
||||
|
||||
import { makeOSCAction, makeHTTPAction } from './testUtils.js';
|
||||
|
||||
import * as oscClient from '../clients/osc.client.js';
|
||||
import * as httpClient from '../clients/http.client.js';
|
||||
|
||||
beforeAll(() => {
|
||||
vi.mock('../../../classes/data-provider/DataProvider.js', () => {
|
||||
// Create a small mock store
|
||||
let automations = {
|
||||
enabledAutomations: true,
|
||||
enabledOscIn: true,
|
||||
oscPortIn: 8888,
|
||||
automations: [],
|
||||
blueprints: {},
|
||||
};
|
||||
return {
|
||||
getDataProvider: vi.fn().mockImplementation(() => {
|
||||
return {
|
||||
getAutomation: vi.fn().mockImplementation(() => automations),
|
||||
setAutomation: vi.fn().mockImplementation((newData) => (automations = newData)),
|
||||
};
|
||||
}),
|
||||
};
|
||||
});
|
||||
});
|
||||
|
||||
afterAll(() => {
|
||||
vi.clearAllMocks();
|
||||
});
|
||||
|
||||
describe('triggerAction()', () => {
|
||||
let oscSpy = vi.spyOn(oscClient, 'emitOSC');
|
||||
let httpSpy = vi.spyOn(httpClient, 'emitHTTP');
|
||||
|
||||
beforeEach(() => {
|
||||
oscSpy = vi.spyOn(oscClient, 'emitOSC').mockImplementation(() => {});
|
||||
httpSpy = vi.spyOn(httpClient, 'emitHTTP').mockImplementation(() => {});
|
||||
|
||||
deleteAllAutomations();
|
||||
const oscBlueprint = addBlueprint({
|
||||
title: 'test-osc',
|
||||
filterRule: 'all',
|
||||
filters: [],
|
||||
outputs: [makeOSCAction()],
|
||||
});
|
||||
const httpBlueprint = addBlueprint({
|
||||
title: 'test-http',
|
||||
filterRule: 'any',
|
||||
filters: [],
|
||||
outputs: [makeHTTPAction()],
|
||||
});
|
||||
addAutomation({
|
||||
title: 'test-osc',
|
||||
trigger: TimerLifeCycle.onLoad,
|
||||
blueprintId: oscBlueprint.id,
|
||||
});
|
||||
addAutomation({
|
||||
title: 'test-http',
|
||||
trigger: TimerLifeCycle.onFinish,
|
||||
blueprintId: httpBlueprint.id,
|
||||
});
|
||||
});
|
||||
|
||||
it('should trigger automations for a given action', () => {
|
||||
triggerAction(TimerLifeCycle.onLoad, {});
|
||||
expect(oscSpy).toHaveBeenCalledTimes(1);
|
||||
expect(httpSpy).not.toBeCalled();
|
||||
oscSpy.mockReset();
|
||||
httpSpy.mockReset();
|
||||
|
||||
triggerAction(TimerLifeCycle.onStart, {});
|
||||
expect(oscClient.emitOSC).not.toBeCalled();
|
||||
expect(httpSpy).not.toBeCalled();
|
||||
oscSpy.mockReset();
|
||||
httpSpy.mockReset();
|
||||
|
||||
triggerAction(TimerLifeCycle.onFinish, {});
|
||||
expect(oscSpy).not.toBeCalled();
|
||||
expect(httpSpy).toHaveBeenCalledTimes(1);
|
||||
oscSpy.mockReset();
|
||||
httpSpy.mockReset();
|
||||
|
||||
triggerAction(TimerLifeCycle.onStop, {});
|
||||
expect(oscSpy).not.toBeCalled();
|
||||
expect(httpSpy).not.toBeCalled();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user