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:
1 parent
c01a38835a
commit
cdd30cf3ee
288 files changed
+39165
-2853
No files matched your search
@@ -5,6 +5,7 @@ import { App } from 'supertest/types';
|
||||
import { PrismaService } from '../src/prisma/prisma.service';
|
||||
import { createTestApp } from './utils/create-test-app';
|
||||
import { login } from './utils/api';
|
||||
import { drainDomainEvents } from './utils/domain-events';
|
||||
|
||||
/**
|
||||
* Regression tests for data-integrity rules that cut across modules:
|
||||
@@ -84,6 +85,21 @@ describe('Data integrity (e2e)', () => {
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
// The events this file's requests recorded (all by its own user) and
|
||||
// the follow-up events their handlers recorded under the same
|
||||
// correlation id - other e2e files share the database.
|
||||
if (userId) {
|
||||
const correlationIds = (
|
||||
await prisma.domainEvent.findMany({
|
||||
where: { actorUserId: userId },
|
||||
select: { correlationId: true },
|
||||
distinct: ['correlationId'],
|
||||
})
|
||||
).map((event) => event.correlationId);
|
||||
await prisma.domainEvent.deleteMany({
|
||||
where: { correlationId: { in: correlationIds } },
|
||||
});
|
||||
}
|
||||
await app.close();
|
||||
});
|
||||
|
||||
@@ -117,6 +133,7 @@ describe('Data integrity (e2e)', () => {
|
||||
expect(
|
||||
await prisma.inspection.count({ where: { colonyId: colony.id } }),
|
||||
).toBe(1);
|
||||
await drainDomainEvents(app, [(first.body as { id: string }).id]);
|
||||
// The automation fired once, not once per delivery attempt.
|
||||
expect(
|
||||
await prisma.task.count({
|
||||
@@ -397,6 +414,76 @@ describe('Data integrity (e2e)', () => {
|
||||
expect((second.body as { completedAt: string }).completedAt).toBe(
|
||||
(first.body as { completedAt: string }).completedAt,
|
||||
);
|
||||
// Announced once: a second TaskCompleted would send the webhook twice.
|
||||
await expect(
|
||||
prisma.domainEvent.count({
|
||||
where: { aggregateId: id, type: 'TaskCompleted' },
|
||||
}),
|
||||
).resolves.toBe(1);
|
||||
});
|
||||
|
||||
it('announces a completion once when two requests complete a task at the same time', async () => {
|
||||
const created = await request(server())
|
||||
.post('/api/v1/tasks')
|
||||
.set(auth())
|
||||
.send({ title: `Gleichzeitig erledigt ${suffix}` })
|
||||
.expect(201);
|
||||
const id = (created.body as { id: string }).id;
|
||||
|
||||
const [first, second] = await Promise.all([
|
||||
request(server())
|
||||
.post(`/api/v1/tasks/${id}/complete`)
|
||||
.set(auth())
|
||||
.expect(201),
|
||||
request(server())
|
||||
.post(`/api/v1/tasks/${id}/complete`)
|
||||
.set(auth())
|
||||
.expect(201),
|
||||
]);
|
||||
|
||||
expect((second.body as { completedAt: string }).completedAt).toBe(
|
||||
(first.body as { completedAt: string }).completedAt,
|
||||
);
|
||||
await expect(
|
||||
prisma.domainEvent.count({
|
||||
where: { aggregateId: id, type: 'TaskCompleted' },
|
||||
}),
|
||||
).resolves.toBe(1);
|
||||
await expect(
|
||||
prisma.auditLog.count({
|
||||
where: { entityType: 'Task', entityId: id, action: 'UPDATE' },
|
||||
}),
|
||||
).resolves.toBe(1);
|
||||
});
|
||||
|
||||
it('announces a completion once when an edit into DONE and "Erledigt" arrive at the same time', async () => {
|
||||
const created = await request(server())
|
||||
.post('/api/v1/tasks')
|
||||
.set(auth())
|
||||
.send({ title: `Bearbeitet und erledigt ${suffix}` })
|
||||
.expect(201);
|
||||
const id = (created.body as { id: string }).id;
|
||||
|
||||
const [edited, completed] = await Promise.all([
|
||||
request(server())
|
||||
.patch(`/api/v1/tasks/${id}`)
|
||||
.set(auth())
|
||||
.send({ status: 'DONE' })
|
||||
.expect(200),
|
||||
request(server())
|
||||
.post(`/api/v1/tasks/${id}/complete`)
|
||||
.set(auth())
|
||||
.expect(201),
|
||||
]);
|
||||
|
||||
expect((edited.body as { completedAt: string }).completedAt).toBe(
|
||||
(completed.body as { completedAt: string }).completedAt,
|
||||
);
|
||||
await expect(
|
||||
prisma.domainEvent.count({
|
||||
where: { aggregateId: id, type: 'TaskCompleted' },
|
||||
}),
|
||||
).resolves.toBe(1);
|
||||
});
|
||||
|
||||
it('clears completedAt when a done task is reopened', async () => {
|
||||
@@ -442,6 +529,20 @@ describe('Data integrity (e2e)', () => {
|
||||
where: { id: template.id },
|
||||
});
|
||||
expect(refreshed.nextDueDate.getTime()).toBeGreaterThan(Date.now());
|
||||
// One TaskCreated carrying that due date, so the calendar entry and
|
||||
// the webhook follow the generated task like any other.
|
||||
const events = await prisma.domainEvent.findMany({
|
||||
where: { aggregateType: 'Task', aggregateId: generated[0].id },
|
||||
});
|
||||
expect(events).toEqual([
|
||||
expect.objectContaining({
|
||||
type: 'TaskCreated',
|
||||
actorUserId: null,
|
||||
payload: expect.objectContaining({
|
||||
dueDate: generated[0].dueDate?.toISOString().slice(0, 10),
|
||||
}) as unknown,
|
||||
}),
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in new issue
Block a user