|
| 1 | +import infrastructureController from '../controllers/infrastructure'; |
| 2 | + |
| 3 | +describe('Infrastructure Controller', () => { |
| 4 | + const mockInfrastructure = { |
| 5 | + name: 'Building A', |
| 6 | + type: 'Office', |
| 7 | + wing: 'East', |
| 8 | + floor: 3, |
| 9 | + capacity: 100, |
| 10 | + }; |
| 11 | + |
| 12 | + it('should add infrastructure', async () => { |
| 13 | + const createSpy = jest.spyOn(infrastructureController, 'create'); |
| 14 | + createSpy.mockResolvedValue(mockInfrastructure); |
| 15 | + |
| 16 | + const result = await infrastructureController.addInfrastructure(mockInfrastructure); |
| 17 | + expect(result).toEqual(mockInfrastructure); |
| 18 | + expect(createSpy).toHaveBeenCalledWith( |
| 19 | + mockInfrastructure.name, |
| 20 | + mockInfrastructure.type, |
| 21 | + mockInfrastructure.wing, |
| 22 | + mockInfrastructure.floor, |
| 23 | + mockInfrastructure.capacity |
| 24 | + ); |
| 25 | + }); |
| 26 | + |
| 27 | + it('should read infrastructure', async () => { |
| 28 | + const filter = { name: 'Building A' }; |
| 29 | + const limit = 5; |
| 30 | + const readSpy = jest.spyOn(infrastructureController, 'read'); |
| 31 | + readSpy.mockResolvedValue([mockInfrastructure]); |
| 32 | + |
| 33 | + const result = await infrastructureController.readInfrastructure(filter, limit); |
| 34 | + expect(result).toEqual([mockInfrastructure]); |
| 35 | + expect(readSpy).toHaveBeenCalledWith(filter, limit); |
| 36 | + }); |
| 37 | + |
| 38 | + it('should update infrastructure', async () => { |
| 39 | + const filter = { name: 'Building A' }; |
| 40 | + const updateData = { capacity: 150 }; |
| 41 | + const updatedInfrastructure = { ...mockInfrastructure, capacity: 150 }; |
| 42 | + const updateSpy = jest.spyOn(infrastructureController, 'update'); |
| 43 | + updateSpy.mockResolvedValue(updatedInfrastructure); |
| 44 | + |
| 45 | + const result = await infrastructureController.updateInfrastructure(filter, updateData); |
| 46 | + expect(result).toEqual(updatedInfrastructure); |
| 47 | + expect(updateSpy).toHaveBeenCalledWith(filter, updateData); |
| 48 | + }); |
| 49 | + |
| 50 | + it('should remove infrastructure', async () => { |
| 51 | + const filter = { name: 'Building A' }; |
| 52 | + const removedInfrastructure = { ...mockInfrastructure }; |
| 53 | + const removeSpy = jest.spyOn(infrastructureController, 'remove'); |
| 54 | + removeSpy.mockResolvedValue(removedInfrastructure); |
| 55 | + |
| 56 | + const result = await infrastructureController.removeInfrastructure(filter); |
| 57 | + expect(result).toEqual(removedInfrastructure); |
| 58 | + expect(removeSpy).toHaveBeenCalledWith(filter); |
| 59 | + }); |
| 60 | +}); |
0 commit comments