feat(queens): verdrängte Königin bekommt ihren Endstatus automatisch
Backend E2E / e2e (push) Successful in 5m24s
Backend Image / build-and-push (push) Successful in 5m3s
Frontend Image / build-and-push (push) Failing after 14m46s

Entscheidung Inhaber: Zieht eine neue Königin ein, wird die bisherige
„Ersetzt“; Vereinigen und Auflösen eines Volks setzen dessen Königin auf
„Ersetzt“, ein Winterverlust auf „Eingegangen“. Nur aus einem verfügbaren
Status (ACTIVE, RESERVE, MATED, UNMATED), über updateStatusIn in derselben
Transaktion mit Archivdatum und Audit (QueensService.retireIn). Ein von
Hand gesetzter Endstatus eines Volks fragt weiter über den Aufräum-
Vorschlag nach.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
This commit is contained in:
Nick.RosenloecherandClaude Opus 5.5 committed 2026-10-19 17:03:22 +02:00
1 parent f9e03a1695
commit 81927d629a
10 files changed
+205 -4

No files matched your search

+52 -2
View File
@@ -42,6 +42,7 @@ describe('Colony ended (e2e)', () => {
'colonies:read',
'colonies:update',
'colonies:deactivate',
'colonies:manage-lifecycle',
'winter-checks:read',
'winter-checks:create',
];
@@ -187,6 +188,9 @@ describe('Colony ended (e2e)', () => {
await prisma.queenColonyHistory.deleteMany({
where: { colonyId: { in: colonyIds } },
});
await prisma.colonyLineage.deleteMany({
where: { fromColonyId: { in: colonyIds } },
});
await prisma.colony.deleteMany({ where: { id: { in: colonyIds } } });
await prisma.queen.deleteMany({ where: { id: { in: queenIds } } });
await prisma.apiary.delete({ where: { id: apiaryId } });
@@ -227,10 +231,13 @@ describe('Colony ended (e2e)', () => {
});
expect(history).toHaveLength(1);
expect(history[0].endDate?.toISOString()).toBe('2002-03-20T00:00:00.000Z');
// The queen herself keeps her status: the clean-up decides.
// She died with the colony and moves to the archive.
await expect(
prisma.queen.findUniqueOrThrow({ where: { id: queenId } }),
).resolves.toMatchObject({ status: 'ACTIVE' });
).resolves.toMatchObject({
status: 'DECEASED',
deactivatedAt: expect.any(Date) as Date,
});
const ended = await prisma.domainEvent.findMany({
where: { aggregateId: colonyId, type: 'ColonyEnded' },
});
@@ -244,6 +251,49 @@ describe('Colony ended (e2e)', () => {
]);
});
it('dissolving a colony moves its queen to the archive as REPLACED', async () => {
const { colonyId, queenId } = await newColony('dissolve', 0);
await api()
.post(`/api/v1/colonies/${colonyId}/dissolve`)
.set(auth(tokens.full))
.expect(201);
await expect(
prisma.queen.findUniqueOrThrow({ where: { id: queenId } }),
).resolves.toMatchObject({
status: 'REPLACED',
deactivatedAt: expect.any(Date) as Date,
});
});
it('merging moves the queen of the merged-away colony to the archive and keeps a sold one sold', async () => {
const survivor = await newColony('survivor', 0);
const absorbed = await newColony('absorbed', 0);
const sold = await newColony('sold', 0);
await prisma.queen.update({
where: { id: sold.queenId },
data: { status: 'SOLD' },
});
await api()
.post(`/api/v1/colonies/${survivor.colonyId}/merge`)
.set(auth(tokens.full))
.send({ mergedColonyIds: [absorbed.colonyId, sold.colonyId] })
.expect(201);
const queens = await prisma.queen.findMany({
where: {
id: { in: [survivor.queenId, absorbed.queenId, sold.queenId] },
},
});
const statusOf = (id: string) =>
queens.find((queen) => queen.id === id)?.status;
expect(statusOf(survivor.queenId)).toBe('ACTIVE');
expect(statusOf(absorbed.queenId)).toBe('REPLACED');
expect(statusOf(sold.queenId)).toBe('SOLD');
});
it('open suggestions become OBSOLETE after draining and one CLEANUP suggestion is left', async () => {
const { colonyId, taskIds, queenId } = await newColony('obsolete', 2);
const open = await proposeForTest(app, {
+22 -1
View File
@@ -92,7 +92,10 @@ describe('Queens (e2e)', () => {
if (queenId) {
// Events go with their deliveries (ON DELETE CASCADE).
await prisma.domainEvent.deleteMany({
where: { aggregateType: 'Queen', aggregateId: queenId },
where: {
aggregateType: 'Queen',
aggregateId: { in: [queenId, daughterQueenId].filter(Boolean) },
},
});
}
if (queenId) {
@@ -358,4 +361,22 @@ describe('Queens (e2e)', () => {
.send({ deactivatedAt: new Date().toISOString() })
.expect(400);
});
it('moves the queen displaced by a new one into the archive as REPLACED', async () => {
// queenId sits in secondColonyId since the calendar test.
await request(app.getHttpServer())
.post(`/api/v1/queens/${daughterQueenId}/assign-colony`)
.set('Authorization', `Bearer ${beekeeperToken}`)
.send({ colonyId: secondColonyId })
.expect(201);
const displaced = await request(app.getHttpServer())
.get(`/api/v1/queens/${queenId}`)
.set('Authorization', `Bearer ${beekeeperToken}`)
.expect(200);
expect(displaced.body).toMatchObject({
status: 'REPLACED',
deactivatedAt: expect.any(String) as string,
});
});
});