60 lines
No EOL
2 KiB
TypeScript
60 lines
No EOL
2 KiB
TypeScript
import { describe, expect, it } from 'bun:test';
|
|
import { getRandomUserAgent } from '../src/user-agent';
|
|
|
|
describe('User Agent', () => {
|
|
describe('getRandomUserAgent', () => {
|
|
it('should return a user agent string', () => {
|
|
const userAgent = getRandomUserAgent();
|
|
expect(typeof userAgent).toBe('string');
|
|
expect(userAgent.length).toBeGreaterThan(0);
|
|
});
|
|
|
|
it('should return a valid user agent containing Mozilla', () => {
|
|
const userAgent = getRandomUserAgent();
|
|
expect(userAgent).toContain('Mozilla');
|
|
});
|
|
|
|
it('should return different user agents on multiple calls', () => {
|
|
const userAgents = new Set();
|
|
// Get 20 user agents
|
|
for (let i = 0; i < 20; i++) {
|
|
userAgents.add(getRandomUserAgent());
|
|
}
|
|
// Should have at least 2 different user agents
|
|
expect(userAgents.size).toBeGreaterThan(1);
|
|
});
|
|
|
|
it('should return user agents with browser identifiers', () => {
|
|
const userAgent = getRandomUserAgent();
|
|
const hasBrowser =
|
|
userAgent.includes('Chrome') ||
|
|
userAgent.includes('Firefox') ||
|
|
userAgent.includes('Safari') ||
|
|
userAgent.includes('Edg');
|
|
expect(hasBrowser).toBe(true);
|
|
});
|
|
|
|
it('should return user agents with OS identifiers', () => {
|
|
const userAgent = getRandomUserAgent();
|
|
const hasOS =
|
|
userAgent.includes('Windows') ||
|
|
userAgent.includes('Macintosh') ||
|
|
userAgent.includes('Mac OS X');
|
|
expect(hasOS).toBe(true);
|
|
});
|
|
|
|
it('should handle multiple concurrent calls', () => {
|
|
const promises = Array(10)
|
|
.fill(null)
|
|
.map(() => Promise.resolve(getRandomUserAgent()));
|
|
|
|
return Promise.all(promises).then(userAgents => {
|
|
expect(userAgents).toHaveLength(10);
|
|
userAgents.forEach(ua => {
|
|
expect(typeof ua).toBe('string');
|
|
expect(ua.length).toBeGreaterThan(0);
|
|
});
|
|
});
|
|
});
|
|
});
|
|
}); |