feat: Schwarmkontrolle-Protokoll
Neues SwarmControlCheck-Modul: strukturierte Weiselzellenkontrollen pro Volk mit Zahl/Verdeckelungsstatus der Zellen, Schwarmstimmung, ergriffener Maßnahme und optionalem naechsten Kontrolltermin. Frontend: neue Karte auf der Volk-Detailseite, Erfassungsformular unter /swarm-control/new sowie Quick-Add-Eintrag.
This commit is contained in:
1 parent
4609a0f9ec
commit
1a7331b6b2
19 files changed
+1076
No files matched your search
@@ -0,0 +1,127 @@
|
||||
import { INestApplication } from '@nestjs/common';
|
||||
import * as bcrypt from 'bcryptjs';
|
||||
import request from 'supertest';
|
||||
import { App } from 'supertest/types';
|
||||
import { PrismaService } from '../src/prisma/prisma.service';
|
||||
import { createTestApp } from './utils/create-test-app';
|
||||
import { login } from './utils/api';
|
||||
|
||||
interface SwarmControlCheckBody {
|
||||
id: string;
|
||||
colonyId: string;
|
||||
queenCellsCapped: boolean;
|
||||
}
|
||||
|
||||
describe('Swarm control checks (e2e)', () => {
|
||||
let app: INestApplication<App>;
|
||||
let prisma: PrismaService;
|
||||
const beekeeperEmail = `swarm-control-e2e-beekeeper-${Date.now()}@example.com`;
|
||||
const staffEmail = `swarm-control-e2e-staff-${Date.now()}@example.com`;
|
||||
const password = 'SuperSecret123!';
|
||||
let beekeeperId: string;
|
||||
let staffId: string;
|
||||
let beekeeperToken: string;
|
||||
let staffToken: string;
|
||||
let apiaryId: string;
|
||||
let colonyId: string;
|
||||
let checkId: string;
|
||||
|
||||
beforeAll(async () => {
|
||||
app = await createTestApp();
|
||||
prisma = app.get(PrismaService);
|
||||
|
||||
const passwordHash = await bcrypt.hash(password, 12);
|
||||
const beekeeper = await prisma.user.create({
|
||||
data: {
|
||||
email: beekeeperEmail,
|
||||
passwordHash,
|
||||
name: 'Beekeeper',
|
||||
role: 'BEEKEEPER',
|
||||
},
|
||||
});
|
||||
beekeeperId = beekeeper.id;
|
||||
const staff = await prisma.user.create({
|
||||
data: { email: staffEmail, passwordHash, name: 'Staff', role: 'STAFF' },
|
||||
});
|
||||
staffId = staff.id;
|
||||
beekeeperToken = (await login(app, beekeeperEmail, password)).accessToken;
|
||||
staffToken = (await login(app, staffEmail, password)).accessToken;
|
||||
|
||||
const apiary = await prisma.apiary.create({
|
||||
data: { name: `Stand ${Date.now()}` },
|
||||
});
|
||||
apiaryId = apiary.id;
|
||||
const colony = await prisma.colony.create({
|
||||
data: {
|
||||
code: `V-${Date.now()}`,
|
||||
apiaryId,
|
||||
colonyType: 'PRODUCTION_COLONY',
|
||||
},
|
||||
});
|
||||
colonyId = colony.id;
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
await prisma.swarmControlCheck.deleteMany({ where: { colonyId } });
|
||||
await prisma.colony.deleteMany({ where: { id: colonyId } });
|
||||
await prisma.apiary.deleteMany({ where: { id: apiaryId } });
|
||||
await prisma.refreshToken.deleteMany({
|
||||
where: { userId: { in: [beekeeperId, staffId] } },
|
||||
});
|
||||
await prisma.auditLog.deleteMany({
|
||||
where: { userId: { in: [beekeeperId, staffId] } },
|
||||
});
|
||||
await prisma.user.deleteMany({
|
||||
where: { id: { in: [beekeeperId, staffId] } },
|
||||
});
|
||||
await app.close();
|
||||
});
|
||||
|
||||
it('rejects create for a STAFF user', () => {
|
||||
return request(app.getHttpServer())
|
||||
.post('/api/v1/swarm-control-checks')
|
||||
.set('Authorization', `Bearer ${staffToken}`)
|
||||
.send({ colonyId, date: new Date().toISOString() })
|
||||
.expect(403);
|
||||
});
|
||||
|
||||
it('lets a BEEKEEPER user record a check', async () => {
|
||||
const response = await request(app.getHttpServer())
|
||||
.post('/api/v1/swarm-control-checks')
|
||||
.set('Authorization', `Bearer ${beekeeperToken}`)
|
||||
.send({
|
||||
colonyId,
|
||||
date: new Date().toISOString(),
|
||||
queenCellsFound: 2,
|
||||
queenCellsCapped: false,
|
||||
swarmMood: 'LOW',
|
||||
})
|
||||
.expect(201);
|
||||
checkId = (response.body as SwarmControlCheckBody).id;
|
||||
expect(checkId).toEqual(expect.any(String));
|
||||
});
|
||||
|
||||
it('lists checks for the colony', async () => {
|
||||
const response = await request(app.getHttpServer())
|
||||
.get(`/api/v1/colonies/${colonyId}/swarm-control-checks`)
|
||||
.set('Authorization', `Bearer ${staffToken}`)
|
||||
.expect(200);
|
||||
const checks = response.body as SwarmControlCheckBody[];
|
||||
expect(checks.some((entry) => entry.id === checkId)).toBe(true);
|
||||
});
|
||||
|
||||
it('updates a check to record capped queen cells', async () => {
|
||||
const response = await request(app.getHttpServer())
|
||||
.patch(`/api/v1/swarm-control-checks/${checkId}`)
|
||||
.set('Authorization', `Bearer ${beekeeperToken}`)
|
||||
.send({
|
||||
queenCellsCapped: true,
|
||||
actionTaken: 'ARTIFICIAL_SWARM',
|
||||
nextCheckDate: new Date().toISOString(),
|
||||
})
|
||||
.expect(200);
|
||||
expect((response.body as SwarmControlCheckBody).queenCellsCapped).toBe(
|
||||
true,
|
||||
);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user