Skip to content

Commit d1f9989

Browse files
패키지 의존성에 vite-tsconfig-paths 추가 및 TypeScript 설정을 개선하여 경로 매핑을 강화하고, E2E 테스트에서 메시지 서비스 관련 유틸리티 함수와 서비스 레이어를 통합하여 테스트 환경을 개선함. 추가적인 타입 검사 규칙을 설정하여 코드 품질을 향상시킴.
1 parent 814a531 commit d1f9989

7 files changed

Lines changed: 272 additions & 202 deletions

File tree

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
"tsup": "^8.5.0",
6363
"typedoc": "^0.28.5",
6464
"typescript": "^5.8.3",
65+
"vite-tsconfig-paths": "^5.1.4",
6566
"vitest": "^3.2.4"
6667
},
6768
"packageManager": "yarn@4.9.2",

test/lib/kakao-test-utils.ts

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
import {KakaoAlimtalkTemplateSchema} from '@/models/base/kakao/kakaoAlimtalkTemplate';
2+
3+
/**
4+
* 카카오 템플릿 변수명에 따른 랜덤 값 생성 함수
5+
*/
6+
export const generateRandomValueForVariable = (
7+
variableName: string,
8+
): string => {
9+
const name = variableName.toLowerCase();
10+
11+
// 변수명에 따른 적절한 더미 데이터 생성
12+
if (
13+
name.includes('이름') ||
14+
name.includes('name') ||
15+
name.includes('고객명')
16+
) {
17+
const names = ['김철수', '이영희', '박민수', '정수진', '최영호'];
18+
return names[Math.floor(Math.random() * names.length)];
19+
}
20+
21+
if (name.includes('날짜') || name.includes('date') || name.includes('일자')) {
22+
const today = new Date();
23+
today.setDate(today.getDate() + Math.floor(Math.random() * 30));
24+
return today.toLocaleDateString('ko-KR');
25+
}
26+
27+
if (name.includes('시간') || name.includes('time')) {
28+
const hour = Math.floor(Math.random() * 24);
29+
const minute = Math.floor(Math.random() * 60);
30+
return `${hour.toString().padStart(2, '0')}:${minute.toString().padStart(2, '0')}`;
31+
}
32+
33+
if (
34+
name.includes('금액') ||
35+
name.includes('price') ||
36+
name.includes('amount')
37+
) {
38+
const amount = Math.floor(Math.random() * 1000000) + 1000;
39+
return amount.toLocaleString('ko-KR') + '원';
40+
}
41+
42+
if (name.includes('번호') || name.includes('number') || name.includes('no')) {
43+
return Math.floor(Math.random() * 10000)
44+
.toString()
45+
.padStart(4, '0');
46+
}
47+
48+
if (
49+
name.includes('등급') ||
50+
name.includes('grade') ||
51+
name.includes('level')
52+
) {
53+
const grades = [
54+
'일반',
55+
'우수',
56+
'VIP',
57+
'VVIP',
58+
'Bronze',
59+
'Silver',
60+
'Gold',
61+
'Platinum',
62+
];
63+
return grades[Math.floor(Math.random() * grades.length)];
64+
}
65+
66+
if (
67+
name.includes('장소') ||
68+
name.includes('여행지') ||
69+
name.includes('location')
70+
) {
71+
const places = [
72+
'서울',
73+
'부산',
74+
'제주도',
75+
'강릉',
76+
'경주',
77+
'전주',
78+
'대전',
79+
'광주',
80+
];
81+
return places[Math.floor(Math.random() * places.length)];
82+
}
83+
84+
// 기본값: 랜덤 문자열
85+
const defaultValues = [
86+
'테스트값',
87+
'샘플데이터',
88+
'예시내용',
89+
'Sample',
90+
'Test',
91+
];
92+
return defaultValues[Math.floor(Math.random() * defaultValues.length)];
93+
};
94+
95+
/**
96+
* 카카오 알림톡 템플릿의 variables 배열에서 변수명을 추출하여
97+
* 랜덤 값으로 채워진 변수 객체를 생성합니다.
98+
*/
99+
export const generateTemplateVariables = (
100+
template: KakaoAlimtalkTemplateSchema,
101+
): Record<string, string> => {
102+
if (!template.variables || template.variables.length === 0) {
103+
return {};
104+
}
105+
106+
return template.variables.reduce(
107+
(acc, variable) => {
108+
acc[variable.name] = generateRandomValueForVariable(variable.name);
109+
return acc;
110+
},
111+
{} as Record<string, string>,
112+
);
113+
};

test/lib/test-layers.ts

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import CashService from '@/services/cash/cashService';
2+
import IamService from '@/services/iam/iamService';
3+
import KakaoChannelService from '@/services/kakao/channels/kakaoChannelService';
4+
import KakaoTemplateService from '@/services/kakao/templates/kakaoTemplateService';
5+
import MessageService from '@/services/messages/messageService';
6+
import StorageService from '@/services/storage/storageService';
7+
import {Config, Context, Effect, Layer} from 'effect';
8+
9+
// Service Tags
10+
export const MessageServiceTag =
11+
Context.GenericTag<MessageService>('MessageService');
12+
export const KakaoChannelServiceTag = Context.GenericTag<KakaoChannelService>(
13+
'KakaoChannelService',
14+
);
15+
export const KakaoTemplateServiceTag = Context.GenericTag<KakaoTemplateService>(
16+
'KakaoTemplateService',
17+
);
18+
export const StorageServiceTag =
19+
Context.GenericTag<StorageService>('StorageService');
20+
export const CashServiceTag = Context.GenericTag<CashService>('CashService');
21+
export const IamServiceTag = Context.GenericTag<IamService>('IamService');
22+
23+
// Helper to create a service layer
24+
const createServiceLayer = <S>(
25+
tag: Context.Tag<S, S>,
26+
ServiceClass: new (apiKey: string, apiSecret: string) => S,
27+
) =>
28+
Layer.effect(
29+
tag,
30+
Effect.gen(function* () {
31+
const apiKey = yield* Config.string('API_KEY');
32+
const apiSecret = yield* Config.string('API_SECRET');
33+
return new ServiceClass(apiKey, apiSecret);
34+
}),
35+
);
36+
37+
// Individual Service Layers
38+
export const MessageServiceLive = createServiceLayer(
39+
MessageServiceTag,
40+
MessageService,
41+
);
42+
export const KakaoChannelServiceLive = createServiceLayer(
43+
KakaoChannelServiceTag,
44+
KakaoChannelService,
45+
);
46+
export const KakaoTemplateServiceLive = createServiceLayer(
47+
KakaoTemplateServiceTag,
48+
KakaoTemplateService,
49+
);
50+
export const StorageServiceLive = createServiceLayer(
51+
StorageServiceTag,
52+
StorageService,
53+
);
54+
export const CashServiceLive = createServiceLayer(CashServiceTag, CashService);
55+
export const IamServiceLive = createServiceLayer(IamServiceTag, IamService);
56+
57+
// Combined Layer for Message Service Tests
58+
export const MessageTestServicesLive = Layer.mergeAll(
59+
MessageServiceLive,
60+
KakaoChannelServiceLive,
61+
KakaoTemplateServiceLive,
62+
StorageServiceLive,
63+
);
64+
65+
// Combined Layer for All Services
66+
export const AllServicesLive = Layer.mergeAll(
67+
MessageTestServicesLive,
68+
CashServiceLive,
69+
IamServiceLive,
70+
);

0 commit comments

Comments
 (0)