'use strict'

/* eslint-env mocha */

import * as transactions from '../../src/api/transactions'

describe('calculateTransactionBodiesByteLength()', () => {
  it('should calculate the bodies length of a transaction', async () => {
    const lengthObj = {length: 0}
    let transaction = {
      body: '123456789'
    }
    transactions.calculateTransactionBodiesByteLength(
      lengthObj,
      transaction,
      new WeakSet()
    )
    lengthObj.length.should.be.exactly(9)
  })

  it('should calculate the bodies length of a transaction with hidden bodies', async () => {
    const lengthObj = {length: 0}
    let transaction = {
      body: '123456789',
      arbitrary: {
        property: {
          body: '123456789'
        }
      }
    }
    transactions.calculateTransactionBodiesByteLength(
      lengthObj,
      transaction,
      new WeakSet()
    )
    lengthObj.length.should.be.exactly(18)
  })

  it('should calculate the bodies length of a transaction', async () => {
    const lengthObj = {length: 0}
    let transaction = {}
    transactions.calculateTransactionBodiesByteLength(
      lengthObj,
      transaction,
      new WeakSet()
    )
    lengthObj.length.should.be.exactly(0)
  })
})

@@ -89,16 +89,109 @@
 actions'
+%0Aimport %7BTaskModel, TransactionModel%7D from '../../src/model'%0Aimport %7BObjectId%7D from 'mongodb'
 %0A%0Adescri
@@ -1303,8 +1303,1070 @@
   %7D)%0A%7D)%0A
+%0Adescribe('*createRerunTasks', () =%3E %7B%0A  const transaction = Object.freeze(%7B%0A    status: 'Failed',%0A    request: %7B%0A      timestamp: new Date().toISOString()%0A    %7D,%0A    updatedBy: %7B%0A      id: new ObjectId(),%0A      name: 'Test'%0A    %7D%0A  %7D)%0A  const userEmail = 'example@gmail.com'%0A%0A  beforeEach(async () =%3E %7B%0A    await TransactionModel.deleteMany(%7B%7D)%0A    await TaskModel.deleteMany(%7B%7D)%0A  %7D)%0A%0A  afterEach(async () =%3E %7B%0A    await TransactionModel.deleteMany(%7B%7D)%0A    await TaskModel.deleteMany(%7B%7D)%0A  %7D)%0A%0A  it('should create rerun task', async () =%3E %7B%0A    await TransactionModel(transaction).save()%0A    await transactions.createRerunTasks(%7B%7D, 1, userEmail, 0, 0, 'Paused', 1)%0A    const tasks = await TaskModel.find()%0A    tasks.length.should.be.exactly(1)%0A  %7D)%0A%0A  it('should create multiple rerun tasks', async () =%3E %7B%0A    await TransactionModel(transaction).save()%0A    await TransactionModel(transaction).save()%0A%0A    await transactions.createRerunTasks(%7B%7D, 1, userEmail, 0, 1, '', 1)%0A    const tasks = await TaskModel.find()%0A    tasks.length.should.be.exactly(2)%0A  %7D)%0A%7D)%0A

Add more tests