use randomString/Number from lib in api tests (#2542)

This commit is contained in:
Meisam
2023-01-04 23:09:51 +01:00
committed by GitHub
parent 2607d90094
commit dad5b28cc5
6 changed files with 28 additions and 22 deletions

View File

@@ -0,0 +1,16 @@
const crypto = require('crypto');
const Random = require('crypto-random');
//returns a random number in range of [1 - max]
function randomNumber(max = 5) {
return Random.range(1, max);
}
//returns a random hex string
function randomString(length = 20) {
const bytesCount = Math.ceil(length / 2);
return crypto.randomBytes(bytesCount).toString('hex').substring(0, length);
}
module.exports.randomNumber = randomNumber;
module.exports.randomString = randomString;