default-params.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import Hashids from '../lib/hashids';
  2. import { assert } from 'chai';
  3. const hashids = new Hashids();
  4. const map = {
  5. 'gY': [0],
  6. 'jR': [1],
  7. 'R8ZN0': [928728],
  8. 'o2fXhV': [1, 2, 3],
  9. 'jRfMcP': [1, 0, 0],
  10. 'jQcMcW': [0, 0, 1],
  11. 'gYcxcr': [0, 0, 0],
  12. 'gLpmopgO6': [1000000000000],
  13. 'lEW77X7g527': [9007199254740991],
  14. 'BrtltWt2tyt1tvt7tJt2t1tD': [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5],
  15. 'G6XOnGQgIpcVcXcqZ4B8Q8B9y': [10000000000, 0, 0, 0, 999999999999999],
  16. '5KoLLVL49RLhYkppOplM6piwWNNANny8N': [9007199254740991, 9007199254740991, 9007199254740991],
  17. 'BPg3Qx5f8VrvQkS16wpmwIgj9Q4Jsr93gqx': [1000000001, 1000000002, 1000000003, 1000000004, 1000000005],
  18. '1wfphpilsMtNumCRFRHXIDSqT2UPcWf1hZi3s7tN': [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]
  19. };
  20. describe('encode/decode using default params', () => {
  21. for (const id in map) {
  22. const numbers = map[id];
  23. it(`should encode [${numbers}] to '${id}' (passing array of numbers)`, () => {
  24. assert.equal(id, hashids.encode(numbers));
  25. });
  26. it(`should encode [${numbers}] to '${id}' (passing numbers)`, () => {
  27. assert.equal(id, hashids.encode.apply(hashids, numbers));
  28. });
  29. it(`should encode [${numbers}] to '${id}' and decode back correctly`, () => {
  30. const encodedId = hashids.encode(numbers);
  31. const decodedNumbers = hashids.decode(encodedId);
  32. assert.deepEqual(numbers, decodedNumbers);
  33. });
  34. }
  35. });