Files
x402-base-facilitator/test/unit/use-cases/supported.js
T

62 lines
1.5 KiB
JavaScript
Raw Normal View History

/*
Unit tests for the src/use-cases/supported.js business logic library.
*/
// Public npm libraries
import { assert } from 'chai'
import sinon from 'sinon'
import SupportedUseCases from '../../../src/use-cases/supported.js'
import adapters from '../mocks/adapters/index.js'
describe('#supported-use-case', () => {
let uut
let sandbox
before(async () => {
})
beforeEach(() => {
sandbox = sinon.createSandbox()
uut = new SupportedUseCases({ adapters })
console.log('SupportedLib adapters: ', adapters.facilitatorMock)
})
afterEach(() => sandbox.restore())
describe('#constructor', () => {
it('should throw an error if adapters are not passed in', () => {
try {
uut = new SupportedUseCases()
assert.fail('Unexpected code path')
} catch (err) {
assert.include(
err.message,
'Instance of adapters must be passed in when instantiating Supported Use Cases library.'
)
}
})
})
describe('#supported', () => {
it('should return the supported payment kinds and extensions', async () => {
const result = await uut.supported()
assert.isObject(result)
})
it('should handle errors', async () => {
try {
sandbox.stub(uut.facilitator, 'getSupported').throws(new Error('test error'))
await uut.supported()
assert.fail('Unexpected code path')
} catch (error) {
assert.include(error.message, 'test error')
}
})
})
})