1 | import Hashids from '../lib/hashids'
|
2 |
|
3 | const hashids = new Hashids()
|
4 |
|
5 | describe.each([
|
6 | ['wpVL4j9g', 'deadbeef'],
|
7 | ['kmP69lB3xv', 'abcdef123456'],
|
8 | ['47JWg0kv4VU0G2KBO2', 'ABCDDD6666DDEEEEEEEEE'],
|
9 | ['y42LW46J9luq3Xq9XMly', '507f1f77bcf86cd799439011'],
|
10 | ['m1rO8xBQNquXmLvmO65BUO9KQmj', 'f00000fddddddeeeee4444444ababab'],
|
11 | ['wBlnMA23NLIQDgw7XxErc2mlNyAjpw', 'abcdef123456abcdef123456abcdef123456'],
|
12 | [
|
13 | 'VwLAoD9BqlT7xn4ZnBXJFmGZ51ZqrBhqrymEyvYLIP199',
|
14 | 'f000000000000000000000000000000000000000000000000000f',
|
15 | ],
|
16 | [
|
17 | 'nBrz1rYyV0C0XKNXxB54fWN0yNvVjlip7127Jo3ri0Pqw',
|
18 | 'fffffffffffffffffffffffffffffffffffffffffffffffffffff',
|
19 | ],
|
20 | ])('encodeHex/decodeHex using default params', (id, hex) => {
|
21 | test(`should encode '0x${hex.toUpperCase()}' to '${id}'`, () => {
|
22 | expect(hashids.encodeHex(hex)).toBe(id)
|
23 | })
|
24 |
|
25 | test(`should encode '0x${hex.toUpperCase()}' to '${id}' and decode back correctly`, () => {
|
26 | const encodedId = hashids.encodeHex(hex)
|
27 | const decodedHex = hashids.decodeHex(encodedId)
|
28 |
|
29 | expect(decodedHex).toBe(hex.toLowerCase())
|
30 | })
|
31 | })
|