7.0.6 사이클에서 유입된 회귀 3건을 출시 전에 닫는다. 추가옵션 저장소의 반환 타입 선언이 실제 반환(중첩 맵)과 어긋나 추가옵션 있는 상품의 담기· 바로구매가 죽었고, 검색 엔진이 결과 소비 시점에 SELECT 를 재작성해 정렬이 참조하던 스코어 별칭을 지웠으며, 미들웨어 targets 가 늘어난 라우트를 따라가지 못해 비회원 현금영수증이 전면 불능이었다. 셋 다 정적 검사의 사각지대였으므로 룰 2건과 계약 테스트를 함께 세워 재발을 막는다. 같은 유형의 잠복 결함 3건(빈 반환의 타입 불일치 2건, 없는 메서드 호출 1건)도 호출 경로가 생기는 순간 fatal 이므로 함께 닫았다. 브라우저 검수 중 드러난 선행 결함 5건을 이어서 수정한다. 엔진이 event 키로 선언한 액션을 React prop 으로 연결하지 않아 오류 없이 조용히 무반응이었고, 연결한 뒤에는 커스텀 컴포넌트의 이벤트 payload 가 유실됐다. 비회원 주문상세 응답에 현금영수증 키가 없어 발급 결과에 도달할 수 없었으며, 입금확인과 현금영수증 발급이 base 통화 금액을 써서 결제 통화가 다른 주문에서 각각 저장 실패와 잘못된 증빙을 냈다. 마지막으로 통화 단위를 코드·문구에서 걷어내 설정으로 이관한다. 다국어 문구의 원/円, 프론트의 KRW 고정표와 리터럴 폴백 173건, 서버 포맷의 통화 코드 리터럴이 대상이며, 기본 통화가 원이 아닌 상점에서 값은 맞고 단위만 틀린 금액이 예외 없이 나가던 문제였다. 통화 판정을 설정 단일 출처로 모으고 규칙 3건을 정적 검사로 고정했다.
95 lines
4.7 KiB
TypeScript
95 lines
4.7 KiB
TypeScript
/**
|
|
* @file optionTotalCurrency.test.tsx
|
|
* @description 상품상세 "총 금액" 선택 통화 환산 구조 회귀 테스트 (D2·D3)
|
|
*
|
|
* 배경:
|
|
* - 상품상세 구매 카드(_purchase_card.json)의 "총 금액"이 선택 통화와 무관하게 KRW 로 고정 표시되던 결함.
|
|
* ① 옵션 선택형(2개 이상): 합계 value 를 multi_currency 로 올바로 합산하나 `.toLocaleString() + '원'` 단위 하드코딩
|
|
* → USD 선택 시 "2.55원"(USD 숫자 + 원) 으로 표시.
|
|
* ② 옵션 없는 상품: `selling_price`(base 정수) * 수량 + '원' → 선택 통화 환산 자체가 없어 항상 base KRW raw.
|
|
* - 수정: 합계 value 를 선택 통화 multi_currency value 로 구한 뒤 handler('formatCurrency', { value, currencyCode })
|
|
* 로 포맷한다(formatCurrency.ts 가 Intl.NumberFormat 으로 통화 기호/소수점 처리).
|
|
*
|
|
* 회귀 차단:
|
|
* - 두 "총 금액" 노드 모두 handler('formatCurrency', ...) 를 통해 선택 통화로 포맷한다.
|
|
* - `.toLocaleString() + '원'` (또는 `+ "원"`) 단위 하드코딩이 없다.
|
|
* - 옵션 없는 상품 합계는 multi_currency_selling_price 선택통화 value 를 우선 사용한다(base 폴백).
|
|
* - 옵션 선택형 합계는 multiCurrencyTotalPrice 선택통화 value 를 합산한다.
|
|
*
|
|
* @vitest-environment jsdom
|
|
*/
|
|
|
|
import { describe, it, expect } from 'vitest';
|
|
import fs from 'node:fs';
|
|
import path from 'node:path';
|
|
|
|
const baseDir = path.resolve(__dirname, '../..');
|
|
|
|
interface Node {
|
|
comment?: string;
|
|
if?: string;
|
|
text?: string;
|
|
props?: Record<string, any>;
|
|
children?: Node[];
|
|
[k: string]: any;
|
|
}
|
|
|
|
function loadJson(relPath: string): Node {
|
|
return JSON.parse(fs.readFileSync(path.resolve(baseDir, relPath), 'utf8'));
|
|
}
|
|
function flatten(node: Node | undefined, acc: Node[] = []): Node[] {
|
|
if (!node) return acc;
|
|
acc.push(node);
|
|
(node.children ?? []).forEach((c) => flatten(c, acc));
|
|
return acc;
|
|
}
|
|
function findByComment(node: Node, needle: string): Node | undefined {
|
|
return flatten(node).find((n) => typeof n.comment === 'string' && n.comment.includes(needle));
|
|
}
|
|
|
|
describe('상품상세 총 금액 선택 통화 환산 (_purchase_card.json)', () => {
|
|
const layout = loadJson('layouts/partials/shop/detail/_purchase_card.json');
|
|
const optionBlock = findByComment(layout, '총 금액 (옵션 선택형');
|
|
const noOptionBlock = findByComment(layout, '총 금액 (옵션 없거나');
|
|
|
|
// value(금액) 노드 = 선택 통화 포맷 맵을 조회하는 노드. 라벨 노드($t:...total_amount)와 구분.
|
|
const optionValueNode = flatten(optionBlock).find(
|
|
(n) => typeof n.text === 'string' && n.text.includes('selectedTotalMultiCurrency'));
|
|
const noOptionValueNode = flatten(noOptionBlock).find(
|
|
(n) => typeof n.text === 'string' && n.text.includes('noOptionTotalMultiCurrency'));
|
|
|
|
it('옵션 선택형 총 금액은 selectedTotalMultiCurrency 선택통화 포맷 맵을 조회한다 (D2)', () => {
|
|
expect(optionValueNode).toBeDefined();
|
|
expect(optionValueNode!.text).toContain("selectedTotalMultiCurrency?.[_global.preferredCurrency ?? _global.defaultCurrency]?.formatted");
|
|
});
|
|
|
|
it('옵션 선택형 총 금액은 handler() 표현식 호출과 원(KRW) 하드코딩을 쓰지 않는다 (금지패턴/D2 회귀 차단)', () => {
|
|
expect(optionValueNode!.text).not.toContain('handler(');
|
|
expect(optionValueNode!.text).not.toMatch(/\+\s*'원'/);
|
|
expect(optionValueNode!.text).not.toMatch(/\+\s*"원"/);
|
|
});
|
|
|
|
it('옵션 없는 상품 총 금액은 noOptionTotalMultiCurrency 또는 단가 formatted 폴백을 쓴다 (D3)', () => {
|
|
expect(noOptionValueNode).toBeDefined();
|
|
expect(noOptionValueNode!.text).toContain("noOptionTotalMultiCurrency?.[_global.preferredCurrency ?? _global.defaultCurrency]?.formatted");
|
|
// 단가 formatted 폴백(초기 수량 1)
|
|
expect(noOptionValueNode!.text).toContain('multi_currency_selling_price');
|
|
});
|
|
|
|
it('옵션 없는 상품 총 금액은 handler() 표현식 호출과 원(KRW) 하드코딩을 쓰지 않는다 (금지패턴/D3 회귀 차단)', () => {
|
|
expect(noOptionValueNode!.text).not.toContain('handler(');
|
|
expect(noOptionValueNode!.text).not.toMatch(/\+\s*'원'/);
|
|
expect(noOptionValueNode!.text).not.toMatch(/\+\s*"원"/);
|
|
});
|
|
|
|
it('개별 선택 항목 가격(multiCurrencyTotalPrice formatted)은 유지된다(비회귀)', () => {
|
|
const text = JSON.stringify(layout);
|
|
expect(text).toContain('multiCurrencyTotalPrice');
|
|
expect(text).toContain("?.[_global.preferredCurrency ?? _global.defaultCurrency]?.formatted");
|
|
});
|
|
|
|
it('레이아웃 전체에 handler() 표현식 호출이 없다 (엔진 표현식 컨텍스트는 handler 미제공)', () => {
|
|
expect(JSON.stringify(layout)).not.toContain("handler('");
|
|
});
|
|
});
|