feat: T4b/T4c wave 9 - phenology reports, autopilot A4-A10, honey ledger, Telegram delivery
- Phenology reports API with corrections and revokes; recompute per apiary via PhenologyRecomputeRequested, allowBackward for corrections; season changes are announced in the morning digest (changes since the previous digest, each once) - Season autopilot A4-A10 with per-apiary sync (Apiary before Colony locks) and WinterCheckRecorded - Honey batch ledger at runtime: initial amount, BOTTLING bookings, manual movements, one gram rounding, untracked bottlings never book - Telegram delivery: planning, Berlin delivery times incl. DST, quiet hours, permission re-check and stale skip at send time, rate limits, cleanup of old deliveries - ARCHITECTURE.md: assumptions 47-50 and updated sections 11.x Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
This commit is contained in:
1 parent
1971b2d9c4
commit
16cc557462
74 files changed
+9634
-340
No files matched your search
@@ -1,6 +1,7 @@
|
||||
import { INestApplication } from '@nestjs/common';
|
||||
import * as bcrypt from 'bcryptjs';
|
||||
import { App } from 'supertest/types';
|
||||
import { addDays } from '../src/common/dates';
|
||||
import { DomainEventsService } from '../src/domain-events/domain-events.service';
|
||||
import type { AnyDomainEventEnvelope } from '../src/domain-events/domain-event-types';
|
||||
import { PrismaService } from '../src/prisma/prisma.service';
|
||||
@@ -18,6 +19,13 @@ const d = (day: string): Date => new Date(`${day}T00:00:00.000Z`);
|
||||
* file's own users, apiary and tasks.
|
||||
*/
|
||||
const TODAY = '2001-04-15';
|
||||
const YESTERDAY = '2001-04-14';
|
||||
|
||||
/** The digest window of a run at 04:30 (UTC, for the test) on `day`. */
|
||||
const windowOf = (day: string) => ({
|
||||
from: new Date(`${addDays(day, -1)}T02:30:00.000Z`),
|
||||
until: new Date(`${day}T02:30:00.000Z`),
|
||||
});
|
||||
|
||||
describe('Reminders (e2e)', () => {
|
||||
let app: INestApplication<App>;
|
||||
@@ -138,6 +146,27 @@ describe('Reminders (e2e)', () => {
|
||||
},
|
||||
});
|
||||
}
|
||||
// Two segment changes of the apiary: one before yesterday's digest
|
||||
// (reported then), one after it (reported today). Status DONE, so no
|
||||
// dispatcher touches them.
|
||||
const seasonEvent = (
|
||||
previousSegment: string,
|
||||
segment: string,
|
||||
occurredAt: string,
|
||||
) =>
|
||||
prisma.domainEvent.create({
|
||||
data: {
|
||||
type: 'SeasonPhaseChanged',
|
||||
aggregateType: 'Apiary',
|
||||
aggregateId: apiaryId,
|
||||
payload: { apiaryId, previousSegment, segment },
|
||||
correlationId: `reminders-e2e-${suffix}`,
|
||||
occurredAt: new Date(occurredAt),
|
||||
status: 'DONE',
|
||||
},
|
||||
});
|
||||
await seasonEvent('FRUEHJAHR', 'SCHWARMZEIT', '2001-04-13T12:00:00.000Z');
|
||||
await seasonEvent('SCHWARMZEIT', 'SOMMER', '2001-04-14T12:00:00.000Z');
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
@@ -147,7 +176,7 @@ describe('Reminders (e2e)', () => {
|
||||
},
|
||||
});
|
||||
await prisma.domainEvent.deleteMany({
|
||||
where: { aggregateId: { in: taskIds } },
|
||||
where: { aggregateId: { in: [...taskIds, apiaryId] } },
|
||||
});
|
||||
await prisma.inspection.deleteMany({
|
||||
where: { colonyId: { in: colonyIds } },
|
||||
@@ -243,8 +272,8 @@ describe('Reminders (e2e)', () => {
|
||||
users.nothing,
|
||||
];
|
||||
|
||||
const first = await digests.runFor(TODAY, own);
|
||||
const second = await digests.runFor(TODAY, own);
|
||||
const first = await digests.runFor(TODAY, own, windowOf(TODAY));
|
||||
const second = await digests.runFor(TODAY, own, windowOf(TODAY));
|
||||
|
||||
expect(first).toBeGreaterThanOrEqual(2);
|
||||
expect(second).toBe(0);
|
||||
@@ -264,8 +293,10 @@ describe('Reminders (e2e)', () => {
|
||||
`Durchsicht fällig: 2 Völker am Stand ${apiaryName}.`,
|
||||
);
|
||||
expect(lines).toContain(
|
||||
`Stand ${apiaryName}: Schwarmzeit beginnt. Durchsicht alle 7 Tage.`,
|
||||
`Stand ${apiaryName}: Sommer beginnt. Durchsicht alle 14 Tage.`,
|
||||
);
|
||||
// The change before yesterday's digest is not repeated.
|
||||
expect(full.message).not.toContain('Schwarmzeit beginnt');
|
||||
expect(full.requiredPermissions).toEqual(
|
||||
expect.arrayContaining([
|
||||
'tasks:read',
|
||||
@@ -276,18 +307,33 @@ describe('Reminders (e2e)', () => {
|
||||
);
|
||||
});
|
||||
|
||||
it('the digest of the day before reports the change of its own window', async () => {
|
||||
await digests.runFor(YESTERDAY, [users.full], windowOf(YESTERDAY));
|
||||
|
||||
const [yesterday] = await prisma.notification.findMany({
|
||||
where: {
|
||||
userId: users.full,
|
||||
dedupeKey: `digest:${YESTERDAY}:${users.full}`,
|
||||
},
|
||||
});
|
||||
expect(yesterday.message).toContain(
|
||||
`Stand ${apiaryName}: Schwarmzeit beginnt. Durchsicht alle 7 Tage.`,
|
||||
);
|
||||
expect(yesterday.message).not.toContain('Sommer beginnt');
|
||||
});
|
||||
|
||||
it('the digest of a user without varroa or inspection rights has no such line', async () => {
|
||||
await digests.runFor(TODAY, [users.noInspection]);
|
||||
await digests.runFor(TODAY, [users.noInspection], windowOf(TODAY));
|
||||
|
||||
const [digest] = await digestOf(users.noInspection);
|
||||
expect(digest.message).toContain(`Stand ${apiaryName}: Schwarmzeit`);
|
||||
expect(digest.message).toContain(`Stand ${apiaryName}: Sommer`);
|
||||
expect(digest.message).not.toContain('Durchsicht fällig');
|
||||
expect(digest.requiredPermissions).not.toContain('inspections:read');
|
||||
expect(digest.requiredPermissions).not.toContain('colonies:read');
|
||||
});
|
||||
|
||||
it('builds no digest for a user who can see nothing in it, and none for a user who switched it off', async () => {
|
||||
await digests.runFor(TODAY, [users.nothing, users.off]);
|
||||
await digests.runFor(TODAY, [users.nothing, users.off], windowOf(TODAY));
|
||||
|
||||
expect(await digestOf(users.nothing)).toHaveLength(0);
|
||||
expect(await digestOf(users.off)).toHaveLength(0);
|
||||
|
||||
Reference in new issue
Block a user