1 | import Hashids from '../lib/hashids'
|
2 |
|
3 | describe('custom salt', () => {
|
4 | const testSalt = (salt: string) => {
|
5 | const hashids = new Hashids(salt)
|
6 | const numbers = [
|
7 | 1,
|
8 | 2,
|
9 | 3,
|
10 |
|
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 | })
|