default-params-hex.js 1.1 KB

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