8000 fix: 숫자가 든 역 이름의 좌표 변환 실패 수정 by Jacob-9909 · Pull Request #282 · hmmhmmhm/daiso-mcp · GitHub
[go: up one dir, main page]

Skip to content
Merged
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
3 changes: 2 additions & 1 deletion src/utils/geocode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,8 @@ export async function geocodeLocation(
// 대체 공급자도 최초 요청의 남은 시간만 사용합니다.
const deadline = Date.now() + (options.timeout ?? options.timeoutMs ?? 10000);
const remaining = () => deadline - Date.now();
const isAddress = /(?:로|길|동|읍|면|리)\s*\d/u.test(keyword);
// '을지로3가역'처럼 숫자가 든 역 이름은 주소가 아니라 장소로 검색합니다.
const isAddress = !keyword.endsWith('역') && /(?:로|길|동|읍|면|리)\s*\d/u.test(keyword);
let documents: KakaoDocument[] = [];
const kakaoTimeout = remaining();
if (options.kakaoRestApiKey?.trim() && kakaoTimeout > 0) {
Expand Down
23 changes: 23 additions & 0 deletions tests/utils/geocode-fallback.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,29 @@ describe('정확한 주소 fallback', () => {
'/v1/search/local.json',
]);
});
it.each(['을지로3가역', '종로3가역'])('숫자가 든 역 이름은 장소로 검색한다: %s', async (query) => {
const fetchImpl = responses(
json({
documents: [
{
place_name: `${query} 1호선`,
address_name: '서울 종로구 예시동 10',
road_address_name: '서울 종로구 예시로 지하 129',
x: '126.99',
y: '37.57',
},
],
}),
);
expect(await geocodeLocation(query, { kakaoRestApiKey: 'test-kakao', fetchImpl })).toEqual({
latitude: 37.57,
longitude: 126.99,
formattedAddress: '서울 종로구 예시로 지하 129',
});
expect(new URL(String(fetchImpl.mock.calls[0][0])).pathname).toBe(
'/v2/local/search/keyword.json',
);
});
it('빈 입력과 환경키 없는 입력은 요청하지 않는다', async () => {
expect(await geocodeLocation(' ')).toBeNull();
expect(await geocodeLocation('예시역')).toBeNull();
Expand Down
0