Skip to content

Commit

Permalink
Adding lib
Browse files Browse the repository at this point in the history
  • Loading branch information
robertoachar committed Jul 22, 2017
1 parent e15999b commit bf4698a
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 10 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"coveralls": "npm run coverage && cat ./coverage/lcov.info | coveralls",
"jest": "jest --colors --verbose",
"lint": "eslint src/**/*.js test/**/*.js",
"start": "nodemon src/index.js",
"start": "nodemon sample/sample.js",
"test": "npm run lint && npm run jest"
},
"repository": {
Expand Down
7 changes: 7 additions & 0 deletions sample/sample.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/* eslint no-console: 0 */

const lib = require('../src');

lib.createHash('Buffer')
.then((hash) => console.log(hash))
.catch((err) => console.error(err));
20 changes: 17 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
'use strict';
const crypto = require('crypto');

module.exports.hello = (done) => {
return done(null, 'It works!');
module.exports.createHash = (buffer) => {
return new Promise((resolve, reject) => {
if (!buffer) reject('Buffer not found');

const md5 = crypto.createHash('md5').update(buffer).digest('hex');
const sha1 = crypto.createHash('sha1').update(buffer).digest('hex');
const sha256 = crypto.createHash('sha256').update(buffer).digest('hex');

const hash = {
md5,
sha1,
sha256
};

resolve(hash);
});
};
30 changes: 24 additions & 6 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,31 @@ const lib = require('../src');

describe('TESTS', () => {

test('Basic test', (done) => {
lib.hello((err, message) => {
expect(err).toBeNull();
expect(message).toBe('It works!');
test('should return an error', (done) => {
lib.createHash('')
.catch((err) => {
expect(err).toBeDefined();
expect(err).toBe('Buffer not found');

done();
});
done();
});
});

test('should return a hash', (done) => {
lib.createHash('Buffer')
.then((hash) => {
expect(hash).toBeDefined();

expect(hash.md5).toBeDefined();
expect(hash.sha1).toBeDefined();
expect(hash.sha256).toBeDefined();

expect(hash.md5).toBe('7e62bc342f41c946868f0ea6f0b712d8');
expect(hash.sha1).toBe('2be5f64b36230104ef9c6e230215846a83d18df6');
expect(hash.sha256).toBe('e44193fd2d21722a46c8fcab041508d4c5be95a34828b72c631df53e8d7e20a6');

done();
});
});

});

0 comments on commit bf4698a

Please sign in to comment.