Files
ontime/apps/server/src/api-data/automation/__tests__/automation.validation.test.ts
T
Alex Christoffer Rasmussen 4d359445a7 Fix ontime aux actions (#1684)
* switch to base ui

* ensure all action types is part of the valitation

* update test

* atempt to do it in the base-ui way

* fix fixing

* allow undefide visible on set timer message

* fix set time not showing

* correct time data for aux set automation

---------

Co-authored-by: Carlos Valente <carlosvalente@pm.me>
2025-07-09 13:14:23 +02:00

167 lines
3.8 KiB
TypeScript

import { parseOutput } from '../automation.validation.js';
describe('parseOutput', () => {
describe('handles OSC outputs', () => {
it('parses a valid payload', () => {
const payload = {
type: 'osc',
targetIP: 'localhost',
targetPort: 1234,
address: '/test',
args: 'test',
};
const result = parseOutput(payload);
expect(result).toStrictEqual(payload);
});
it('throws on a invalid payload', () => {
const payload = {
type: 'osc',
targetIP: 1234,
targetPort: 1234,
address: '/test',
args: 'test',
};
expect(() => parseOutput(payload)).toThrow();
});
});
describe('handles HTTP outputs', () => {
it('parses a valid payload', () => {
const payload = {
type: 'http',
url: 'http://asdasdas',
};
const result = parseOutput(payload);
expect(result).toStrictEqual(payload);
});
it('throws on a invalid payload', () => {
const payload = {
type: 'http',
};
expect(() => parseOutput(payload)).toThrow();
});
});
describe('handles Ontime outputs', () => {
it('parses a valid payload', () => {
const auxStart = {
type: 'ontime',
action: 'aux1-start',
};
expect(parseOutput(auxStart)).toStrictEqual(auxStart);
const auxStop = {
type: 'ontime',
action: 'aux3-stop',
};
expect(parseOutput(auxStop)).toStrictEqual(auxStop);
const auxPause = {
type: 'ontime',
action: 'aux2-pause',
};
expect(parseOutput(auxPause)).toStrictEqual(auxPause);
});
it('removes extra properties', () => {
expect(
parseOutput({
type: 'ontime',
action: 'aux1-start',
time: 10,
}),
).toStrictEqual({
type: 'ontime',
action: 'aux1-start',
});
});
it('throws on a invalid payload', () => {
const payload = {
type: 'ontime',
action: 'not-exist',
};
expect(() => parseOutput(payload)).toThrow();
});
it('parses message-set', () => {
expect(
parseOutput({
type: 'ontime',
action: 'message-set',
text: 'test',
visible: true,
}),
).toMatchObject({
text: 'test',
visible: true,
});
expect(
parseOutput({
type: 'ontime',
action: 'message-set',
text: '',
visible: false,
}),
).toMatchObject({
text: undefined,
visible: false,
});
expect(
parseOutput({
type: 'ontime',
action: 'message-set',
text: '',
}),
).toMatchObject({
text: undefined,
visible: undefined,
});
expect(() =>
parseOutput({
type: 'ontime',
action: 'message-set',
text: 123,
visible: '',
}),
).toThrow();
});
it('parses message-secondary', () => {});
expect(
parseOutput({
type: 'ontime',
action: 'message-secondary',
secondarySource: 'test',
}),
).toMatchObject({
secondarySource: null,
});
expect(
parseOutput({
type: 'ontime',
action: 'message-secondary',
secondarySource: '',
}),
).toMatchObject({
secondarySource: null,
});
expect(
parseOutput({
type: 'ontime',
action: 'message-secondary',
secondarySource: 'aux1',
}),
).toMatchObject({
secondarySource: 'aux1',
});
expect(
parseOutput({
type: 'ontime',
action: 'message-secondary',
secondarySource: 'secondary',
}),
).toMatchObject({
secondarySource: 'secondary',
});
});
});