feat(config): add automation.cron schema for scheduled jobs
This commit is contained in:
@@ -0,0 +1,78 @@
|
||||
import { describe, it, expect } from 'vitest';
|
||||
import { configSchema } from './schema.js';
|
||||
|
||||
describe('configSchema automation', () => {
|
||||
const baseConfig = {
|
||||
telegram: { bot_token: 'test-token', allowed_chat_ids: [123] },
|
||||
models: { default: { provider: 'anthropic', model: 'claude-sonnet' } },
|
||||
};
|
||||
|
||||
it('accepts config without automation section', () => {
|
||||
const result = configSchema.parse(baseConfig);
|
||||
expect(result.automation).toBeDefined();
|
||||
expect(result.automation.cron).toEqual([]);
|
||||
});
|
||||
|
||||
it('accepts config with cron jobs', () => {
|
||||
const result = configSchema.parse({
|
||||
...baseConfig,
|
||||
automation: {
|
||||
cron: [{
|
||||
name: 'morning-briefing',
|
||||
schedule: '0 9 * * *',
|
||||
message: 'Good morning!',
|
||||
output: { channel: 'telegram', peer: '123' },
|
||||
}],
|
||||
},
|
||||
});
|
||||
expect(result.automation.cron).toHaveLength(1);
|
||||
expect(result.automation.cron[0].name).toBe('morning-briefing');
|
||||
expect(result.automation.cron[0].enabled).toBe(true); // default
|
||||
});
|
||||
|
||||
it('rejects cron job with empty name', () => {
|
||||
expect(() => configSchema.parse({
|
||||
...baseConfig,
|
||||
automation: {
|
||||
cron: [{
|
||||
name: '',
|
||||
schedule: '0 9 * * *',
|
||||
message: 'test',
|
||||
output: { channel: 'telegram', peer: '123' },
|
||||
}],
|
||||
},
|
||||
})).toThrow();
|
||||
});
|
||||
|
||||
it('rejects cron job with empty schedule', () => {
|
||||
expect(() => configSchema.parse({
|
||||
...baseConfig,
|
||||
automation: {
|
||||
cron: [{
|
||||
name: 'test',
|
||||
schedule: '',
|
||||
message: 'test',
|
||||
output: { channel: 'telegram', peer: '123' },
|
||||
}],
|
||||
},
|
||||
})).toThrow();
|
||||
});
|
||||
|
||||
it('accepts cron job with optional fields', () => {
|
||||
const result = configSchema.parse({
|
||||
...baseConfig,
|
||||
automation: {
|
||||
cron: [{
|
||||
name: 'test',
|
||||
schedule: '0 9 * * *',
|
||||
message: 'test',
|
||||
output: { channel: 'telegram', peer: '123' },
|
||||
enabled: false,
|
||||
timezone: 'America/New_York',
|
||||
}],
|
||||
},
|
||||
});
|
||||
expect(result.automation.cron[0].enabled).toBe(false);
|
||||
expect(result.automation.cron[0].timezone).toBe('America/New_York');
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user