add tests and registry

This commit is contained in:
root
2026-05-22 02:58:59 -04:00
parent 99c429d69c
commit b9197bcb5d
10 changed files with 480 additions and 16 deletions
@@ -122,4 +122,27 @@ describe('vehicle.service', () => {
expect(result).toEqual({ id: 'block_1' })
})
})
describe('getMaintenanceLogs', () => {
it('throws NotFoundError when vehicle does not belong to the requesting company', async () => {
vi.mocked(repo.findById).mockResolvedValue(null)
await expect(service.getMaintenanceLogs('veh_1', 'other_company')).rejects.toThrow('Vehicle not found')
})
it('returns maintenance logs when vehicle belongs to the requesting company', async () => {
const mockLogs = [{ id: 'log_1', vehicleId: 'veh_1', description: 'Oil change' }]
vi.mocked(repo.findById).mockResolvedValue(mockVehicle as any)
vi.mocked(repo.findMaintenanceLogs).mockResolvedValue(mockLogs as any)
const result = await service.getMaintenanceLogs('veh_1', 'comp_1')
expect(repo.findById).toHaveBeenCalledWith('veh_1', 'comp_1')
expect(result).toEqual(mockLogs)
})
it('passes companyId to repo.findById for ownership validation', async () => {
vi.mocked(repo.findById).mockResolvedValue(mockVehicle as any)
vi.mocked(repo.findMaintenanceLogs).mockResolvedValue([])
await service.getMaintenanceLogs('veh_1', 'comp_1')
expect(repo.findById).toHaveBeenCalledWith('veh_1', 'comp_1')
})
})
})