Skip to content

Commit 1249c81

Browse files
chore: updated Tests
1 parent 262cba7 commit 1249c81

File tree

1 file changed

+28
-43
lines changed

1 file changed

+28
-43
lines changed

__tests__/unit/logic.test.ts

Lines changed: 28 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -154,10 +154,8 @@ describe('TADProc Service', () => {
154154
const channelResult = requestBody.channelResult;
155155
const message = networkMap.messages.find((tran) => tran.txTp === transaction.TxTp);
156156

157-
if (message) {
158-
const result = await handleChannels(message, transaction, networkMap, channelResult);
159-
expect(result).toBeDefined();
160-
}
157+
const result = await handleChannels(message!, transaction, networkMap, channelResult);
158+
expect(result).toBeDefined();
161159
});
162160

163161
it('should handle successful request, all channels not found', async () => {
@@ -166,10 +164,8 @@ describe('TADProc Service', () => {
166164
const channelResult = requestBody.channelResult;
167165
const message = networkMap.messages.find((tran) => tran.txTp === transaction.TxTp);
168166

169-
if (message) {
170-
const result = await handleChannels(message, transaction, networkMap, channelResult);
171-
expect(result).toBeDefined();
172-
}
167+
const result = await handleChannels(message!, transaction, networkMap, channelResult);
168+
expect(result).toBeDefined();
173169
});
174170

175171
it('should handle successful request, above threshold', async () => {
@@ -224,12 +220,10 @@ describe('TADProc Service', () => {
224220
const channelResult = requestBody.channelResult;
225221
const message = networkMap.messages.find((tran) => tran.txTp === transaction.TxTp);
226222

227-
if (message) {
228-
const result = await handleChannels(message, transaction, networkMap, channelResult);
229-
expect(result).toBeDefined();
230-
if (result[0]?.status) expect(result[0].status).toBe('ALRT');
231-
else throw 'Test failed - expect response to be called';
232-
}
223+
const result = await handleChannels(message!, transaction, networkMap, channelResult);
224+
expect(result).toBeDefined();
225+
if (result[0]?.status) expect(result[0].status).toBe('ALRT');
226+
else throw 'Test failed - expect response to be called';
233227
});
234228

235229
it('should handle successful request, below threshold', async () => {
@@ -285,13 +279,10 @@ describe('TADProc Service', () => {
285279
const networkMap = requestBody.networkMap as NetworkMap;
286280
const channelResult = requestBody.channelResult;
287281
const message = networkMap.messages.find((tran) => tran.txTp === transaction.TxTp);
282+
const result = await handleChannels(message!, transaction, networkMap, channelResult);
288283

289-
if (message) {
290-
const result = await handleChannels(message, transaction, networkMap, channelResult);
291-
292-
if (result[0]?.status) expect(result[0].status).toBe('NALT');
293-
else throw 'Test failed - expect response to be called';
294-
}
284+
if (result[0]?.status) expect(result[0].status).toBe('NALT');
285+
else throw 'Test failed - expect response to be called';
295286
});
296287

297288
it('should handle successful request, already processed', async () => {
@@ -321,10 +312,8 @@ describe('TADProc Service', () => {
321312
const channelResult = requestBody.channelResult;
322313
const message = networkMap.messages.find((tran) => tran.txTp === transaction.TxTp);
323314

324-
if (message) {
325-
const result = await handleChannels(message, transaction, networkMap, channelResult);
326-
expect(result).toBeDefined();
327-
}
315+
const result = await handleChannels(message!, transaction, networkMap, channelResult);
316+
expect(result).toBeDefined();
328317
});
329318

330319
it('should throw error if no config', async () => {
@@ -339,10 +328,8 @@ describe('TADProc Service', () => {
339328
const channelResult = requestBody.channelResult;
340329
const message = networkMap.messages.find((tran) => tran.txTp === transaction.TxTp);
341330

342-
if (message) {
343-
const result = await handleChannels(message, transaction, networkMap, channelResult);
344-
expect(server.handleResponse).toHaveBeenCalledTimes(0);
345-
}
331+
const result = await handleChannels(message!, transaction, networkMap, channelResult);
332+
expect(server.handleResponse).toHaveBeenCalledTimes(0);
346333
});
347334

348335
it('should handle error in handleChannels', async () => {
@@ -357,12 +344,10 @@ describe('TADProc Service', () => {
357344
const channelResult = requestBody.channelResult;
358345
const message = networkMap.messages.find((tran) => tran.txTp === transaction.TxTp);
359346

360-
if (message) {
361-
const thrownFunction = await handleChannels(message, transaction, networkMap, channelResult);
362-
try {
363-
expect(await thrownFunction).toThrow();
364-
} catch (err) {}
365-
}
347+
const thrownFunction = await handleChannels(message!, transaction, networkMap, channelResult);
348+
try {
349+
expect(await thrownFunction).toThrow();
350+
} catch (err) {}
366351
});
367352

368353
it('should handle error in handleChannels, wrong transaction type.', async () => {
@@ -375,9 +360,13 @@ describe('TADProc Service', () => {
375360
const message = networkMap.messages.find((tran) => tran.txTp === transaction.TxTp);
376361
const channelResult = requestBody.channelResult;
377362

378-
if (message) {
379-
const result = await handleChannels(message, transaction, networkMap, channelResult);
363+
try {
364+
const result = await handleChannels(message!, transaction, networkMap, channelResult);
365+
expect(result).toBeNull();
366+
} catch (error) {
367+
expect(error).toStrictEqual(new TypeError(`Cannot read properties of undefined (reading 'id')`));
380368
}
369+
// await handleChannels(message!, transaction, networkMap, channelResult);
381370
});
382371

383372
it('should handle error in networkmap', async () => {
@@ -390,9 +379,7 @@ describe('TADProc Service', () => {
390379
const channelResult = errorRequestBody.channelResult;
391380
const message = networkMap.messages.find((tran) => tran.txTp === transaction.TxTp);
392381

393-
if (message) {
394-
await handleChannels(message, transaction, networkMap, channelResult);
395-
}
382+
await handleChannels(message!, transaction, networkMap, channelResult);
396383
});
397384

398385
it('should handle error in networkmap, no configuration returned', async () => {
@@ -458,10 +445,8 @@ describe('TADProc Service', () => {
458445
const channelResult = requestBody.channelResult;
459446
const message = networkMap.messages.find((tran) => tran.txTp === transaction.TxTp);
460447

461-
if (message) {
462-
const result = await handleChannels(message, transaction, networkMap, channelResult);
463-
expect(result).toBeDefined();
464-
}
448+
const result = await handleChannels(message!, transaction, networkMap, channelResult);
449+
expect(result).toBeDefined();
465450
});
466451
});
467452

0 commit comments

Comments
 (0)