httpHeaderAddActions.test.ts 952 B

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