SCRAPE-25: Add fixture-based unit tests for parseUnits() (#29)
Co-authored-by: Stephen Minakian <stephenminakian@gmail.com> Co-committed-by: Stephen Minakian <stephenminakian@gmail.com>
This commit is contained in:
@ -384,7 +384,93 @@ describe('parseUnits', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// ---------------------------------------------------------------
|
// ---------------------------------------------------------------
|
||||||
// 7. Multiple units with varied data
|
// 7. Fixture-based tests (sample-listing-empty.html, sample-listing-call.html)
|
||||||
|
// ---------------------------------------------------------------
|
||||||
|
describe('fixture: sample-listing-empty.html', () => {
|
||||||
|
let emptyHtml;
|
||||||
|
|
||||||
|
beforeAll(() => {
|
||||||
|
emptyHtml = fs.readFileSync(
|
||||||
|
path.join(fixturesDir, 'sample-listing-empty.html'),
|
||||||
|
'utf-8'
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return empty array when fixture has container but no articles', () => {
|
||||||
|
const units = parseUnits(emptyHtml, mockLogger);
|
||||||
|
|
||||||
|
expect(units).toEqual([]);
|
||||||
|
// Container exists so no error about missing container
|
||||||
|
expect(mockLogger.error).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should log zero parsed units for empty fixture', () => {
|
||||||
|
parseUnits(emptyHtml, mockLogger);
|
||||||
|
|
||||||
|
expect(mockLogger.info).toHaveBeenCalledWith(
|
||||||
|
'Units parsed',
|
||||||
|
expect.objectContaining({ count: 0 })
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('fixture: sample-listing-call.html', () => {
|
||||||
|
let callHtml;
|
||||||
|
|
||||||
|
beforeAll(() => {
|
||||||
|
callHtml = fs.readFileSync(
|
||||||
|
path.join(fixturesDir, 'sample-listing-call.html'),
|
||||||
|
'utf-8'
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should extract both units from the call-for-pricing fixture', () => {
|
||||||
|
const units = parseUnits(callHtml, mockLogger);
|
||||||
|
|
||||||
|
expect(units).toHaveLength(2);
|
||||||
|
expect(units.map(u => u.unit_code)).toEqual(['P-101', 'P-102']);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should preserve "Call for pricing" as raw string in the price field', () => {
|
||||||
|
const units = parseUnits(callHtml, mockLogger);
|
||||||
|
|
||||||
|
expect(units[0].price).toBe('Call for pricing');
|
||||||
|
expect(units[1].price).toBe('Call for pricing');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should extract all attributes correctly from call-for-pricing units', () => {
|
||||||
|
const units = parseUnits(callHtml, mockLogger);
|
||||||
|
const unit = units.find(u => u.unit_code === 'P-101');
|
||||||
|
|
||||||
|
expect(unit.id).toBe('9001');
|
||||||
|
expect(unit.unit_id).toBe('9001');
|
||||||
|
expect(unit.floor).toBe('1');
|
||||||
|
expect(unit.area).toBe('750');
|
||||||
|
expect(unit.bed_count).toBe('1');
|
||||||
|
expect(unit.bath_count).toBe('1');
|
||||||
|
expect(unit.available).toBe('true');
|
||||||
|
expect(unit.unavailable).toBe('false');
|
||||||
|
expect(unit.soonest).toBe('Now');
|
||||||
|
expect(unit.date_available).toBe('1706745600');
|
||||||
|
expect(unit.plan_id).toBe('500');
|
||||||
|
expect(unit.plan_name).toBe('Penthouse A');
|
||||||
|
expect(unit.community).toBe('Country Club Towers');
|
||||||
|
expect(unit.asset).toBe('420');
|
||||||
|
expect(unit.href).toBe('?spaces_tab=unit-detail&detail=9001');
|
||||||
|
expect(unit.inventory_href).toBe('?spaces_tab=unit-detail&detail=9001');
|
||||||
|
expect(unit.specials_content).toBe('');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should not have image_url when fixture units lack img elements', () => {
|
||||||
|
const units = parseUnits(callHtml, mockLogger);
|
||||||
|
|
||||||
|
expect(units[0].image_url).toBeUndefined();
|
||||||
|
expect(units[1].image_url).toBeUndefined();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------
|
||||||
|
// 8. Multiple units with varied data
|
||||||
// ---------------------------------------------------------------
|
// ---------------------------------------------------------------
|
||||||
describe('varied unit data', () => {
|
describe('varied unit data', () => {
|
||||||
it('should handle unavailable units correctly', () => {
|
it('should handle unavailable units correctly', () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user