Skip to content

Commit 89ca88a

Browse files
committed
Add more tests
1 parent 15671f4 commit 89ca88a

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

test/unit/transactionsTest.js

+42
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
/* eslint-env mocha */
44

55
import * as transactions from '../../src/api/transactions'
6+
import {TaskModel, TransactionModel} from '../../src/model'
7+
import {ObjectId} from 'mongodb'
68

79
describe('calculateTransactionBodiesByteLength()', () => {
810
it('should calculate the bodies length of a transaction', async () => {
@@ -47,3 +49,43 @@ describe('calculateTransactionBodiesByteLength()', () => {
4749
lengthObj.length.should.be.exactly(0)
4850
})
4951
})
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

Comments
 (0)