Files
bch-dex/test/unit/adapters/p2wdb.adapter.unit.js
T
2022-02-23 05:51:12 -08:00

53 lines
1.2 KiB
JavaScript

/*
Unit tests for the p2wdb adapter library.
*/
// Public npm libraries.
const assert = require('chai').assert
const sinon = require('sinon')
// Local libraries.
const P2wdbAdapter = require('../../../src/adapters/p2wdb')
describe('#P2wdbAdapter', () => {
let uut, sandbox
beforeEach(() => {
uut = new P2wdbAdapter()
sandbox = sinon.createSandbox()
})
afterEach(() => sandbox.restore())
describe('#write', () => {
it('should write an offer to the P2WDB', async () => {
const inputObj = {
txid: 'testTxid',
signature: 'testSignature',
message: 'testMessage',
appId: 'testAppId',
data: { key: 'value' }
}
// Mock axios to prevent live network call
sandbox.stub(uut.axios, 'post').resolves({ data: { hash: 'testhash' } })
const result = await uut.write(inputObj)
// console.log('result: ', result)
assert.equal(result, 'testhash')
})
it('should catch and throw errors', async () => {
try {
await uut.write()
assert.fail('Unexpected code path')
} catch (err) {
// console.log(err)
assert.include(err.message, 'Cannot destructure property')
}
})
})
})