mirror of
https://github.com/duhanbalci/iyzico.git
synced 2026-03-03 20:29:18 +00:00
init
This commit is contained in:
53
tests/unit/utils.test.ts
Normal file
53
tests/unit/utils.test.ts
Normal file
@@ -0,0 +1,53 @@
|
||||
/**
|
||||
* Utility functions unit tests
|
||||
*/
|
||||
|
||||
import { describe, it, expect } from 'vitest';
|
||||
import { generateRandomNumber, generateRandomKey } from '../../src/utils';
|
||||
|
||||
describe('generateRandomNumber', () => {
|
||||
it('should generate a number within the specified range', () => {
|
||||
const result = generateRandomNumber(1, 10);
|
||||
expect(result).toBeGreaterThanOrEqual(1);
|
||||
expect(result).toBeLessThanOrEqual(10);
|
||||
});
|
||||
|
||||
it('should use default values when no arguments provided', () => {
|
||||
const result = generateRandomNumber();
|
||||
expect(result).toBeGreaterThanOrEqual(0);
|
||||
expect(result).toBeLessThanOrEqual(100);
|
||||
});
|
||||
|
||||
it('should throw error when min is greater than max', () => {
|
||||
expect(() => generateRandomNumber(10, 5)).toThrow('Min value cannot be greater than max value');
|
||||
});
|
||||
|
||||
it('should handle equal min and max', () => {
|
||||
const result = generateRandomNumber(5, 5);
|
||||
expect(result).toBe(5);
|
||||
});
|
||||
});
|
||||
|
||||
describe('generateRandomKey', () => {
|
||||
it('should generate a non-empty string', () => {
|
||||
const result = generateRandomKey();
|
||||
expect(result).toBeTruthy();
|
||||
expect(typeof result).toBe('string');
|
||||
expect(result.length).toBeGreaterThan(0);
|
||||
});
|
||||
|
||||
it('should generate different keys on each call', () => {
|
||||
const key1 = generateRandomKey();
|
||||
const key2 = generateRandomKey();
|
||||
expect(key1).not.toBe(key2);
|
||||
});
|
||||
|
||||
it('should generate keys that start with timestamp', () => {
|
||||
const result = generateRandomKey();
|
||||
const timestamp = Date.now();
|
||||
const keyTimestamp = parseInt(result.substring(0, 13));
|
||||
// Should be within 1 second of current timestamp
|
||||
expect(Math.abs(timestamp - keyTimestamp)).toBeLessThan(1000);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user