-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from ajimae/add-unit-test-#0001
#1 setup unit tests
- Loading branch information
Showing
11 changed files
with
158 additions
and
162 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{ | ||
"cache": false, | ||
"check-coverage": false, | ||
"extension": [ | ||
".ts" | ||
], | ||
"include": [ | ||
"**/*js", | ||
"**/*ts" | ||
], | ||
"exclude": [ | ||
"coverage/**", | ||
"node_modules/**", | ||
"**/*.d.ts", | ||
"**/*.test.ts" | ||
], | ||
"sourceMap": true, | ||
"reporter": [ | ||
"html", | ||
"text", | ||
"text-summary" | ||
], | ||
"all": true, | ||
"instrument": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
language: node_js | ||
node_js: | ||
- "node" | ||
cache: | ||
directories: | ||
- "node_modules" | ||
script: | ||
- npm test | ||
after_success: | ||
- npm run coverage | ||
- ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,5 @@ | ||
# ncrypt-js | ||
|
||
[![Build Status](https://travis-ci.com/ajimae/ncrypt-js.svg?branch=master)](https://travis-ci.com/ajimae/ncrypt-js) [![Coverage Status](https://coveralls.io/repos/github/ajimae/ncrypt-js/badge.svg)](https://coveralls.io/github/ajimae/ncrypt-js) | ||
|
||
A light weight plain text encoder and decoder |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
import * as chai from "chai"; | ||
|
||
import * as ncrypt from '../index'; | ||
|
||
const expect = chai.expect; | ||
const { encrypt, decrypt } = ncrypt; | ||
|
||
const object = { | ||
SimpleCrypto: "is great.", | ||
You: "should try it!" | ||
}; | ||
const string = "SimpleCrypto is great."; | ||
const number = 19960404; | ||
const boolean = false; | ||
|
||
const _secret = 'shhh its a secret'; | ||
const _nullSecret: any = null; | ||
|
||
const encryptString = encrypt(string, _secret); | ||
const encryptNumber = encrypt(number, _secret); | ||
const encryptObject = encrypt(object, _secret); | ||
const encryptBoolean = encrypt(boolean, _secret); | ||
|
||
const decryptString = decrypt(encryptString); | ||
const decryptNumber = decrypt(encryptNumber); | ||
const decryptObject = decrypt(encryptObject); | ||
const decryptBoolean = decrypt(encryptBoolean); | ||
|
||
describe('Encrytion', () => { | ||
it('should be able to encrypt a string', () => { | ||
expect(string).to.be.a('string'); | ||
expect(typeof encryptString).to.eql('string'); | ||
}); | ||
|
||
it('should be able to encrypt an object', () => { | ||
expect(object).to.be.a('object'); | ||
expect(typeof encryptObject).to.eql('string'); | ||
}); | ||
|
||
it('should be able to encrypt a number', () => { | ||
expect(number).to.be.a('number'); | ||
expect(typeof encryptNumber).to.eql('string'); | ||
}); | ||
|
||
it('should be able to encrypt a boolean', () => { | ||
expect(boolean).to.be.a('boolean'); | ||
expect(typeof encryptBoolean).to.eql('string'); | ||
}); | ||
}); | ||
|
||
describe('Decrytion', () => { | ||
it('should be able to decrypt original string', () => { | ||
expect(decryptString).to.be.eql(string); | ||
expect(typeof decryptString).to.eql('string'); | ||
}); | ||
|
||
it('should be able to decrypt original object', () => { | ||
expect(decryptObject).to.be.eql(object); | ||
expect(typeof decryptObject).to.eql('object'); | ||
}); | ||
|
||
it('should be able to decrypt original number', () => { | ||
expect(decryptNumber).to.be.eql(number); | ||
expect(typeof decryptNumber).to.eql('number'); | ||
}); | ||
|
||
it('should be able to decrypt original boolean', () => { | ||
expect(decryptBoolean).to.be.eql(boolean); | ||
expect(typeof decryptBoolean).to.eql('boolean'); | ||
}); | ||
}); | ||
|
||
describe('Error handling and validations', () => { | ||
it('should error when secret is not provided', () => { | ||
try { | ||
encrypt('nullSecret', _nullSecret); | ||
} catch (error) { | ||
expect(error.message).equal('must be initialized with a secret key of type string'); | ||
} | ||
}); | ||
|
||
it('should throw an error when an undefined data is to be encrypted', () => { | ||
try { | ||
encrypt(undefined, _secret); | ||
} catch (error) { | ||
expect(error.message).equal('no data was entered, enter data of type object, number, string or boolean to be encrypted.'); | ||
} | ||
}); | ||
|
||
it('should throw an error when an undefined data is to be encrypted', () => { | ||
try { | ||
encrypt(null, _secret); | ||
} catch (error) { | ||
expect(error.message).equal('no data was entered, enter data of type object, number, string or boolean to be encrypted.'); | ||
} | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters