Files
gongxue-base/apps/admin/src/pages/Occupancies/occupancy-form.integration.test.ts

76 lines
1.9 KiB
TypeScript

import { describe, expect, it } from 'vitest';
import dayjs from 'dayjs';
import { buildCheckInPayload, buildTransferPayload } from './occupancy-form';
describe('occupancy check-in form', () => {
it('submits all required manual check-in fields with defaults', () => {
expect(
buildCheckInPayload({
studentId: 1,
roomId: 2,
checkInDate: dayjs('2026-07-18'),
billingStartDate: dayjs('2026-07-18'),
stayType: 'short',
collectDeposit: true,
depositAmount: 500,
bedId: 3,
notes: ' 备注 ',
}),
).toEqual({
studentId: 1,
roomId: 2,
checkInDate: '2026-07-18',
billingStartDate: '2026-07-18',
stayType: 'short',
collectDeposit: true,
depositAmount: 500,
notes: '备注',
bedId: 3,
lockerId: undefined,
});
});
it('falls back to check-in date and short stay type', () => {
expect(
buildCheckInPayload({
studentId: 1,
roomId: 2,
checkInDate: dayjs('2026-07-18'),
collectDeposit: false,
bedId: 3,
}),
).toEqual(
expect.objectContaining({
billingStartDate: '2026-07-18',
stayType: 'short',
collectDeposit: false,
depositAmount: undefined,
}),
);
});
});
describe('occupancy transfer form', () => {
it('submits the target room resources with the transfer dates', () => {
expect(
buildTransferPayload({
newRoomId: 5,
newBedId: 12,
newLockerId: 18,
transferDate: dayjs('2026-07-13'),
oldBillingEndDate: dayjs('2026-07-13'),
newBillingStartDate: dayjs('2026-07-14'),
reason: '调整宿舍',
}),
).toEqual({
newRoomId: 5,
newBedId: 12,
newLockerId: 18,
transferDate: '2026-07-13',
oldBillingEndDate: '2026-07-13',
newBillingStartDate: '2026-07-14',
reason: '调整宿舍',
});
});
});