Skip to content

Commit 52de078

Browse files
committed
Added unit test to TransactionSchedulerService.
Signed-off-by: Eric Le Ponner <eric.leponner@icloud.com>
1 parent ada4f2f commit 52de078

2 files changed

Lines changed: 43 additions & 3 deletions

File tree

back-end/apps/chain/src/transaction-scheduler/transaction-scheduler.service.spec.ts

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818
TransactionGroup,
1919
TransactionGroupItem,
2020
TransactionStatus,
21+
UserKey,
2122
} from '@entities';
2223

2324
import { TransactionSchedulerService } from './transaction-scheduler.service';
@@ -528,7 +529,7 @@ describe('TransactionStatusService', () => {
528529
id: 1,
529530
atomic: false,
530531
sequential: true,
531-
}
532+
},
532533
},
533534
} as Transaction,
534535
{
@@ -541,7 +542,7 @@ describe('TransactionStatusService', () => {
541542
id: 1,
542543
atomic: false,
543544
sequential: true,
544-
}
545+
},
545546
},
546547
} as Transaction,
547548
];
@@ -553,6 +554,45 @@ describe('TransactionStatusService', () => {
553554

554555
expect(service.collateGroupAndExecute).toHaveBeenCalledTimes(1);
555556
});
557+
558+
it('should not call collateGroupAndExecute when transactionGroup is null', async () => {
559+
const transactionGroups = [
560+
{
561+
id: 1,
562+
status: TransactionStatus.WAITING_FOR_EXECUTION,
563+
validStart: new Date(),
564+
groupItem: {
565+
groupId: 1,
566+
group: {
567+
id: 1,
568+
atomic: false,
569+
sequential: true,
570+
},
571+
},
572+
} as Transaction,
573+
{
574+
id: 3,
575+
status: TransactionStatus.WAITING_FOR_EXECUTION,
576+
validStart: new Date(),
577+
groupItem: {
578+
groupId: 1,
579+
group: {
580+
id: 1,
581+
atomic: false,
582+
sequential: true,
583+
},
584+
},
585+
} as Transaction,
586+
];
587+
588+
transactionGroupRepo.findOne.mockResolvedValueOnce(null);
589+
jest.spyOn(service, 'collateGroupAndExecute').mockImplementation(jest.fn());
590+
jest.spyOn(service, 'isValidStartExecutable').mockImplementation(() => true);
591+
592+
await service.prepareTransactions(transactionGroups);
593+
594+
expect(service.collateGroupAndExecute).toHaveBeenCalledTimes(0);
595+
});
556596
});
557597

558598
describe('collateGroupAndExecute', () => {

back-end/apps/chain/src/transaction-scheduler/transaction-scheduler.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ export class TransactionSchedulerService {
214214
},
215215
},
216216
});
217-
if (transactionGroup !== null) {
217+
if (transactionGroup) {
218218
// All the transactions for the group are now pulled. If there is an issue validating for even one
219219
// transaction, the group will not be executed. This is handled in executeTransactionGroup
220220
this.collateGroupAndExecute(transactionGroup);

0 commit comments

Comments
 (0)