Skip to content

Commit d279fc0

Browse files
committed
#127 issue no creating test casses for infrastructure endpoint done here
1 parent 56c132d commit d279fc0

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed

test/routes/infrastructure.test.js

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
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

Comments
 (0)