UNPKG

@unito/integration-sdk

Version:

Integration SDK

38 lines (37 loc) 1.4 kB
import assert from 'node:assert/strict'; import { describe, it } from 'node:test'; import extractCredentials from '../../src/middlewares/credentials.js'; import { BadRequestError } from '../../src/httpErrors.js'; describe('credentials middleware', () => { it('generates', async () => { const credentials = Buffer.from(JSON.stringify({ accessToken: 'abc', })).toString('base64'); const request = { header: (_key) => credentials }; const response = { locals: {} }; extractCredentials(request, response, () => { }); assert.deepEqual(response.locals, { credentials: { accessToken: 'abc', }, }); }); it('malformed header', async () => { const request = { header: (_key) => 'nope' }; const response = { locals: {} }; assert.throws(() => extractCredentials(request, response, () => { }), BadRequestError); }); it('variables', async () => { const credentials = Buffer.from(JSON.stringify({ apiKey: 'abc', })).toString('base64'); const request = { header: (_key) => credentials }; const response = { locals: {} }; extractCredentials(request, response, () => { }); assert.deepEqual(response.locals, { credentials: { apiKey: 'abc', }, }); }); });