1 | import Hashids from '../lib/hashids'
|
2 |
|
3 | const hashids = new Hashids()
|
4 |
|
5 | describe.each([
|
6 | ['gY', [0]],
|
7 | ['jR', [1]],
|
8 | ['R8ZN0', [928728]],
|
9 | ['o2fXhV', [1, 2, 3]],
|
10 | ['jRfMcP', [1, 0, 0]],
|
11 | ['jQcMcW', [0, 0, 1]],
|
12 | ['gYcxcr', [0, 0, 0]],
|
13 | ['gLpmopgO6', [1000000000000]],
|
14 | ['lEW77X7g527', [9007199254740991]],
|
15 | ['BrtltWt2tyt1tvt7tJt2t1tD', [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]],
|
16 | ['G6XOnGQgIpcVcXcqZ4B8Q8B9y', [10000000000, 0, 0, 0, 999999999999999]],
|
17 | [
|
18 | '5KoLLVL49RLhYkppOplM6piwWNNANny8N',
|
19 | [9007199254740991, 9007199254740991, 9007199254740991],
|
20 | ],
|
21 | [
|
22 | 'BPg3Qx5f8VrvQkS16wpmwIgj9Q4Jsr93gqx',
|
23 | [1000000001, 1000000002, 1000000003, 1000000004, 1000000005],
|
24 | ],
|
25 | [
|
26 | '1wfphpilsMtNumCRFRHXIDSqT2UPcWf1hZi3s7tN',
|
27 | [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],
|
28 | ],
|
29 |
|
30 | ...(typeof BigInt === 'function'
|
31 | ? require('./bigint-test-cases').defaultParams
|
32 | : []),
|
33 | ] as [string, (number | bigint)[]][])(
|
34 | 'encode/decode using default params',
|
35 | (id, numbers) => {
|
36 | test(`should encode [${numbers}] to '${id}' (passing array of numbers)`, () => {
|
37 | expect(id).toEqual(hashids.encode(numbers))
|
38 | })
|
39 |
|
40 | test(`should encode [${numbers}] to '${id}' (passing numbers)`, () => {
|
41 | expect(id).toEqual(hashids.encode(...numbers))
|
42 | })
|
43 |
|
44 | test(`should encode [${numbers}] to '${id}' and decode back correctly`, () => {
|
45 | const encodedId = hashids.encode(numbers)
|
46 | const decodedNumbers = hashids.decode(encodedId)
|
47 |
|
48 | expect(numbers).toEqual(decodedNumbers)
|
49 | })
|
50 | },
|
51 | )
|