|
1 | 1 | import { AuthInvalidJwtError } from '../src' |
2 | 2 | import { |
3 | 3 | decodeJWT, |
| 4 | + generateCallbackId, |
4 | 5 | getAlgorithm, |
5 | 6 | parseParametersFromURL, |
6 | 7 | parseResponseAPIVersion, |
7 | 8 | getCodeChallengeAndMethod, |
8 | 9 | validateUUID, |
9 | 10 | } from '../src/lib/helpers' |
10 | 11 |
|
| 12 | +describe('generateCallbackId', () => { |
| 13 | + it('should return a Symbol', () => { |
| 14 | + const id = generateCallbackId() |
| 15 | + expect(typeof id).toBe('symbol') |
| 16 | + }) |
| 17 | + |
| 18 | + it('should return unique Symbols on each call', () => { |
| 19 | + const id1 = generateCallbackId() |
| 20 | + const id2 = generateCallbackId() |
| 21 | + const id3 = generateCallbackId() |
| 22 | + |
| 23 | + expect(id1).not.toBe(id2) |
| 24 | + expect(id2).not.toBe(id3) |
| 25 | + expect(id1).not.toBe(id3) |
| 26 | + }) |
| 27 | + |
| 28 | + it('should work as Map keys', () => { |
| 29 | + const id1 = generateCallbackId() |
| 30 | + const id2 = generateCallbackId() |
| 31 | + |
| 32 | + const map = new Map() |
| 33 | + map.set(id1, 'callback1') |
| 34 | + map.set(id2, 'callback2') |
| 35 | + |
| 36 | + expect(map.get(id1)).toBe('callback1') |
| 37 | + expect(map.get(id2)).toBe('callback2') |
| 38 | + expect(map.size).toBe(2) |
| 39 | + |
| 40 | + map.delete(id1) |
| 41 | + expect(map.has(id1)).toBe(false) |
| 42 | + expect(map.has(id2)).toBe(true) |
| 43 | + }) |
| 44 | + |
| 45 | + it('should have a description for debugging', () => { |
| 46 | + const id = generateCallbackId() |
| 47 | + expect(id.toString()).toBe('Symbol(auth-callback)') |
| 48 | + }) |
| 49 | +}) |
| 50 | + |
11 | 51 | describe('parseParametersFromURL', () => { |
12 | 52 | it('should parse parameters from a URL with query params only', () => { |
13 | 53 | const url = new URL('https://supabase.com') |
|
0 commit comments