Intial Version
This commit is contained in:
55
backend/tests/scrapers/scraper-service.test.ts
Normal file
55
backend/tests/scrapers/scraper-service.test.ts
Normal 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);
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user