Skip to content

Commit

Permalink
Add: empty string test
Browse files Browse the repository at this point in the history
  • Loading branch information
danang-id committed May 11, 2020
1 parent 915569c commit 938e1be
Showing 1 changed file with 28 additions and 4 deletions.
32 changes: 28 additions & 4 deletions test/Cryptographic.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,23 @@ const object = {
SimpleCrypto: "is great.",
You: "should try it!"
}
const emptyString = ""
const string = "SimpleCrypto is great."
const stringThatStartsWithNumber = "49ers are my favorite team!"
const number = 19960404
const boolean = false

const cipherTextFromObject = instance.encryptObject(object)
const cipherTextFromString = instance.encrypt(string)
const cipherTextFromEmptyString = instance.encrypt(emptyString)
const cipherTextFromStringThatStartsWithNumber = instance.encrypt(stringThatStartsWithNumber)
const cipherTextFromNumber = instance.encrypt(number)
const cipherTextFromBoolean = instance.encrypt(boolean)

const plainExpectsObject = instance.decryptObject(cipherTextFromObject)
const plainExpectsString = instance.decrypt(cipherTextFromString, SimpleCrypto.encoders.Utf8)
const plainExpectsStringThatStartsWithNumber = instance.decrypt(cipherTextFromStringThatStartsWithNumber, SimpleCrypto.encoders.Utf8)
const plainExpectsEmptyString = instance.decrypt(cipherTextFromEmptyString)
const plainExpectsStringThatStartsWithNumber = instance.decrypt(cipherTextFromStringThatStartsWithNumber)
const plainExpectsNumber = instance.decrypt(cipherTextFromNumber, false)
const plainExpectsBoolean = instance.decrypt(cipherTextFromBoolean)

Expand All @@ -42,6 +45,20 @@ describe("Cryptographic: Encryption", () => {
expect(cipherTextFromString.substr(107, 1)).to.be.equals("=")
})

it("should be able to encrypt from empty string", () => {
expect(cipherTextFromEmptyString).to.be.a("string")
expect(cipherTextFromEmptyString).to.have.length(152)
expect(cipherTextFromEmptyString.substr(85, 1)).not.to.be.equals("=")
expect(cipherTextFromEmptyString.substr(86, 2)).to.be.equals("==")
})

it("should be able to encrypt from empty string that starts with number", () => {
expect(cipherTextFromStringThatStartsWithNumber).to.be.a("string")
expect(cipherTextFromStringThatStartsWithNumber).to.have.length(172)
expect(cipherTextFromStringThatStartsWithNumber.substr(106, 1)).not.to.be.equals("=")
expect(cipherTextFromStringThatStartsWithNumber.substr(107, 1)).to.be.equals("=")
})

it("should be able to encrypt from number", () => {
expect(cipherTextFromNumber).to.be.a("string")
expect(cipherTextFromNumber).to.have.length(152)
Expand All @@ -66,13 +83,20 @@ describe("Cryptographic: Decryption", () => {
})

it("should be able to decrypt to string", () => {
expect(plainExpectsStringThatStartsWithNumber).to.be.a("string")
expect(plainExpectsStringThatStartsWithNumber).to.be.eql(stringThatStartsWithNumber)

expect(plainExpectsString).to.be.a("string")
expect(plainExpectsString).to.be.eql(string)
})

it("should be able to decrypt to empty string", () => {
expect(plainExpectsEmptyString).to.be.a("string")
expect(plainExpectsEmptyString).to.be.eql(emptyString)
})

it("should be able to decrypt to string that starts with number", () => {
expect(plainExpectsStringThatStartsWithNumber).to.be.a("string")
expect(plainExpectsStringThatStartsWithNumber).to.be.eql(stringThatStartsWithNumber)
})

it("should be able to decrypt to number", () => {
expect(plainExpectsNumber).to.be.a("number")
expect(plainExpectsNumber).to.be.eql(number)
Expand Down

0 comments on commit 938e1be

Please sign in to comment.