mirror of
https://github.com/Permissionless-Software-Foundation/x402-base-facilitator.git
synced 2026-09-21 16:52:01 -07:00
78 lines
2.1 KiB
JavaScript
78 lines
2.1 KiB
JavaScript
/*
|
|
Unit tests for the src/use-cases/settle.js business logic library.
|
|
|
|
*/
|
|
|
|
// Public npm libraries
|
|
import { assert } from 'chai'
|
|
import sinon from 'sinon'
|
|
|
|
import SettleUseCases from '../../../src/use-cases/settle.js'
|
|
|
|
import adapters from '../mocks/adapters/index.js'
|
|
describe('#settle-use-case', () => {
|
|
let uut
|
|
let sandbox
|
|
|
|
before(async () => {
|
|
|
|
})
|
|
|
|
beforeEach(() => {
|
|
sandbox = sinon.createSandbox()
|
|
|
|
uut = new SettleUseCases({ 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 SettleUseCases()
|
|
|
|
assert.fail('Unexpected code path')
|
|
} catch (err) {
|
|
assert.include(
|
|
err.message,
|
|
'Instance of adapters must be passed in when instantiating Settle Use Cases library.'
|
|
)
|
|
}
|
|
})
|
|
})
|
|
|
|
describe('#settle', () => {
|
|
it('should return the supported payment kinds and extensions', async () => {
|
|
const result = await uut.settle({ paymentPayload: {}, paymentRequirements: {} })
|
|
|
|
assert.isObject(result)
|
|
})
|
|
it('should throw an error if paymentPayload are not provided', async () => {
|
|
try {
|
|
await uut.settle({})
|
|
assert.fail('Unexpected code path')
|
|
} catch (error) {
|
|
assert.include(error.message, 'Missing paymentPayload or paymentRequirements')
|
|
}
|
|
})
|
|
it('should throw an error if paymentRequirements are not provided', async () => {
|
|
try {
|
|
await uut.settle({ paymentPayload: {} })
|
|
assert.fail('Unexpected code path')
|
|
} catch (error) {
|
|
assert.include(error.message, 'Missing paymentPayload or paymentRequirements')
|
|
}
|
|
})
|
|
it('should handle facilitator errors', async () => {
|
|
try {
|
|
sandbox.stub(uut.facilitator, 'settle').throws(new Error('test error'))
|
|
await uut.settle({ paymentPayload: {}, paymentRequirements: {} })
|
|
assert.fail('Unexpected code path')
|
|
} catch (error) {
|
|
assert.include(error.message, 'test error')
|
|
}
|
|
})
|
|
})
|
|
})
|