mirror of
https://github.com/crypto-pro-web/crypto-pro-js.git
synced 2025-04-21 13:03:07 +03:00
45 lines
1.0 KiB
TypeScript
45 lines
1.0 KiB
TypeScript
import 'cadesplugin';
|
|
import { createHash } from './createHash';
|
|
|
|
const executionSteps = [Symbol('step 0'), Symbol('step 1')];
|
|
|
|
const executionFlow = {
|
|
[executionSteps[0]]: {
|
|
propset_Algorithm: jest.fn(),
|
|
propset_DataEncoding: jest.fn(),
|
|
Hash: jest.fn(),
|
|
Value: executionSteps[1],
|
|
},
|
|
[executionSteps[1]]: 'hash',
|
|
};
|
|
|
|
window.cadesplugin.__defineExecutionFlow(executionFlow);
|
|
window.cadesplugin.CreateObjectAsync.mockImplementation((object) => {
|
|
switch (object) {
|
|
case 'CAdESCOM.HashedData':
|
|
return executionSteps[0];
|
|
}
|
|
});
|
|
|
|
describe('createHash', () => {
|
|
test('uses Buffer to encrypt the message', async () => {
|
|
const originalBufferFrom = global.Buffer.from;
|
|
|
|
(global.Buffer.from as jest.Mock) = jest.fn(() => ({
|
|
toString: jest.fn(),
|
|
}));
|
|
|
|
await createHash('message');
|
|
|
|
expect(global.Buffer.from).toHaveBeenCalledTimes(1);
|
|
|
|
global.Buffer.from = originalBufferFrom;
|
|
});
|
|
|
|
test('returns created hash', async () => {
|
|
const hash = await createHash('message');
|
|
|
|
expect(hash).toEqual('hash');
|
|
});
|
|
});
|