feat(queens): verdrängte Königin bekommt ihren Endstatus automatisch
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:
1 parent
f9e03a1695
commit
81927d629a
10 files changed
+205
-4
No files matched your search
@@ -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, {
|
||||
|
||||
Reference in new issue
Block a user