-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathbroker.controller.spec.ts
More file actions
117 lines (100 loc) · 3.5 KB
/
broker.controller.spec.ts
File metadata and controls
117 lines (100 loc) · 3.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
import { Test, TestingModule } from '@nestjs/testing';
import { BrokerController } from './broker.controller';
import { BrokerService } from './broker.service';
describe('BrokerController', () => {
let controller: BrokerController;
let brokerService: jest.Mocked<BrokerService>;
beforeEach(async () => {
const mockBrokerService = {
getBrokers: jest.fn(),
stopBroker: jest.fn(),
startBroker: jest.fn(),
restartBroker: jest.fn(),
getBrokerStatus: jest.fn(),
startAllBrokers: jest.fn(),
stopAllBrokers: jest.fn(),
addDbmtUser: jest.fn(),
updateDbmtUser: jest.fn(),
};
const module: TestingModule = await Test.createTestingModule({
controllers: [BrokerController],
providers: [
{
provide: BrokerService,
useValue: mockBrokerService,
},
],
}).compile();
controller = module.get<BrokerController>(BrokerController);
brokerService = module.get(BrokerService);
});
it('should be defined', () => {
expect(controller).toBeDefined();
});
describe('startAllBrokers', () => {
it('should call brokerService.startAllBrokers and return { success: true }', async () => {
const req = { user: { sub: 'user-123' } };
brokerService.startAllBrokers.mockResolvedValue({ success: true });
const result = await controller.startAllBrokers(req, 'host-uid-1');
expect(brokerService.startAllBrokers).toHaveBeenCalledWith(
'user-123',
'host-uid-1'
);
expect(result).toEqual({ success: true });
});
});
describe('stopAllBrokers', () => {
it('should call brokerService.stopAllBrokers and return { success: true }', async () => {
const req = { user: { sub: 'user-123' } };
brokerService.stopAllBrokers.mockResolvedValue({ success: true });
const result = await controller.stopAllBrokers(req, 'host-uid-1');
expect(brokerService.stopAllBrokers).toHaveBeenCalledWith(
'user-123',
'host-uid-1'
);
expect(result).toEqual({ success: true });
});
});
describe('addDbmtUser', () => {
it('should call brokerService.addDbmtUser and return dblist and userlist', async () => {
const req = { user: { sub: 'user-123' } };
const body = {
targetid: 'test_user_2',
password: '1234',
casauth: 'none',
dbcreate: 'none',
statusmonitorauth: 'none',
};
const mockResponse = { dblist: [], userlist: [] };
brokerService.addDbmtUser.mockResolvedValue(mockResponse);
const result = await controller.addDbmtUser(req, 'host-uid-1', body);
expect(brokerService.addDbmtUser).toHaveBeenCalledWith(
'user-123',
'host-uid-1',
body
);
expect(result).toEqual(mockResponse);
});
});
describe('updateDbmtUser', () => {
it('should call brokerService.updateDbmtUser and return dblist and userlist', async () => {
const req = { user: { sub: 'user-123' } };
const body = {
targetid: 'test_user_2',
dbauth: [],
casauth: 'none',
dbcreate: 'none',
statusmonitorauth: 'none',
};
const mockResponse = { dblist: [], userlist: [] };
brokerService.updateDbmtUser.mockResolvedValue(mockResponse);
const result = await controller.updateDbmtUser(req, 'host-uid-1', body);
expect(brokerService.updateDbmtUser).toHaveBeenCalledWith(
'user-123',
'host-uid-1',
body
);
expect(result).toEqual(mockResponse);
});
});
});