mirror of
https://github.com/Permissionless-Software-Foundation/x402-base-facilitator.git
synced 2026-09-21 16:52:01 -07:00
62 lines
1.5 KiB
JavaScript
62 lines
1.5 KiB
JavaScript
/*
|
|
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')
|
|
}
|
|
})
|
|
})
|
|
})
|