bad-input.js
2.4 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import Hashids from '../lib/hashids';
import { assert } from 'chai';
const hashids = new Hashids();
describe('bad input', () => {
it(`should throw an error when small alphabet`, () => {
assert.throws(() => {
const hashidsIgnored = new Hashids('', 0, '1234567890');
});
});
it(`should throw an error when alphabet has spaces`, () => {
assert.throws(() => {
const hashidsIgnored = new Hashids('', 0, 'a cdefghijklmnopqrstuvwxyz');
});
});
it(`should return an empty string when encoding nothing`, () => {
const id = hashids.encode();
assert.equal(id, '');
});
it(`should return an empty string when encoding an empty array`, () => {
const id = hashids.encode([]);
assert.equal(id, '');
});
it(`should return an empty string when encoding a negative number`, () => {
const id = hashids.encode(-1);
assert.equal(id, '');
});
it(`should return an empty string when encoding a string with non-numeric characters`, () => {
assert.equal(hashids.encode('6B'), '');
assert.equal(hashids.encode('123a'), '');
});
it(`should return an empty string when encoding infinity`, () => {
const id = hashids.encode(Infinity);
assert.equal(id, '');
});
it(`should return an empty string when encoding a null`, () => {
const id = hashids.encode(null);
assert.equal(id, '');
});
it(`should return an empty string when encoding a NaN`, () => {
const id = hashids.encode(NaN);
assert.equal(id, '');
});
it(`should return an empty string when encoding an undefined`, () => {
const id = hashids.encode(undefined);
assert.equal(id, '');
});
it(`should return an empty string when encoding an array with non-numeric input`, () => {
const id = hashids.encode(['z']);
assert.equal(id, '');
});
it(`should return an empty array when decoding nothing`, () => {
const numbers = hashids.decode();
assert.deepEqual(numbers, []);
});
it(`should return an empty string when encoding non-numeric input`, () => {
const id = hashids.encode('z');
assert.equal(id, '');
});
it(`should return an empty array when decoding invalid id`, () => {
const numbers = hashids.decode('f');
assert.deepEqual(numbers, []);
});
it(`should return an empty string when encoding non-hex input`, () => {
const id = hashids.encodeHex('z');
assert.equal(id, '');
});
it(`should return an empty array when hex-decoding invalid id`, () => {
const numbers = hashids.decodeHex('f');
assert.deepEqual(numbers, []);
});
});