8000 fix: 메가박스 경기 광주시 지역 코드 오판정 수정 by Jacob-9909 · Pull Request #306 · 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
11 changes: 8 additions & 3 deletions src/services/megabox/location.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,17 @@ function isValidCoordinate(value: number | undefined): value is number {

function resolveAreaCodeFromText(text: string): string | null {
const normalized = text.replace(/\s+/g, '');
// 목록 순서가 아니라 텍스트에서 가장 앞에 나온 지역을 사용합니다. (예: "경기 광주시"는 광주광역시가 아닌 경기도)
let matchedAreaCode: string | null = null;
let matchedIndex = Number.POSITIVE_INFINITY;
for (const [region, areaCode] of MEGABOX_AREA_CODE_BY_REGION) {
if (normalized.includes(region.replace(/\s+/g, ''))) {
return areaCode;
const index = normalized.indexOf(region);
if (index !== -1 && index < matchedIndex) {
matchedAreaCode = areaCode;
matchedIndex = index;
}
}
return null;
return matchedAreaCode;
}

export async function resolveMegaboxLocation(
Expand Down
8 changes: 8 additions & 0 deletions tests/services/megabox/location.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,4 +211,12 @@ describe('무료 위치 해석 계약', () => {
mockFetch.mockResolvedValueOnce(new Response(JSON.stringify({ documents: [{ place_name: '부산역', address_name: '부산 동구', x: '129.041', y: '35.115' }] })));
expect(await resolveMegaboxLocation({ keyword: '부산역' }, { kakaoRestApiKey: 'free' })).toMatchObject({ areaCode: '26', latitude: 35.115 });
});
it('경기 광주시 주소는 광주광역시가 아닌 경기 지역으로 결정한다', async () => {
mockFetch.mockResolvedValueOnce(new Response(JSON.stringify({ documents: [{ place_name: '경안동', address_name: '경기 광주시 경안동', x: '127.255', y: '37.41' }] })));
expect(await resolveMegaboxLocation({ keyword: '경안동' }, { kakaoRestApiKey: 'free' })).toMatchObject({ areaCode: '41' });
});
it('광주광역시 주소는 광주 지역으로 결정한다', async () => {
mockFetch.mockResolvedValueOnce(new Response(JSON.stringify({ documents: [{ place_name: '광주송정역', address_name: '광주 광산구 송정동', x: '126.793', y: '35.137' }] })));
expect(await resolveMegaboxLocation({ keyword: '광주송정역' }, { kakaoRestApiKey: 'free' })).toMatchObject({ areaCode: '29' });
});
});
Loading
0