custom-salt.js
818 字节
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import Hashids from '../lib/hashids';
import { assert } from 'chai';
describe('custom salt', () => {
const testSalt = (salt) => {
const hashids = new Hashids(salt);
const numbers = [1, 2, 3];
const id = hashids.encode(numbers);
const decodedNumbers = hashids.decode(id);
assert.deepEqual(decodedNumbers, numbers);
};
it(`should work with ''`, () => {
testSalt('');
});
it(`should work with ' '`, () => {
testSalt(' ');
});
it(`should work with 'this is my salt'`, () => {
testSalt('this is my salt');
});
it(`should work with a really long salt`, () => {
testSalt('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890`~!@#$%^&*()-_=+\\|\'";:/?.>,<{[}]');
});
it(`should work with a weird salt`, () => {
testSalt('`~!@#$%^&*()-_=+\\|\'";:/?.>,<{[}]');
});
});