custom-salt.js 818 B

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