2016-08-16 01:37:40 +00:00
|
|
|
"use strict";
|
|
|
|
require("typings-test");
|
|
|
|
const should = require("should");
|
|
|
|
const fs = require("fs");
|
|
|
|
const nodehash = require("../dist/index");
|
|
|
|
describe("nodehash", function () {
|
|
|
|
describe("sha256FromStringSync", function () {
|
|
|
|
it("should convert a String to sha256 hash synchronously", function () {
|
|
|
|
let testHash = nodehash.sha256FromStringSync("test");
|
|
|
|
let testHash2 = nodehash.sha256FromStringSync("testString");
|
|
|
|
let testHash3 = nodehash.sha256FromStringSync("test");
|
|
|
|
should.equal(testHash, testHash3);
|
|
|
|
should.notEqual(testHash, "test");
|
|
|
|
});
|
|
|
|
});
|
|
|
|
describe("sha256fromStringSync", function () {
|
|
|
|
it("should convert a String to sha256 hash synchronously", function (done) {
|
|
|
|
nodehash.sha256FromString("test")
|
|
|
|
.then(resultString => {
|
|
|
|
let compareString = nodehash.sha256FromStringSync("test");
|
|
|
|
should.equal(resultString, compareString);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
describe("sha256fromStream", function () {
|
|
|
|
it("should convert a Stream to sha256 and resolve a promise with result", function (done) {
|
|
|
|
let readStream = fs.createReadStream("./test/testImageForHash.jpg");
|
|
|
|
nodehash.sha256FromStream(readStream)
|
|
|
|
.then((resultString) => {
|
|
|
|
should.equal(resultString, "45b80413ed93acb495691186ce61850449439f9183352b9bff96d5533fa1046c");
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
describe("sha256fromFile", function () {
|
|
|
|
it("should convert a Stream to sha256 and resolve a promise with result", function (done) {
|
|
|
|
nodehash.sha256FromFile("./test/testImageForHash.jpg")
|
|
|
|
.then((resultString) => {
|
|
|
|
should.equal(resultString, "45b80413ed93acb495691186ce61850449439f9183352b9bff96d5533fa1046c");
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
//# sourceMappingURL=data:application/json;base64,ey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