Skip to content

Commit

Permalink
Add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bradsawadye committed Oct 10, 2022
1 parent 15671f4 commit 89ca88a
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions test/unit/transactionsTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
/* eslint-env mocha */

import * as transactions from '../../src/api/transactions'
import {TaskModel, TransactionModel} from '../../src/model'
import {ObjectId} from 'mongodb'

describe('calculateTransactionBodiesByteLength()', () => {
it('should calculate the bodies length of a transaction', async () => {
Expand Down Expand Up @@ -47,3 +49,43 @@ describe('calculateTransactionBodiesByteLength()', () => {
lengthObj.length.should.be.exactly(0)
})
})

describe('*createRerunTasks', () => {
const transaction = Object.freeze({
status: 'Failed',
request: {
timestamp: new Date().toISOString()
},
updatedBy: {
id: new ObjectId(),
name: 'Test'
}
})
const userEmail = '[email protected]'

beforeEach(async () => {
await TransactionModel.deleteMany({})
await TaskModel.deleteMany({})
})

afterEach(async () => {
await TransactionModel.deleteMany({})
await TaskModel.deleteMany({})
})

it('should create rerun task', async () => {
await TransactionModel(transaction).save()
await transactions.createRerunTasks({}, 1, userEmail, 0, 0, 'Paused', 1)
const tasks = await TaskModel.find()
tasks.length.should.be.exactly(1)
})

it('should create multiple rerun tasks', async () => {
await TransactionModel(transaction).save()
await TransactionModel(transaction).save()

await transactions.createRerunTasks({}, 1, userEmail, 0, 1, '', 1)
const tasks = await TaskModel.find()
tasks.length.should.be.exactly(2)
})
})

0 comments on commit 89ca88a

Please sign in to comment.