@@ -15,6 +15,7 @@ import { UserService } from '../user/user.service';
15
15
16
16
describe ( 'TradebotController' , ( ) => {
17
17
let controller : TradebotController ;
18
+ // let tradebotService: TradebotService;
18
19
19
20
beforeEach ( async ( ) => {
20
21
const module : TestingModule = await Test . createTestingModule ( {
@@ -38,9 +39,261 @@ describe('TradebotController', () => {
38
39
} ) . compile ( ) ;
39
40
40
41
controller = module . get < TradebotController > ( TradebotController ) ;
42
+ // tradebotService = module.get<TradebotService>(TradebotService);
41
43
} ) ;
42
44
43
45
it ( 'should be defined' , ( ) => {
44
46
expect ( controller ) . toBeDefined ( ) ;
45
47
} ) ;
46
48
} ) ;
49
+ // TODO: (20240325 - Jacky) Should be finish in the future for higher quality
50
+ // describe('create', () => {
51
+ // it('should create a tradebot and return the tradebot details', async () => {
52
+ // const createTradebotResult = {
53
+ // returnDeposit: true,
54
+ // tradebot: {
55
+ // id: '1',
56
+ // created_at: '2022-01-01',
57
+ // wallet: {
58
+ // address: 'address',
59
+ // privateKey: 'privateKey',
60
+ // },
61
+ // currentAsset: {
62
+ // data: {
63
+ // balance: {
64
+ // available: 100,
65
+ // },
66
+ // },
67
+ // },
68
+ // },
69
+ // };
70
+ // jest
71
+ // .spyOn(tradebotService, 'create')
72
+ // .mockImplementation(async);
73
+
74
+ // const result = await controller.create();
75
+
76
+ // expect(result).toEqual(
77
+ // 'Tradebot 1 created at 2022-01-01 public address is address private key is privateKey and received deposit is true and currentAvailable = 100',
78
+ // );
79
+ // });
80
+
81
+ // it('should return an error message if tradebot creation fails', async () => {
82
+ // jest.spyOn(tradebotService, 'create').mockResolvedValue(null);
83
+
84
+ // const result = await controller.create();
85
+
86
+ // expect(result).toEqual('Tradebot not created');
87
+ // });
88
+
89
+ // it('should return an error message if deposit is not successful', async () => {
90
+ // const createTradebotResult = {
91
+ // returnDeposit: false,
92
+ // tradebot: {
93
+ // id: '1',
94
+ // created_at: '2022-01-01',
95
+ // wallet: {
96
+ // address: 'address',
97
+ // privateKey: 'privateKey',
98
+ // },
99
+ // currentAsset: {
100
+ // data: {
101
+ // balance: {
102
+ // available: 100,
103
+ // },
104
+ // },
105
+ // },
106
+ // },
107
+ // };
108
+ // jest
109
+ // .spyOn(tradebotService, 'create')
110
+ // .mockResolvedValue(createTradebotResult);
111
+
112
+ // const result = await controller.create();
113
+
114
+ // expect(result).toEqual('Tradebot is created, but deposit is not successful');
115
+ // });
116
+ // });
117
+
118
+ // describe('getTradebot', () => {
119
+ // it('should return all tradebots if id is not provided', async () => {
120
+ // const tradebotArray = [
121
+ // {
122
+ // id: '1',
123
+ // toJSON: () => ({
124
+ // id: '1',
125
+ // wallet: {
126
+ // privateKey: 'privateKey',
127
+ // },
128
+ // }),
129
+ // },
130
+ // {
131
+ // id: '2',
132
+ // toJSON: () => ({
133
+ // id: '2',
134
+ // wallet: {
135
+ // privateKey: 'privateKey',
136
+ // },
137
+ // }),
138
+ // },
139
+ // ];
140
+ // jest.spyOn(tradebotService, 'getAllTradebots').mockResolvedValue(tradebotArray);
141
+
142
+ // const result = await controller.getTradebot();
143
+
144
+ // expect(result).toEqual([
145
+ // {
146
+ // tradebot: {
147
+ // id: '1',
148
+ // wallet: {
149
+ // privateKey: 'privateKey',
150
+ // },
151
+ // },
152
+ // 'private key': 'privateKey',
153
+ // },
154
+ // {
155
+ // tradebot: {
156
+ // id: '2',
157
+ // wallet: {
158
+ // privateKey: 'privateKey',
159
+ // },
160
+ // },
161
+ // 'private key': 'privateKey',
162
+ // },
163
+ // ]);
164
+ // });
165
+
166
+ // it('should return a tradebot by id', async () => {
167
+ // const tradebot = {
168
+ // id: '1',
169
+ // toJSON: () => ({
170
+ // id: '1',
171
+ // wallet: {
172
+ // privateKey: 'privateKey',
173
+ // },
174
+ // }),
175
+ // };
176
+ // jest.spyOn(tradebotService, 'getTradebotById').mockResolvedValue(tradebot);
177
+
178
+ // const result = await controller.getTradebot('1');
179
+
180
+ // expect(result).toEqual({
181
+ // tradebot: {
182
+ // id: '1',
183
+ // wallet: {
184
+ // privateKey: 'privateKey',
185
+ // },
186
+ // },
187
+ // 'private key': 'privateKey',
188
+ // });
189
+ // });
190
+ // });
191
+
192
+ // describe('updateTradebot', () => {
193
+ // it('should update a tradebot and return the updated tradebot details', async () => {
194
+ // const tradebot = {
195
+ // id: '1',
196
+ // toJSON: () => ({
197
+ // id: '1',
198
+ // }),
199
+ // };
200
+ // const updatedTradebot = {
201
+ // id: '1',
202
+ // toJSON: () => ({
203
+ // id: '1',
204
+ // }),
205
+ // };
206
+ // const data = {
207
+ // suggestion: 'suggestion',
208
+ // tradeStrategy: 'tradeStrategy',
209
+ // stopLoss: 'stopLoss',
210
+ // takeProfit: 'takeProfit',
211
+ // };
212
+ // jest.spyOn(tradebotService, 'getTradebotById').mockResolvedValue(tradebot);
213
+ // jest.spyOn(tradebotService, 'updateTradebot').mockResolvedValue(updatedTradebot);
214
+
215
+ // const result = await controller.updateTradebot('1', data);
216
+
217
+ // expect(result).toEqual('1 is updated and tradebot = {"id":"1"}');
218
+ // });
219
+
220
+ // it('should return an error message if tradebot is not found', async () => {
221
+ // jest.spyOn(tradebotService, 'getTradebotById').mockResolvedValue(null);
222
+
223
+ // const result = await controller.updateTradebot('1', {});
224
+
225
+ // expect(result).toEqual('Tradebot not found');
226
+ // });
227
+ // });
228
+
229
+ // describe('command', () => {
230
+ // it('should run a command to start the tradebot', async () => {
231
+ // const tradebot = {
232
+ // id: '1',
233
+ // };
234
+ // jest.spyOn(tradebotService, 'getTradebotById').mockResolvedValue(tradebot);
235
+ // jest.spyOn(tradebotService, 'run').mockReturnValue('Run command executed');
236
+
237
+ // const result = await controller.command('1', { strategy: 'strategy', command: 'run' });
238
+
239
+ // expect(result).toEqual('Run command executed');
240
+ // });
241
+
242
+ // it('should run a command to stop the tradebot', async () => {
243
+ // const tradebot = {
244
+ // id: '1',
245
+ // };
246
+ // jest.spyOn(tradebotService, 'getTradebotById').mockResolvedValue(tradebot);
247
+ // jest.spyOn(tradebotService, 'stop').mockReturnValue('Stop command executed');
248
+
249
+ // const result = await controller.command('1', { strategy: 'strategy', command: 'stop' });
250
+
251
+ // expect(result).toEqual('Stop command executed');
252
+ // });
253
+
254
+ // it('should run a command to receive deposit for the tradebot', async () => {
255
+ // const tradebot = {
256
+ // id: '1',
257
+ // };
258
+ // jest.spyOn(tradebotService, 'getTradebotById').mockResolvedValue(tradebot);
259
+ // jest.spyOn(tradebotService, 'receiveDeposit').mockReturnValue('Deposit command executed');
260
+
261
+ // const result = await controller.command('1', { strategy: 'strategy', command: 'deposit' });
262
+
263
+ // expect(result).toEqual('Deposit command executed');
264
+ // });
265
+
266
+ // it('should return an error message for an invalid command', async () => {
267
+ // const tradebot = {
268
+ // id: '1',
269
+ // };
270
+ // jest.spyOn(tradebotService, 'getTradebotById').mockResolvedValue(tradebot);
271
+
272
+ // const result = await controller.command('1', { strategy: 'strategy', command: 'invalid' });
273
+
274
+ // expect(result).toEqual('invalid is invalid command');
275
+ // });
276
+
277
+ // it('should return an error message if tradebot is not found', async () => {
278
+ // jest.spyOn(tradebotService, 'getTradebotById').mockResolvedValue(null);
279
+
280
+ // const result = await controller.command('1', { strategy: 'strategy', command: 'run' });
281
+
282
+ // expect(result).toEqual('Tradebot not found');
283
+ // });
284
+
285
+ // it('should return an error message if an exception occurs', async () => {
286
+ // const tradebot = {
287
+ // id: '1',
288
+ // };
289
+ // jest.spyOn(tradebotService, 'getTradebotById').mockResolvedValue(tradebot);
290
+ // jest.spyOn(tradebotService, 'run').mockImplementation(() => {
291
+ // throw new Error('An error occurred');
292
+ // });
293
+
294
+ // const result = await controller.command('1', { strategy: 'strategy', command: 'run' });
295
+
296
+ // expect(result).toEqual('An error occurred');
297
+ // });
298
+ // });
299
+ // });
0 commit comments