Add fixture-based unit tests for parseUnits()
All checks were successful
CI/CD Pipeline - Apartment API / Scan Dependencies (pull_request) Successful in 15s
CI/CD Pipeline - Apartment API / Lint & Test (pull_request) Successful in 43s
CI/CD Pipeline - Apartment API / Send Webhook Notification (pull_request) Successful in 2s
CI/CD Pipeline - Apartment API / Build & Push Image (pull_request) Has been skipped
CI/CD Pipeline - Apartment API / Deploy to Production (pull_request) Has been skipped
All checks were successful
CI/CD Pipeline - Apartment API / Scan Dependencies (pull_request) Successful in 15s
CI/CD Pipeline - Apartment API / Lint & Test (pull_request) Successful in 43s
CI/CD Pipeline - Apartment API / Send Webhook Notification (pull_request) Successful in 2s
CI/CD Pipeline - Apartment API / Build & Push Image (pull_request) Has been skipped
CI/CD Pipeline - Apartment API / Deploy to Production (pull_request) Has been skipped
Add 6 new tests using sample-listing-empty.html and sample-listing-call.html fixtures: - Verify empty section container returns empty array - Verify zero-count logging for empty fixtures - Verify extraction of "Call for pricing" units - Verify raw string preservation for price fields - Verify all attribute extraction from call-for-pricing units - Verify image_url handling when img elements are absent Total parseUnits test coverage: 28 tests across 9 describe blocks.
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', () => {
|
||||
it('should handle unavailable units correctly', () => {
|
||||
|
||||
Reference in New Issue
Block a user