mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-19 17:55:17 -04:00
test(generatePublicId): test if with a given random buffer a correct encoding is generated
Signed-off-by: Philip Molares <philip.molares@udo.edu>
This commit is contained in:
parent
b636afc4bd
commit
eea0e410d3
1 changed files with 22 additions and 0 deletions
22
src/notes/utils.spec.ts
Normal file
22
src/notes/utils.spec.ts
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
/*
|
||||||
|
* SPDX-FileCopyrightText: 2021 The HedgeDoc developers (see AUTHORS file)
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { randomBytes } from 'crypto';
|
||||||
|
import { generatePublicId } from './utils';
|
||||||
|
jest.mock('crypto');
|
||||||
|
|
||||||
|
it('generatePublicId', () => {
|
||||||
|
const random128bitBuffer = Buffer.from([
|
||||||
|
0xe1, 0x75, 0x86, 0xb7, 0xc3, 0xfb, 0x03, 0xa9, 0x26, 0x9f, 0xc9, 0xd6,
|
||||||
|
0x8c, 0x2d, 0x7b, 0x7b,
|
||||||
|
]);
|
||||||
|
const mockRandomBytes = randomBytes as jest.MockedFunction<
|
||||||
|
typeof randomBytes
|
||||||
|
>;
|
||||||
|
mockRandomBytes.mockImplementationOnce((_) => random128bitBuffer);
|
||||||
|
|
||||||
|
expect(generatePublicId()).toEqual('w5trddy3zc1tj9mzs7b8rbbvfc');
|
||||||
|
});
|
Loading…
Add table
Add a link
Reference in a new issue