feat: streamline occupancy check-in and imports
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import { ValidationPipe } from '@nestjs/common';
|
||||
import { validate } from 'class-validator';
|
||||
import { CheckInDto, TransferRoomDto } from './occupancy.dto';
|
||||
|
||||
@@ -14,6 +15,50 @@ describe('manual occupancy DTO bed requirements', () => {
|
||||
expect(errors.some((error) => error.property === 'bedId')).toBe(true);
|
||||
});
|
||||
|
||||
it('accepts optional deposit collection details for manual check-in', async () => {
|
||||
const dto = Object.assign(new CheckInDto(), {
|
||||
studentId: 1,
|
||||
roomId: 2,
|
||||
checkInDate: '2026-07-13',
|
||||
bedId: 3,
|
||||
collectDeposit: true,
|
||||
depositAmount: 500,
|
||||
});
|
||||
|
||||
await expect(validate(dto)).resolves.toHaveLength(0);
|
||||
});
|
||||
|
||||
it('rejects a non-positive deposit amount', async () => {
|
||||
const dto = Object.assign(new CheckInDto(), {
|
||||
studentId: 1,
|
||||
roomId: 2,
|
||||
checkInDate: '2026-07-13',
|
||||
bedId: 3,
|
||||
collectDeposit: true,
|
||||
depositAmount: 0,
|
||||
});
|
||||
|
||||
const errors = await validate(dto);
|
||||
|
||||
expect(errors.some((error) => error.property === 'depositAmount')).toBe(true);
|
||||
});
|
||||
|
||||
it('strips a manually supplied responsible organization', async () => {
|
||||
const pipe = new ValidationPipe({ transform: true, whitelist: true });
|
||||
const dto = await pipe.transform(
|
||||
{
|
||||
studentId: 1,
|
||||
roomId: 2,
|
||||
checkInDate: '2026-07-13',
|
||||
bedId: 3,
|
||||
responsibleOrganizationId: 99,
|
||||
},
|
||||
{ type: 'body', metatype: CheckInDto },
|
||||
);
|
||||
|
||||
expect(dto).not.toHaveProperty('responsibleOrganizationId');
|
||||
});
|
||||
|
||||
it('requires a new bed for a room transfer while keeping the locker optional', async () => {
|
||||
const dto = Object.assign(new TransferRoomDto(), {
|
||||
newRoomId: 3,
|
||||
|
||||
Reference in New Issue
Block a user