httpHeaderAddActions.test.ts30 lines · main
1import { describe, expect, it } from 'vitest'
2
3import { buildEdgeFunctionHeaderAddActions } from './httpHeaderAddActions'
4
5describe('buildEdgeFunctionHeaderAddActions', () => {
6 it('includes the apikey header when requested', () => {
7 const [authAction] = buildEdgeFunctionHeaderAddActions({
8 apiKey: 'secret-key',
9 includeApiKeyHeader: true,
10 createRow: (name, value) => ({ name, value }),
11 })
12
13 expect(authAction.createRows()).toEqual([
14 { name: 'Authorization', value: 'Bearer secret-key' },
15 { name: 'apikey', value: 'secret-key' },
16 ])
17 })
18
19 it('omits the apikey header when not requested', () => {
20 const [authAction] = buildEdgeFunctionHeaderAddActions({
21 apiKey: 'service-key',
22 includeApiKeyHeader: false,
23 createRow: (name, value) => ({ name, value }),
24 })
25
26 expect(authAction.createRows()).toEqual([
27 { name: 'Authorization', value: 'Bearer service-key' },
28 ])
29 })
30})