UNPKG

1.16 kBPlain TextView Raw
1import Hashids from '../lib/hashids'
2
3describe('custom salt', () => {
4 const testSalt = (salt: string) => {
5 const hashids = new Hashids(salt)
6 const numbers = [
7 1,
8 2,
9 3,
10 // bigint format:
11 ...(typeof BigInt === 'function'
12 ? require('./bigint-test-cases').customSaltNumbers
13 : []),
14 ]
15
16 const id = hashids.encode(numbers)
17 const decodedNumbers = hashids.decode(id)
18
19 expect(decodedNumbers).toEqual(numbers)
20 }
21
22 test(`should work with ''`, () => {
23 testSalt('')
24 })
25
26 test(`should work with ' '`, () => {
27 testSalt(' ')
28 })
29
30 test(`should work with 'this is my salt'`, () => {
31 testSalt('this is my salt')
32 })
33
34 test(`should work with a really long salt`, () => {
35 testSalt(
36 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890`~!@#$%^&*()-_=+\\|\'";:/?.>,<{[}]',
37 )
38 })
39
40 test(`should work with a weird salt`, () => {
41 testSalt('`~!@#$%^&*()-_=+\\|\'";:/?.>,<{[}]')
42 })
43
44 test(`should work with an ultra weird salt`, () => {
45 testSalt('πŸ€ΊπŸ‘©πŸΏβ€πŸ¦³πŸ›πŸ‘©πŸ»πŸ¦·πŸ€¦β€β™‚οΈπŸβ˜πŸΌβœπŸΎπŸ‘‰πŸ½πŸ‡ΈπŸ‡°β€οΈπŸ­')
46 })
47})