-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
44 lines (34 loc) · 1.39 KB
/
test.js
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
var convertId = require("./index");
var expect = require("expect.js");
var data = [
{hex: "521fc843178a921652000007", base64: 'Uh-IQxeKkhZSAAAH'},
{hex: "521fc843178a921652000060", base64: 'Uh-IQxeKkhZSAABg'},
{hex: "52336be5b74a7a0000000015", base64: 'UjNr5bdKegAAAAAV'},
{hex: "53c5d28ca62be0a940000002", base64: 'U8XSjKYr4KlAAAAC'},
{hex: "521fc86d178a92165200001d", base64: 'Uh-IbReKkhZSAAAd'},
{hex: "52af5b7913d8e99f41136d4c", base64: 'Uq9beRPY6Z9BE21M'},
{hex: "5397b40c7232ef916a000967", base64: 'U5e0DHIy75FqAAln'},
{hex: "000000000000000000000000", base64: 'AAAAAAAAAAAAAAAA'},
{hex: "000000000000000000000003", base64: 'AAAAAAAAAAAAAAAD'},
{hex: "ffffffffffffffffffffffff", base64: '----------------'},
];
describe("base64-mongo-id", function() {
it("throws on bad input for hex to base64", function() {
expect(function() {
convertId.toBase64(data[0].base64);
}).to.throwError();
});
it("throws on bad input for base64 to hex", function() {
expect(function() {
convertId.toHex(data[0].hex);
}).to.throwError();
});
data.forEach(function(pair, i) {
it("converts hex to base64 properly - test " + (i + 1), function() {
expect(convertId.toBase64(pair.hex)).to.be(pair.base64);
});
it("converts base64 to hex properly - test " + (i + 1), function() {
expect(convertId.toHex(pair.base64)).to.be(pair.hex);
});
});
});