add tests and registry
This commit is contained in:
@@ -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')
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user