1
0
mirror of https://github.com/pavlobu/deskreen.git synced 2025-05-17 16:00:16 -07:00
deskreen/app/utils/message.spec.ts
2020-12-25 01:11:01 +02:00

54 lines
1.4 KiB
TypeScript

import { prepare, process } from './message';
import getTestPublickKeyPem from './mocks/getTestPublicKeyPem';
import getTestPrivateKeyPem from './mocks/getTestPrivateKeyPem';
interface TestPayload {
text: string;
}
describe('message.ts tests for proper encryption and decryption functionality', () => {
const TEST_TEXT = 'some test text here';
const TEST_TEXT_AS_URL = 'some%20test%20text%20here';
const testPayloadToEncrypt = {
payload: {
text: TEST_TEXT,
},
};
const testUser = {
username: 'testUsername',
id: 'testId',
};
const testPartner = {
publicKey: getTestPublickKeyPem(),
};
it('should create encrypted payload with prepare() method', async () => {
const encryptedPayload = await prepare(
testPayloadToEncrypt,
testUser,
testPartner
);
expect(encryptedPayload.toSend.payload).not.toContain(TEST_TEXT);
expect(encryptedPayload.toSend.payload).not.toContain(TEST_TEXT_AS_URL);
});
it('should decrypt encrypted payload with process() method', async () => {
const encryptedPayload = await prepare(
testPayloadToEncrypt,
testUser,
testPartner
);
const decryptedPayload = await process(
encryptedPayload.toSend,
getTestPrivateKeyPem()
);
expect(
((decryptedPayload.payload as unknown) as TestPayload).text
).toContain(TEST_TEXT_AS_URL);
});
});