mirror of
https://github.com/Permissionless-Software-Foundation/x402-base-facilitator.git
synced 2026-09-21 16:52:01 -07:00
47 lines
1.1 KiB
JavaScript
47 lines
1.1 KiB
JavaScript
const assert = require('chai').assert
|
|
const PassportLib = require('../../src/lib/passport')
|
|
|
|
const sinon = require('sinon')
|
|
|
|
let uut
|
|
let sandbox
|
|
|
|
describe('#passport.js', () => {
|
|
beforeEach(() => {
|
|
uut = new PassportLib()
|
|
|
|
sandbox = sinon.createSandbox()
|
|
})
|
|
|
|
afterEach(() => sandbox.restore())
|
|
|
|
describe('authUser()', () => {
|
|
it('should throw error if ctx is not provided', async () => {
|
|
try {
|
|
await uut.authUser()
|
|
assert(false, 'Unexpected result')
|
|
} catch (err) {
|
|
assert.include(err.message, 'ctx is required')
|
|
}
|
|
})
|
|
|
|
it('Should throw error if the passport library fails', async () => {
|
|
try {
|
|
const error = new Error('cant auth user')
|
|
const user = null
|
|
|
|
// Mock calls
|
|
// https://sinonjs.org/releases/latest/stubs/
|
|
// About yields
|
|
sandbox.stub(uut.passport, 'authenticate').yields(error, user)
|
|
|
|
const ctx = {}
|
|
await uut.authUser(ctx)
|
|
assert(false, 'Unexpected result')
|
|
} catch (err) {
|
|
assert.include(err.message, 'cant auth user')
|
|
}
|
|
})
|
|
})
|
|
})
|