From 2cefb9350491bcea909e6c32d1e7f5bf91d6fb86 Mon Sep 17 00:00:00 2001 From: Ratnesh Mishra Date: Sat, 10 Feb 2024 04:14:01 +0530 Subject: [PATCH 1/2] test: Add failing tests in util.spec.ts --- apps/api/src/common/util.spec.ts | 38 ++++++++++++++++++++++++-------- 1 file changed, 29 insertions(+), 9 deletions(-) diff --git a/apps/api/src/common/util.spec.ts b/apps/api/src/common/util.spec.ts index 9a27c4a3..8b69b605 100644 --- a/apps/api/src/common/util.spec.ts +++ b/apps/api/src/common/util.spec.ts @@ -26,16 +26,26 @@ describe('util', () => { expect(decrypted).toEqual(plaintext) }) + it('should fail to encrypt and decrypt a string', () => { + const keyPair = createKeyPair() + const plainText = 'hello world' + const encrypted = encrypt(keyPair.publicKey, plainText) + const modifiedText = 'modified hello world' + const decrypted = decrypt(keyPair.privateKey, encrypted) + expect(decrypted).not.toEqual(modifiedText) + }) + + const object = { + id: '1', + name: 'John Doe', + email: 'johndoe@keyshade.xyz', + profilePictureUrl: 'https://keyshade.xyz/johndoe.jpg', + isActive: true, + isOnboardingFinished: false, + isAdmin: false + } + it('should exclude fields', () => { - const object = { - id: '1', - name: 'John Doe', - email: 'johndoe@keyshade.xyz', - profilePictureUrl: 'https://keyshade.xyz/johndoe.jpg', - isActive: true, - isOnboardingFinished: false, - isAdmin: false - } const excluded = excludeFields(object, 'isActive') expect(excluded).not.toHaveProperty('isActive') expect(excluded).toEqual({ @@ -43,4 +53,14 @@ describe('util', () => { isActive: undefined }) }) + + it ('should fail to exclude fields', () => { + const excluded = excludeFields(object, 'isActive') + excluded.isActive = true + expect(excluded).toHaveProperty('isActive') + expect(excluded).toEqual({ + ...object, + isActive: true + }) + }) }) From 55497fd5c2d9f37b44692f5e08f47cbc5abdf362 Mon Sep 17 00:00:00 2001 From: Ratnesh Mishra Date: Sun, 11 Feb 2024 00:22:59 +0530 Subject: [PATCH 2/2] test: Add failing tests in util.spec.ts --- apps/api/src/common/util.spec.ts | 38 +++++++++++++------------------- 1 file changed, 15 insertions(+), 23 deletions(-) diff --git a/apps/api/src/common/util.spec.ts b/apps/api/src/common/util.spec.ts index 8b69b605..2dd037f1 100644 --- a/apps/api/src/common/util.spec.ts +++ b/apps/api/src/common/util.spec.ts @@ -28,24 +28,26 @@ describe('util', () => { it('should fail to encrypt and decrypt a string', () => { const keyPair = createKeyPair() + const differenetKeyPair = createKeyPair() const plainText = 'hello world' const encrypted = encrypt(keyPair.publicKey, plainText) - const modifiedText = 'modified hello world' - const decrypted = decrypt(keyPair.privateKey, encrypted) - expect(decrypted).not.toEqual(modifiedText) + const decrypted = () => { + decrypt(differenetKeyPair.privateKey, encrypted); + }; + expect(decrypted).toThrow() }) - const object = { - id: '1', - name: 'John Doe', - email: 'johndoe@keyshade.xyz', - profilePictureUrl: 'https://keyshade.xyz/johndoe.jpg', - isActive: true, - isOnboardingFinished: false, - isAdmin: false - } - it('should exclude fields', () => { + const object = { + id: '1', + name: 'John Doe', + email: 'johndoe@keyshade.xyz', + profilePictureUrl: 'https://keyshade.xyz/johndoe.jpg', + isActive: true, + isOnboardingFinished: false, + isAdmin: false + } + const excluded = excludeFields(object, 'isActive') expect(excluded).not.toHaveProperty('isActive') expect(excluded).toEqual({ @@ -53,14 +55,4 @@ describe('util', () => { isActive: undefined }) }) - - it ('should fail to exclude fields', () => { - const excluded = excludeFields(object, 'isActive') - excluded.isActive = true - expect(excluded).toHaveProperty('isActive') - expect(excluded).toEqual({ - ...object, - isActive: true - }) - }) })