1
0

add basic helper function

This commit is contained in:
2025-07-24 21:56:26 +02:00
parent 2e594d09f5
commit a08adf3c03
2 changed files with 17 additions and 0 deletions

View File

@@ -261,6 +261,21 @@ describe('Router', () => {
expect(await response.text()).toBe(testToken)
})
test('basic', async () => {
const router = new Router()
const testCredentials = ['user', 'password']
const testBasicAuth = btoa(testCredentials.join(':'))
const testRequest = new Request('https://example.com/', { headers: { 'Authorization': `Basic ${testBasicAuth}` }})
router.get('/', ({ req }) => Response.json(req.basic()))
const response = await router.handle(testRequest, {})
expect(response.status).toEqual(200)
expect(await response.json()).toMatchObject(testCredentials)
})
})
describe('Middleware', () => {