feat: platform backbone and field capture complete (checkpoint)

Platform backbone (plan 2026-10-13-plattform-rueckgrat), all tasks reviewed:
- webhooks with delivery table, retries and stable delivery id
- calendar handlers; a finished task removes its Outlook event
- tasks, automations, inspections, varroa, treatments, feedings,
  harvests, colonies, wintering, stock and bottling record domain events
  in the same transaction; legacy post-commit calls removed
- row locks through one helper (lockRowForUpdate, lockRowsForShare,
  lockRowsForUpdate)
- job framework with JobRun, cli exit codes, cleanup, task templates,
  daily evaluation, hourly app-backup and the rekey job
- system API and page "Verwaltung > System" with retry
- @nestjs/schedule removed, guard tests against in-process schedulers

Field capture T3 (plan 2026-10-13-t3-erfassung-am-stand), all tasks reviewed:
- inspection photo offline without metadata
- bulk capture for treatments, feedings and varroa (backend + frontend)
- offline stand mode with service worker, offline pages and packs
- offline session, cold start and logout on shared devices

Docs: ARCHITECTURE.md assumptions and sections updated, TASKS.md.
Gates: backend lint, typecheck, 1770 unit, 420 e2e, build, no schema
drift; frontend lint, typecheck, 913 tests, build. Not rolled out.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
This commit is contained in:
Nick SzaunigandClaude Opus 5.5 committed 2026-10-14 11:36:38 +02:00
1 parent c01a38835a
commit cdd30cf3ee
288 files changed
+39165 -2853

No files matched your search

+136 -3
View File
@@ -17,6 +17,12 @@ interface BottlingBatchBody {
lotNumber: string;
}
interface RecordedEvent {
type: string;
payload: unknown;
actorUserId: string | null;
}
describe('Bottling (e2e)', () => {
let app: INestApplication<App>;
let prisma: PrismaService;
@@ -24,12 +30,49 @@ describe('Bottling (e2e)', () => {
const password = 'SuperSecret123!';
let beekeeperId: string;
let beekeeperToken: string;
// Removing a bottling needs bottling-batch:delete, which BEEKEEPER lacks.
const adminEmail = `bottling-e2e-admin-${Date.now()}@example.com`;
let adminId: string;
let adminToken: string;
let apiaryId: string;
let colonyId: string;
let harvestId: string;
let extractionId: string;
let honeyBatchId: string;
let bottlingBatchId: string;
const seenEventIds = new Set<string>();
/**
* The events recorded on the bottling since the last call, by type - one
* request's events share a correlation id.
*/
async function newEventsOf(id: string): Promise<RecordedEvent[]> {
const events = (
await prisma.domainEvent.findMany({
where: { aggregateType: 'BottlingBatch', aggregateId: id },
select: {
id: true,
type: true,
payload: true,
actorUserId: true,
correlationId: true,
},
})
).filter((event) => !seenEventIds.has(event.id));
events.forEach((event) => seenEventIds.add(event.id));
expect(new Set(events.map((event) => event.correlationId)).size).toBe(1);
return events
.map(({ type, payload, actorUserId }) => ({ type, payload, actorUserId }))
.sort((a, b) => a.type.localeCompare(b.type));
}
async function honeyBatchAmount(): Promise<number | null> {
const response = await request(app.getHttpServer())
.get(`/api/v1/honey-batches/${honeyBatchId}`)
.set('Authorization', `Bearer ${beekeeperToken}`)
.expect(200);
return (response.body as HoneyBatchBody).amount;
}
beforeAll(async () => {
app = await createTestApp();
@@ -46,6 +89,16 @@ describe('Bottling (e2e)', () => {
});
beekeeperId = beekeeper.id;
beekeeperToken = (await login(app, beekeeperEmail, password)).accessToken;
const admin = await prisma.user.create({
data: {
email: adminEmail,
passwordHash,
name: 'Admin',
role: { connect: { key: 'ADMIN' } },
},
});
adminId = admin.id;
adminToken = (await login(app, adminEmail, password)).accessToken;
const apiary = await prisma.apiary.create({
data: { name: `Stand ${Date.now()}` },
@@ -79,6 +132,12 @@ describe('Bottling (e2e)', () => {
afterAll(async () => {
if (bottlingBatchId) {
await prisma.domainEvent.deleteMany({
where: {
aggregateType: 'BottlingBatch',
aggregateId: bottlingBatchId,
},
});
await prisma.bottlingBatch.deleteMany({ where: { id: bottlingBatchId } });
}
await prisma.honeyBatch.deleteMany({ where: { id: honeyBatchId } });
@@ -88,9 +147,12 @@ describe('Bottling (e2e)', () => {
await prisma.harvest.deleteMany({ where: { id: harvestId } });
await prisma.colony.deleteMany({ where: { id: colonyId } });
await prisma.apiary.deleteMany({ where: { id: apiaryId } });
await prisma.refreshToken.deleteMany({ where: { userId: beekeeperId } });
await prisma.auditLog.deleteMany({ where: { userId: beekeeperId } });
await prisma.user.deleteMany({ where: { id: beekeeperId } });
const userIds = [beekeeperId, adminId].filter(Boolean);
await prisma.refreshToken.deleteMany({
where: { userId: { in: userIds } },
});
await prisma.auditLog.deleteMany({ where: { userId: { in: userIds } } });
await prisma.user.deleteMany({ where: { id: { in: userIds } } });
await app.close();
});
@@ -134,4 +196,75 @@ describe('Bottling (e2e)', () => {
expect(honeyBatch.amount).toBe(0);
expect(honeyBatch.status).toBe('BOTTLED');
});
it('bottling create records BatchBottled and StockChanged together', async () => {
expect(await newEventsOf(bottlingBatchId)).toEqual([
{
type: 'BatchBottled',
payload: { honeyBatchId },
actorUserId: beekeeperId,
},
{
type: 'StockChanged',
payload: {
bottlingBatchIds: [bottlingBatchId],
productIds: [],
rawMaterialKinds: [],
},
actorUserId: beekeeperId,
},
]);
});
it('a correction records BottlingCorrected and StockChanged together', async () => {
await request(app.getHttpServer())
.patch(`/api/v1/bottling-batches/${bottlingBatchId}`)
.set('Authorization', `Bearer ${beekeeperToken}`)
.send({ jarCount: 40 })
.expect(200);
// 10 jars of 500 g fewer: 5 kg go back to the honey batch.
expect(await honeyBatchAmount()).toBe(5);
expect(await newEventsOf(bottlingBatchId)).toEqual([
{
type: 'BottlingCorrected',
payload: { honeyBatchId, removed: false },
actorUserId: beekeeperId,
},
{
type: 'StockChanged',
payload: {
bottlingBatchIds: [bottlingBatchId],
productIds: [],
rawMaterialKinds: [],
},
actorUserId: beekeeperId,
},
]);
});
it('a removal records BottlingCorrected { removed: true } and StockChanged together', async () => {
await request(app.getHttpServer())
.delete(`/api/v1/bottling-batches/${bottlingBatchId}`)
.set('Authorization', `Bearer ${adminToken}`)
.expect(200);
expect(await honeyBatchAmount()).toBe(25);
expect(await newEventsOf(bottlingBatchId)).toEqual([
{
type: 'BottlingCorrected',
payload: { honeyBatchId, removed: true },
actorUserId: adminId,
},
{
type: 'StockChanged',
payload: {
bottlingBatchIds: [bottlingBatchId],
productIds: [],
rawMaterialKinds: [],
},
actorUserId: adminId,
},
]);
});
});