refactor: replace math.random with crypto

This commit is contained in:
Barış Soner Uşaklı
2024-12-09 18:18:02 -05:00
parent c69765e305
commit 9d2af7e10c
8 changed files with 39 additions and 8 deletions

View File

@@ -102,7 +102,7 @@ describe('Utility Methods', () => {
});
});
describe('UUID generation', () => {
describe('UUID generation / secureRandom', () => {
it('return unique random value every time', () => {
delete require.cache[require.resolve('../src/utils')];
const { generateUUID } = require('../src/utils');
@@ -110,6 +110,19 @@ describe('Utility Methods', () => {
const uuid2 = generateUUID();
assert.notEqual(uuid1, uuid2, 'matches');
});
it('should return a random number between 1-10 inclusive', () => {
const { secureRandom } = require('../src/utils');
const r1 = secureRandom(1, 10);
assert(r1 >= 1);
assert(r1 <= 10);
});
it('should always return 3', () => {
const { secureRandom } = require('../src/utils')
const r1 = secureRandom(3, 3);
assert.strictEqual(r1, 3);
});
});
describe('cleanUpTag', () => {