Skip to content

Commit 390ce3c

Browse files
committed
test(auth): added tests for the new subscription id method
1 parent 826e195 commit 390ce3c

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

packages/core/auth-js/test/helpers.test.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,53 @@
11
import { AuthInvalidJwtError } from '../src'
22
import {
33
decodeJWT,
4+
generateCallbackId,
45
getAlgorithm,
56
parseParametersFromURL,
67
parseResponseAPIVersion,
78
getCodeChallengeAndMethod,
89
validateUUID,
910
} from '../src/lib/helpers'
1011

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+
1151
describe('parseParametersFromURL', () => {
1252
it('should parse parameters from a URL with query params only', () => {
1353
const url = new URL('https://supabase.com')

0 commit comments

Comments
 (0)