mirror of
https://github.com/Permissionless-Software-Foundation/ipfs-bch-wallet-consumer.git
synced 2026-09-21 16:52:03 -07:00
73 lines
1.7 KiB
JavaScript
73 lines
1.7 KiB
JavaScript
/*
|
|||
|
|
Unit tests for the timer-controller.js Controller library
|
||
|
|
*/
|
||
|
|
|
||
|
|
// Public npm libraries
|
||
|
|
import { assert } from 'chai'
|
||
|
|
import sinon from 'sinon'
|
||
|
|
|
||
|
|
// Local libraries
|
||
|
|
import TimerControllers from '../../../src/controllers/timer-controllers.js'
|
||
|
|
import adapters from '../mocks/adapters/index.js'
|
||
|
|
import UseCasesMock from '../mocks/use-cases/index.js'
|
||
|
|
|
||
|
|
describe('#Timer-Controllers', () => {
|
||
|
|
let uut
|
||
|
|
let sandbox
|
||
|
|
|
||
|
|
beforeEach(() => {
|
||
|
|
sandbox = sinon.createSandbox()
|
||
|
|
|
||
|
|
const useCases = new UseCasesMock()
|
||
|
|
uut = new TimerControllers({ adapters, useCases })
|
||
|
|
})
|
||
|
|
|
||
|
|
afterEach(() => {
|
||
|
|
sandbox.restore()
|
||
|
|
|
||
|
|
uut.stopTimers()
|
||
|
|
})
|
||
|
|
|
||
|
|
describe('#constructor', () => {
|
||
|
|
it('should throw an error if adapters are not passed in', () => {
|
||
|
|
try {
|
||
|
|
uut = new TimerControllers()
|
||
|
|
|
||
|
|
assert.fail('Unexpected code path')
|
||
|
|
} catch (err) {
|
||
|
|
assert.include(
|
||
|
|
err.message,
|
||
|
|
'Instance of Adapters library required when instantiating Timer Controller libraries.'
|
||
|
|
)
|
||
|
|
}
|
||
|
|
})
|
||
|
|
|
||
|
|
it('should throw an error if useCases are not passed in', () => {
|
||
|
|
try {
|
||
|
|
uut = new TimerControllers({ adapters })
|
||
|
|
|
||
|
|
assert.fail('Unexpected code path')
|
||
|
|
} catch (err) {
|
||
|
|
assert.include(
|
||
|
|
err.message,
|
||
|
|
'Instance of Use Cases library required when instantiating Timer Controller libraries.'
|
||
|
|
)
|
||
|
|
}
|
||
|
|
})
|
||
|
|
})
|
||
|
|
|
||
|
|
describe('#exampleTimerFunc', () => {
|
||
|
|
it('should kick off the Use Case', async () => {
|
||
|
|
const result = await uut.exampleTimerFunc()
|
||
|
|
|
||
|
|
assert.equal(result, true)
|
||
|
|
})
|
||
|
|
|
||
|
|
it('should return false on error', async () => {
|
||
|
|
const result = await uut.exampleTimerFunc(true)
|
||
|
|
|
||
|
|
assert.equal(result, false)
|
||
|
|
})
|
||
|
|
})
|
||
|
|
})
|