Files
psf-bch-api-base/test/unit/lib/x402/facilitator-client-factory-unit.js
T

40 lines
1.5 KiB
JavaScript
Raw Normal View History

import { assert } from 'chai'
import { createFacilitatorClient } from '../../../../src/lib/x402/facilitator-client-factory.js'
import { RoundRobinFacilitatorClient } from '../../../../src/lib/x402/round-robin-facilitator-client.js'
class FakeFacilitatorClient {
constructor (opts) {
this.opts = opts
}
}
describe('#facilitator-client-factory', () => {
it('returns single strategy when only one facilitator is configured', () => {
const connectionOpts = [
{ key: 'cdp', name: 'Coinbase CDP', url: 'https://cdp.example.com', requiresAuth: true }
]
const result = createFacilitatorClient(connectionOpts, async () => ({}), FakeFacilitatorClient)
assert.equal(result.strategy, 'single')
2026-04-22 08:08:51 -07:00
assert.isFunction(result.client.verify)
assert.isFunction(result.client.settle)
assert.isFunction(result.client.getSupported)
})
it('returns round-robin strategy when multiple facilitators are configured', () => {
const connectionOpts = [
{ key: 'cdp', name: 'Coinbase CDP', url: 'https://cdp.example.com', requiresAuth: true },
{ key: 'dexter', name: 'Dexter', url: 'https://dexter.example.com', requiresAuth: false }
]
const result = createFacilitatorClient(connectionOpts, async () => ({}), FakeFacilitatorClient)
assert.equal(result.strategy, 'round-robin-failover')
assert.instanceOf(result.client, RoundRobinFacilitatorClient)
assert.lengthOf(result.client.entries, 2)
assert.equal(result.client.entries[0].key, 'cdp')
assert.equal(result.client.entries[1].key, 'dexter')
})
})