Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions lib/services/immoscout/immoscout-web-translator.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,29 +168,34 @@ export function convertWebToMobile(webUrl) {
}
}

if (segments.includes('shape')) {
throw new Error('Shape is currently not supported using Immoscout');
}

const { query: rawParams } = queryString.parseUrl(webUrl, { arrayFormat: 'comma' });
const webParams = Object.fromEntries(
Object.entries(rawParams).filter(([key]) => key !== 'enteredFrom' && PARAM_NAME_MAP[key]),
);

const geocodes = `/${segments.slice(2, segments.length - 1).join('/')}`;
const isRadius = segments.includes('radius');
const isShape = segments.includes('shape');
const mobileParams = {
searchType: isRadius ? 'radius' : 'region',
searchType: isRadius ? 'radius' : isShape ? 'shape' : 'region',
realestatetype: realType,
...(isRadius ? {} : { geocodes }),
...(isRadius || isShape ? {} : { geocodes }),
...additionalParamsFromWebPath,
};

if (isShape && webParams.shape) {
const browserShape = webParams.shape;
const normalized = browserShape.replace(/\.\./g, '==').replace(/\./g, '=');
const polyline = Buffer.from(normalized, 'base64').toString('utf-8');
mobileParams.shape = polyline; // Raw polyline for Mobile API
}

if (webParams.geocoordinates) {
mobileParams.geocoordinates = webParams.geocoordinates;
}

for (const [key, val] of Object.entries(webParams)) {
if (key === 'shape') continue;
if (key === 'equipment') {
const items = [].concat(val).flatMap((v) => `${v}`.split(','));
const currentEquipmentParams = mobileParams[PARAM_NAME_MAP[key]];
Expand Down
11 changes: 11 additions & 0 deletions test/services/immoscout/immoscout-web-translator.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,17 @@ describe('#immoscout-mobile URL conversion', () => {
expect(actualMobileUrl).to.equal(expectedMobileUrl);
});

// Test shape URL conversion
it('should convert a full web URL with shape to mobile URL', () => {
const webUrl =
'https://www.immobilienscout24.de/Suche/shape/haus-kaufen?shape=aW9yfkhfa3htQXJgUGlnYEBmekhte3BAcXNAfWBsQGNyQ2lkUHVvbEB3eX5Ab25WYn5Fa2BLaGRQY29FaGtTfEhme3xBdHBEdHFMamlHbmdRfHhMcmxPeHlWYnpS&price=-600000.0&ground=240.0-&enteredFrom=result_list';
const expectedMobileUrl =
'https://api.mobile.immobilienscout24.de/search/list?price=-600000.0&realestatetype=housebuy&searchType=shape&shape=ior~H_kxmAr%60Pig%60%40fzHm%7Bp%40qs%40%7D%60l%40crCidPuol%40wy~%40onVb~Ek%60KhdPcoEhkS%7CHf%7B%7CAtpDtqLjiGngQ%7CxLrlOxyVbzR';

const actualMobileUrl = convertWebToMobile(webUrl);
expect(actualMobileUrl).to.equal(expectedMobileUrl);
});

// Test URL conversion of web-only SEO path
it('should convert a SEO web path to the correct query params', () => {
const webUrl = 'https://www.immobilienscout24.de/Suche/de/berlin/berlin/wohnung-mit-balkon-mieten?equipment=garden';
Expand Down
4 changes: 4 additions & 0 deletions test/services/immoscout/testdata.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,9 @@
"rentHouse": {
"url": "https://www.immobilienscout24.de/Suche/de/nordrhein-westfalen/duesseldorf/haus-mieten?enteredFrom=one_step_search",
"type": "houserent"
},
"buyHouseWithShape": {
"url": "https://www.immobilienscout24.de/Suche/shape/haus-kaufen?shape=aW9yfkhfa3htQXJgUGlnYEBmekhte3BAcXNAfWBsQGNyQ2lkUHVvbEB3eX5Ab25WYn5Fa2BLaGRQY29FaGtTfEhme3xBdHBEdHFMamlHbmdRfHhMcmxPeHlWYnpS&price=-600000.0&ground=240.0-&enteredFrom=result_list",
"type": "housebuy"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -141,21 +141,7 @@ export default function ProviderMutator({
</p>
</>
)}
<Banner
fullMode={false}
type="warning"
closeIcon={null}
title={<div style={{ fontWeight: 600, fontSize: '14px', lineHeight: '20px' }}>Warning</div>}
style={{ marginBottom: '1rem' }}
description={
<div>
<p>
Currently, our Immoscout implementation does not support drawing shapes on a map. Use a radius instead.
</p>
</div>
}
/>


<Select
filter
placeholder="Select a provider"
Expand Down
Loading