feat: T4 waves 1-2 - rule configs, schema, suggestions core, season, rule forms
- Rule configs with typed parsers and registry; Berlin day helpers - Schema: T4 enums, Suggestion table, feed vocabulary (feedStatus as ColonyCondition with legacy text mapping), split queen source, varroa sample size; migration harness for data migrations - SuggestionsService: propose/refresh/resolve/obsolete/expire, accept/dismiss/reopen incl. bulk, lock order, concurrency e2e - SeasonService: phenology-based segments, inspection/varroa due dates, queen age; TimeEventsStep with JobPartialFailure - Frontend: per-rule settings forms with visible value sources Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
This commit is contained in:
1 parent
7097fcd97c
commit
d99a697739
116 files changed
+11239
-801
No files matched your search
@@ -7,6 +7,7 @@ import { AutomationTriggerType, Prisma } from '../generated/prisma';
|
||||
import { createTestApp } from './utils/create-test-app';
|
||||
import { login } from './utils/api';
|
||||
import { drainDomainEvents } from './utils/domain-events';
|
||||
import { DEFAULT_RULES } from '../src/automation/rule-config';
|
||||
|
||||
interface AutomationRuleBody {
|
||||
id: string;
|
||||
@@ -165,6 +166,94 @@ describe('Automation rules (e2e)', () => {
|
||||
)!.id;
|
||||
});
|
||||
|
||||
const NEW_TRIGGERS = [
|
||||
'INSPECTION_INTERVAL',
|
||||
'QUEEN_CELLS_SWARM_CHECK',
|
||||
'QUEEN_ACCEPTANCE_CHECK',
|
||||
'SPLIT_SCHEDULE',
|
||||
'COLONY_ENDED_CLEANUP',
|
||||
'WITHDRAWAL_ENDED',
|
||||
'HONEY_WATER_CONTENT',
|
||||
'SEASON_AUTOPILOT',
|
||||
'PHENOLOGY',
|
||||
] as const;
|
||||
|
||||
it('lists the nine new rules with their defaults', async () => {
|
||||
const response = await request(app.getHttpServer())
|
||||
.get('/api/v1/automation-rules')
|
||||
.set('Authorization', `Bearer ${adminToken}`)
|
||||
.expect(200);
|
||||
const rules = response.body as AutomationRuleBody[];
|
||||
|
||||
for (const trigger of NEW_TRIGGERS) {
|
||||
const rule = rules.find((entry) => entry.triggerType === trigger);
|
||||
expect(rule).toBeDefined();
|
||||
expect(rule!.active).toBe(DEFAULT_RULES[trigger].active ?? true);
|
||||
expect(rule!.config).toEqual(DEFAULT_RULES[trigger].config);
|
||||
expect(rule!.actionTemplate).toBe('');
|
||||
}
|
||||
// Existing rules keep their stored config; a fresh database has the new defaults.
|
||||
const varroa = rules.find(
|
||||
(rule) => rule.triggerType === 'VARROA_THRESHOLD',
|
||||
);
|
||||
expect(varroa?.config).toBeTruthy();
|
||||
});
|
||||
|
||||
it('PATCH a rule with an invalid known value answers 400 with the field', async () => {
|
||||
const rules = (
|
||||
await request(app.getHttpServer())
|
||||
.get('/api/v1/automation-rules')
|
||||
.set('Authorization', `Bearer ${adminToken}`)
|
||||
.expect(200)
|
||||
).body as AutomationRuleBody[];
|
||||
const autopilot = rules.find(
|
||||
(rule) => rule.triggerType === 'SEASON_AUTOPILOT',
|
||||
)!;
|
||||
|
||||
const res = await request(app.getHttpServer())
|
||||
.patch(`/api/v1/automation-rules/${autopilot.id}`)
|
||||
.set('Authorization', `Bearer ${adminToken}`)
|
||||
.send({ config: { queenMaxAgeYears: 0 } })
|
||||
.expect(400);
|
||||
|
||||
const body = res.body as {
|
||||
message: string;
|
||||
issues: { field: string; message: string }[];
|
||||
};
|
||||
expect(body.message).toBe('Die Einstellung ist ungültig.');
|
||||
expect(body.issues).toEqual([
|
||||
expect.objectContaining({ field: 'queenMaxAgeYears' }),
|
||||
]);
|
||||
// Nothing was written.
|
||||
const stored = await prisma.automationRule.findUniqueOrThrow({
|
||||
where: { id: autopilot.id },
|
||||
});
|
||||
expect(stored.config).toEqual(autopilot.config);
|
||||
});
|
||||
|
||||
it('PATCH keeps unknown keys and saves a valid config', async () => {
|
||||
const rule = await prisma.automationRule.findUniqueOrThrow({
|
||||
where: { triggerType: 'SEASON_AUTOPILOT' },
|
||||
});
|
||||
try {
|
||||
await request(app.getHttpServer())
|
||||
.patch(`/api/v1/automation-rules/${rule.id}`)
|
||||
.set('Authorization', `Bearer ${adminToken}`)
|
||||
.send({ config: { queenMaxAgeYears: 3, futureKey: 'x' } })
|
||||
.expect(200);
|
||||
|
||||
const stored = await prisma.automationRule.findUniqueOrThrow({
|
||||
where: { id: rule.id },
|
||||
});
|
||||
expect(stored.config).toEqual({ queenMaxAgeYears: 3, futureKey: 'x' });
|
||||
} finally {
|
||||
await prisma.automationRule.update({
|
||||
where: { id: rule.id },
|
||||
data: { config: rule.config as Prisma.InputJsonValue },
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
it('creates a task and notification when queen not seen and no eggs present', async () => {
|
||||
await record('inspections', { queenSeen: false, eggsPresent: false });
|
||||
|
||||
@@ -190,7 +279,7 @@ describe('Automation rules (e2e)', () => {
|
||||
});
|
||||
|
||||
it('triggers a feeding task when feed status is kritisch', async () => {
|
||||
await record('inspections', { feedStatus: 'kritisch' });
|
||||
await record('inspections', { feedStatus: 'CRITICAL' });
|
||||
|
||||
const tasks = await prisma.task.findMany({
|
||||
where: { relatedId: colonyId },
|
||||
@@ -212,7 +301,7 @@ describe('Automation rules (e2e)', () => {
|
||||
await request(app.getHttpServer())
|
||||
.patch(`/api/v1/inspections/${id}`)
|
||||
.set('Authorization', `Bearer ${staffToken}`)
|
||||
.send({ queenSeen: false, eggsPresent: false, feedStatus: 'kritisch' })
|
||||
.send({ queenSeen: false, eggsPresent: false, feedStatus: 'CRITICAL' })
|
||||
.expect(200);
|
||||
await drainDomainEvents(app, [id]);
|
||||
|
||||
|
||||
Reference in new issue
Block a user