2022-06-20 07:19:36 -07:00
|
|
|
/*
|
|
|
|
|
Unit tests for the adapters index.js library
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
// Global npm libraries
|
2022-09-08 08:58:39 -07:00
|
|
|
import { assert } from 'chai'
|
|
|
|
|
|
|
|
|
|
import sinon from 'sinon'
|
2022-06-20 07:19:36 -07:00
|
|
|
|
|
|
|
|
// Local libraries
|
2022-09-08 08:58:39 -07:00
|
|
|
import Adapters from '../../../src/adapters/index.js'
|
2022-06-20 07:19:36 -07:00
|
|
|
|
|
|
|
|
describe('#adapters', () => {
|
|
|
|
|
let uut, sandbox
|
|
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
|
sandbox = sinon.createSandbox()
|
2026-02-02 18:54:18 -07:00
|
|
|
uut = new Adapters()
|
2022-06-20 07:19:36 -07:00
|
|
|
})
|
|
|
|
|
|
|
|
|
|
afterEach(() => {
|
2026-02-02 18:54:18 -07:00
|
|
|
if (sandbox) {
|
|
|
|
|
sandbox.restore()
|
|
|
|
|
}
|
2022-06-20 07:19:36 -07:00
|
|
|
})
|
|
|
|
|
|
|
|
|
|
describe('#start', () => {
|
|
|
|
|
it('should start the async adapters', async () => {
|
|
|
|
|
// Mock dependencies
|
|
|
|
|
uut.config.getJwtAtStartup = true
|
2023-04-10 09:19:51 -07:00
|
|
|
uut.config.useIpfs = true
|
|
|
|
|
uut.config.env = 'not-a-test'
|
2022-06-20 07:19:36 -07:00
|
|
|
sandbox.stub(uut.fullStackJwt, 'getJWT').resolves()
|
|
|
|
|
sandbox.stub(uut.fullStackJwt, 'instanceBchjs').resolves()
|
|
|
|
|
sandbox.stub(uut.ipfs, 'start').resolves()
|
|
|
|
|
|
|
|
|
|
const result = await uut.start()
|
|
|
|
|
|
|
|
|
|
assert.equal(result, true)
|
|
|
|
|
})
|
2025-06-27 20:11:27 -04:00
|
|
|
it('should not start ipfs on test enviroment', async () => {
|
|
|
|
|
// Mock dependencies
|
|
|
|
|
uut.config.getJwtAtStartup = true
|
|
|
|
|
uut.config.useIpfs = true
|
|
|
|
|
uut.config.env = 'test'
|
|
|
|
|
|
|
|
|
|
sandbox.stub(uut.fullStackJwt, 'getJWT').resolves()
|
|
|
|
|
sandbox.stub(uut.fullStackJwt, 'instanceBchjs').resolves()
|
|
|
|
|
const ipfsSpy = sandbox.stub(uut.ipfs, 'start').resolves(null)
|
|
|
|
|
|
|
|
|
|
const result = await uut.start()
|
|
|
|
|
|
|
|
|
|
assert.isTrue(ipfsSpy.notCalled)
|
|
|
|
|
assert.equal(result, true)
|
|
|
|
|
})
|
2022-06-20 07:19:36 -07:00
|
|
|
|
|
|
|
|
it('should catch and throw an error', async () => {
|
|
|
|
|
try {
|
2022-06-27 10:09:08 -07:00
|
|
|
// Force an error
|
2022-06-20 07:19:36 -07:00
|
|
|
uut.config.getJwtAtStartup = false
|
2022-06-27 10:09:08 -07:00
|
|
|
uut.config.env = 'dev'
|
2022-06-20 07:19:36 -07:00
|
|
|
sandbox.stub(uut.ipfs, 'start').rejects(new Error('test error'))
|
|
|
|
|
|
|
|
|
|
await uut.start()
|
|
|
|
|
|
|
|
|
|
assert.fail('Unexpected result')
|
|
|
|
|
} catch (err) {
|
|
|
|
|
// console.log('err: ', err)
|
|
|
|
|
assert.include(err.message, 'test error')
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
})
|