mirror of
https://github.com/Permissionless-Software-Foundation/x402-base-facilitator.git
synced 2026-09-21 16:52:01 -07:00
feat(x402): Implemented x402 Base facilitator
This commit is contained in:
@@ -0,0 +1,77 @@
|
||||
/*
|
||||
Unit tests for the src/use-cases/verify.js business logic library.
|
||||
|
||||
*/
|
||||
|
||||
// Public npm libraries
|
||||
import { assert } from 'chai'
|
||||
import sinon from 'sinon'
|
||||
|
||||
import VerifyUseCases from '../../../src/use-cases/verify.js'
|
||||
|
||||
import adapters from '../mocks/adapters/index.js'
|
||||
describe('#verify-use-case', () => {
|
||||
let uut
|
||||
let sandbox
|
||||
|
||||
before(async () => {
|
||||
|
||||
})
|
||||
|
||||
beforeEach(() => {
|
||||
sandbox = sinon.createSandbox()
|
||||
|
||||
uut = new VerifyUseCases({ 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 VerifyUseCases()
|
||||
|
||||
assert.fail('Unexpected code path')
|
||||
} catch (err) {
|
||||
assert.include(
|
||||
err.message,
|
||||
'Instance of adapters must be passed in when instantiating Verify Use Cases library.'
|
||||
)
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
describe('#verify', () => {
|
||||
it('should return the supported payment kinds and extensions', async () => {
|
||||
const result = await uut.verify({ paymentPayload: {}, paymentRequirements: {} })
|
||||
|
||||
assert.isObject(result)
|
||||
})
|
||||
it('should throw an error if paymentPayload are not provided', async () => {
|
||||
try {
|
||||
await uut.verify({})
|
||||
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.verify({ 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, 'verify').throws(new Error('test error'))
|
||||
await uut.verify({ paymentPayload: {}, paymentRequirements: {} })
|
||||
assert.fail('Unexpected code path')
|
||||
} catch (error) {
|
||||
assert.include(error.message, 'test error')
|
||||
}
|
||||
})
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user