Intial Version

This commit is contained in:
2025-12-03 18:00:10 -05:00
parent 43c4227da7
commit 0b86c88eb4
55 changed files with 8938 additions and 0 deletions

View File

@@ -0,0 +1,55 @@
import { ScraperService } from '../../src/scrapers/scraper-service';
import { VendorListing } from '../../src/scrapers/types';
describe('ScraperService', () => {
let service: ScraperService;
beforeEach(() => {
service = new ScraperService();
});
afterEach(async () => {
await service.close();
});
describe('calculatePriceIndex', () => {
it('should return null for empty listings', () => {
const result = service.calculatePriceIndex([]);
expect(result).toBeNull();
});
it('should calculate median for odd number of listings', () => {
const listings: VendorListing[] = [
{ pricePerMillion: 10 } as VendorListing,
{ pricePerMillion: 20 } as VendorListing,
{ pricePerMillion: 30 } as VendorListing,
];
const result = service.calculatePriceIndex(listings);
expect(result).toBe(20);
});
it('should calculate median for even number of listings', () => {
const listings: VendorListing[] = [
{ pricePerMillion: 10 } as VendorListing,
{ pricePerMillion: 20 } as VendorListing,
{ pricePerMillion: 30 } as VendorListing,
{ pricePerMillion: 40 } as VendorListing,
];
const result = service.calculatePriceIndex(listings);
expect(result).toBe(25);
});
it('should handle unsorted listings', () => {
const listings: VendorListing[] = [
{ pricePerMillion: 30 } as VendorListing,
{ pricePerMillion: 10 } as VendorListing,
{ pricePerMillion: 20 } as VendorListing,
];
const result = service.calculatePriceIndex(listings);
expect(result).toBe(20);
});
});
});