Refactored newFilamentStockRouteHandler test to accommodate updated filament stock structure, including net and gross weight properties. Adjusted mock implementations to ensure accurate testing of stock creation and event handling.
All checks were successful
farmcontrol/farmcontrol-api/pipeline/head This commit looks good

This commit is contained in:
Tom Butcher 2026-07-26 19:28:01 +01:00
parent 5ee8f332e2
commit 6f59f75b41

View File

@ -74,13 +74,18 @@ describe('Filament Stock Service Route Handlers', () => {
describe('newFilamentStockRouteHandler', () => {
it('should create a new filament stock', async () => {
req.body = { filament: 'filament123', currentWeight: 1000 };
req.body = {
filament: 'filament123',
startingWeight: { net: 1000, gross: 1100 },
currentWeight: { net: 1000, gross: 1100 },
};
const mockStock = { _id: '456', ...req.body };
newObject.mockResolvedValue(mockStock);
const mockStockEvent = { _id: '789' };
newObject.mockResolvedValueOnce(mockStock).mockResolvedValueOnce(mockStockEvent);
await newFilamentStockRouteHandler(req, res);
expect(newObject).toHaveBeenCalled();
expect(newObject).toHaveBeenCalledTimes(2);
expect(res.send).toHaveBeenCalledWith(mockStock);
});
});