Files
homeclaw/tests/exchange-rate.test.ts
T

69 lines
3.2 KiB
TypeScript

/**
* exchange_rate — 통화 이름 해석·결과 포맷·툴 스코프 게이트(네트워크 없음).
*/
import { describe, test } from 'node:test';
import assert from 'node:assert/strict';
import { toCurrencyCode, formatRates } from '../src/tools/exchange-rate';
import { buildSkillToolFilter } from '../src/gateway/chat/tool-scope';
describe('toCurrencyCode', () => {
test('ISO 코드와 한국어 이름', () => {
assert.equal(toCurrencyCode('usd'), 'USD');
assert.equal(toCurrencyCode('달러'), 'USD');
assert.equal(toCurrencyCode('홍콩 달러'), 'HKD');
assert.equal(toCurrencyCode('엔화'), 'JPY');
assert.equal(toCurrencyCode('원화'), 'KRW');
assert.equal(toCurrencyCode('인도네시아 루피아'), 'IDR');
assert.equal(toCurrencyCode('뭔지모를돈'), null);
});
});
describe('formatRates', () => {
test('기준일·출처·환산 금액·수수료 안내', () => {
const t = formatRates({ base: 'USD', date: '2026-10-23', source: 'ECB', rates: { KRW: 1324.45 } }, ['KRW'], [1600, 2400]);
assert.match(t, /기준일 2026-10-23 · ECB/);
assert.match(t, /1 USD = 1,324\.45 KRW/);
assert.match(t, /1,600 USD = 2,119,120 KRW/);
assert.match(t, /2,400 USD = 3,178,680 KRW/);
assert.match(t, /수수료/);
});
test('엔→원은 100엔 단위도', () => {
const t = formatRates({ base: 'JPY', date: 'd', source: 's', rates: { KRW: 8.45 } }, ['KRW'], []);
assert.match(t, /100 JPY = 845 KRW/);
assert.match(t, /역환율 1 KRW = 0\.1183 JPY/);
});
});
describe('exchange_rate 게이트', () => {
const filter = (message: string, recentUserText = message, lastAssistantMsg = '') => buildSkillToolFilter({
message, recentUserText, lastAssistantMsg, sessionId: 'abc', userWorkspace: null, isSkillEnabledForUser: () => true,
} as any)('exchange_rate');
test('환율 어휘면 연다', () => {
assert.equal(filter('오늘 달러 환율 얼마야?'), true);
assert.equal(filter('100엔이면 우리 돈 얼마?'), true);
assert.equal(filter('$2,400이면?'), true);
});
test('직전 답에 외화 금액이 있고 원화를 물으면 연다', () => {
assert.equal(filter('한달에 300 만원 정도란 거지?', '한달에 300 만원 정도란 거지?', '2베드룸은 월 $1,600~2,400 선입니다.'), true);
});
test('관계없는 말엔 닫는다', () => {
assert.equal(filter('내일 날씨 어때?'), false);
assert.equal(filter('엔진 오일 교체 주기'), false);
assert.equal(filter('한달에 300 만원 정도란 거지?'), false);
});
});
describe('기본 노출 다이어트(10-25)', () => {
const on = (message: string, tool: string) => buildSkillToolFilter({
message, recentUserText: message, lastAssistantMsg: '', sessionId: 'abc', userWorkspace: null, isSkillEnabledForUser: () => true,
} as any)(tool);
test('search_images는 사진 요청에만', () => {
assert.equal(on('눈향나무 사진 찾아줘', 'search_images'), true);
assert.equal(on('몬타나', 'search_images'), false);
});
test('memory_stats는 기억 질문에만', () => {
assert.equal(on('너 나에 대해 기억하는 게 몇 개나 돼?', 'memory_stats'), true);
assert.equal(on('몬태나 살기 좋은 곳', 'memory_stats'), false);
});
});