|
3 | 3 | /* eslint-env mocha */
|
4 | 4 |
|
5 | 5 | import * as transactions from '../../src/api/transactions'
|
| 6 | +import {TaskModel, TransactionModel} from '../../src/model' |
| 7 | +import {ObjectId} from 'mongodb' |
6 | 8 |
|
7 | 9 | describe('calculateTransactionBodiesByteLength()', () => {
|
8 | 10 | it('should calculate the bodies length of a transaction', async () => {
|
@@ -47,3 +49,43 @@ describe('calculateTransactionBodiesByteLength()', () => {
|
47 | 49 | lengthObj.length.should.be.exactly(0)
|
48 | 50 | })
|
49 | 51 | })
|
| 52 | + |
| 53 | +describe('*createRerunTasks', () => { |
| 54 | + const transaction = Object.freeze({ |
| 55 | + status: 'Failed', |
| 56 | + request: { |
| 57 | + timestamp: new Date().toISOString() |
| 58 | + }, |
| 59 | + updatedBy: { |
| 60 | + id: new ObjectId(), |
| 61 | + name: 'Test' |
| 62 | + } |
| 63 | + }) |
| 64 | + const userEmail = '[email protected]' |
| 65 | + |
| 66 | + beforeEach(async () => { |
| 67 | + await TransactionModel.deleteMany({}) |
| 68 | + await TaskModel.deleteMany({}) |
| 69 | + }) |
| 70 | + |
| 71 | + afterEach(async () => { |
| 72 | + await TransactionModel.deleteMany({}) |
| 73 | + await TaskModel.deleteMany({}) |
| 74 | + }) |
| 75 | + |
| 76 | + it('should create rerun task', async () => { |
| 77 | + await TransactionModel(transaction).save() |
| 78 | + await transactions.createRerunTasks({}, 1, userEmail, 0, 0, 'Paused', 1) |
| 79 | + const tasks = await TaskModel.find() |
| 80 | + tasks.length.should.be.exactly(1) |
| 81 | + }) |
| 82 | + |
| 83 | + it('should create multiple rerun tasks', async () => { |
| 84 | + await TransactionModel(transaction).save() |
| 85 | + await TransactionModel(transaction).save() |
| 86 | + |
| 87 | + await transactions.createRerunTasks({}, 1, userEmail, 0, 1, '', 1) |
| 88 | + const tasks = await TaskModel.find() |
| 89 | + tasks.length.should.be.exactly(2) |
| 90 | + }) |
| 91 | +}) |
0 commit comments