|
| 1 | +import type { Auth } from '@hey-api/client-core'; |
1 | 2 | import { describe, expect, it, vi } from 'vitest';
|
2 | 3 |
|
3 |
| -import type { Auth } from '../types'; |
4 |
| -import { |
5 |
| - axiosHeadersKeywords, |
6 |
| - getAuthToken, |
7 |
| - mergeHeaders, |
8 |
| - setAuthParams, |
9 |
| -} from '../utils'; |
10 |
| - |
11 |
| -describe('getAuthToken', () => { |
12 |
| - it('returns bearer token', async () => { |
13 |
| - const auth = vi.fn().mockReturnValue('foo'); |
14 |
| - const token = await getAuthToken( |
15 |
| - { |
16 |
| - scheme: 'bearer', |
17 |
| - type: 'http', |
18 |
| - }, |
19 |
| - auth, |
20 |
| - ); |
21 |
| - expect(auth).toHaveBeenCalled(); |
22 |
| - expect(token).toBe('Bearer foo'); |
23 |
| - }); |
24 |
| - |
25 |
| - it('returns basic token', async () => { |
26 |
| - const auth = vi.fn().mockReturnValue('foo:bar'); |
27 |
| - const token = await getAuthToken( |
28 |
| - { |
29 |
| - scheme: 'basic', |
30 |
| - type: 'http', |
31 |
| - }, |
32 |
| - auth, |
33 |
| - ); |
34 |
| - expect(auth).toHaveBeenCalled(); |
35 |
| - expect(token).toBe(`Basic ${btoa('foo:bar')}`); |
36 |
| - }); |
37 |
| - |
38 |
| - it('returns raw token', async () => { |
39 |
| - const auth = vi.fn().mockReturnValue('foo'); |
40 |
| - const token = await getAuthToken( |
41 |
| - { |
42 |
| - type: 'http', |
43 |
| - }, |
44 |
| - auth, |
45 |
| - ); |
46 |
| - expect(auth).toHaveBeenCalled(); |
47 |
| - expect(token).toBe('foo'); |
48 |
| - }); |
49 |
| - |
50 |
| - it('returns nothing when auth function is undefined', async () => { |
51 |
| - const token = await getAuthToken( |
52 |
| - { |
53 |
| - type: 'http', |
54 |
| - }, |
55 |
| - undefined, |
56 |
| - ); |
57 |
| - expect(token).toBeUndefined(); |
58 |
| - }); |
59 |
| -}); |
| 4 | +import { axiosHeadersKeywords, mergeHeaders, setAuthParams } from '../utils'; |
60 | 5 |
|
61 | 6 | describe('mergeHeaders', () => {
|
62 | 7 | it.each(axiosHeadersKeywords)(
|
|
0 commit comments