-
Notifications
You must be signed in to change notification settings - Fork 3
[feature] stringToDate 유틸리티 함수 단위 테스트 추가 #442
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
adc74e0
987c1d5
c0de6ab
24930ef
f41a55c
d0c9b4d
28de158
a5ab9b9
f49d960
e7efb5c
cddbfbb
53975a8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| import { parseRecruitmentPeriod } from './recruitmentPeriodParser.ts'; | ||
|
|
||
| describe('parseRecruitmentPeriod 함수 테스트', () => { | ||
| it('올바른 형식의 날짜를 파싱한다.', () => { | ||
| const input = '2024.03.20 14:00 ~ 2024.03.25 18:00'; | ||
| const result = parseRecruitmentPeriod(input); | ||
|
|
||
| expect(result.recruitmentStart).toEqual(new Date('2024-03-20T14:00:00')); | ||
| expect(result.recruitmentEnd).toEqual(new Date('2024-03-25T18:00:00')); | ||
| }); | ||
|
|
||
| it('날짜가 기간형식이 아닌 단일 날짜 형식인 경우 null을 반환한다.', () => { | ||
| const input = '2024.03.20 14:00'; | ||
| const result = parseRecruitmentPeriod(input); | ||
|
|
||
| expect(result.recruitmentStart).toBeNull(); | ||
| expect(result.recruitmentEnd).toBeNull(); | ||
| }); | ||
|
|
||
| it('빈 문자열이라면 null을 반환한다.', () => { | ||
| const input = ''; | ||
| const result = parseRecruitmentPeriod(input); | ||
|
|
||
| expect(result.recruitmentStart).toBeNull(); | ||
| expect(result.recruitmentEnd).toBeNull(); | ||
| }); | ||
|
|
||
| it('날짜 사이 ~가 없다면 null을 반환한다.', () => { | ||
| const input = '2024.03.20 14:00 - 2024.03.25 18:00'; | ||
| const result = parseRecruitmentPeriod(input); | ||
|
|
||
| expect(result.recruitmentStart).toBeNull(); | ||
| expect(result.recruitmentEnd).toBeNull(); | ||
| }); | ||
| }); | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,50 @@ | ||||||||||||||||||||||||||||||||
| import { parseRecruitmentDateString } from './recruitmentPeriodParser.ts'; | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| describe('parseRecruitmentPeriod 함수 테스트', () => { | ||||||||||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. describe 블록 이름이 실제 테스트하는 함수와 일치하지 않습니다. describe 블록에서 "parseRecruitmentPeriod 함수 테스트"라고 되어 있지만, 실제로는 다음과 같이 수정해주세요: -describe('parseRecruitmentPeriod 함수 테스트', () => {
+describe('parseRecruitmentDateString 함수 테스트', () => {📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||
| it('날짜와 시간이 포함된 문자열을 Date 객체로 정확히 바꾼다', () => { | ||||||||||||||||||||||||||||||||
| const input = '2025.05.25 13:45'; | ||||||||||||||||||||||||||||||||
| const result = new Date('2025-05-25T13:45:00'); | ||||||||||||||||||||||||||||||||
| expect(parseRecruitmentDateString(input)).toEqual(result); | ||||||||||||||||||||||||||||||||
|
Comment on lines
+6
to
+7
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Verification agent 🧩 Analysis chain시간대 문제로 인한 테스트 불안정성 가능성을 확인해주세요. 테스트에서 다음 스크립트로 시간대 문제가 있는지 확인해보겠습니다: Also applies to: 12-13 🏁 Script executed: #!/bin/bash
# Description: 테스트 파일의 Date 객체 생성 방식 확인
# Test: Date 객체 생성 패턴 검색
rg -A 2 -B 2 "new Date\(" frontend/src/utils/recruitmentPeriodParser.test.tsLength of output: 513 🏁 Script executed: #!/bin/bash
# Retrieve the implementation of parseRecruitmentDateString for timezone behavior analysis
rg -n "parseRecruitmentDateString" -A5 -B5 frontend/src/utils/recruitmentPeriodParser.tsLength of output: 174 🏁 Script executed: #!/bin/bash
# Search for parseRecruitmentDateString implementation across the repo
rg -n "parseRecruitmentDateString" -A5 -B5Length of output: 5713 🏁 Script executed: #!/bin/bash
# List files in the utils directory
echo "Files in frontend/src/utils:"
ls -1 frontend/src/utils
# Print the content of the parser implementation file(s)
echo -e "\nContent of recruitmentPeriodParser.ts:"
sed -n '1,200p' frontend/src/utils/recruitmentPeriodParser.ts || echo "frontend/src/utils/recruitmentPeriodParser.ts not found"
echo -e "\nContent of recruitmentPeriodParser.ts.ts:"
sed -n '1,200p' frontend/src/utils/recruitmentPeriodParser.ts.ts || echo "frontend/src/utils/recruitmentPeriodParser.ts.ts not found"Length of output: 1734 테스트의 Date 생성 방식이 로컬 타임존에 종속되어 있어 환경별로 실패할 수 있습니다 ISO 문자열( 수정 위치:
제안 드리는 diff: it('날짜와 시간이 포함된 문자열을 Date 객체로 정확히 바꾼다', () => {
const input = '2025.05.25 13:45';
- const result = new Date('2025-05-25T13:45:00');
+ const result = new Date(2025, 4, 25, 13, 45);
expect(parseRecruitmentDateString(input)).toEqual(result);
});
it('자정 시간 "YYYY.MM.DD 00:00" 형식을 올바르게 Date 객체로 변환한다', () => {
const input = '2025.05.25 00:00';
- const result = new Date('2025-05-25T00:00:00');
+ const result = new Date(2025, 4, 25, 0, 0);
expect(parseRecruitmentDateString(input)).toEqual(result);
});📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| it('자정 시간 "YYYY.MM.DD 00:00" 형식을 올바르게 Date 객체로 변환한다', () => { | ||||||||||||||||||||||||||||||||
| const input = '2025.05.25 00:00'; | ||||||||||||||||||||||||||||||||
| const result = new Date('2025-05-25T00:00:00'); | ||||||||||||||||||||||||||||||||
| expect(parseRecruitmentDateString(input)).toEqual(result); | ||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| it('공백이 없는 문자열이라면 예외가 발생한다.', () => { | ||||||||||||||||||||||||||||||||
| const input = '2025.05.2513:45'; | ||||||||||||||||||||||||||||||||
| expect(() => parseRecruitmentDateString(input)).toThrow( | ||||||||||||||||||||||||||||||||
| '유효하지 않은 날짜 형식입니다. 형식은 "YYYY.MM.DD HH:mm" 이어야 합니다.', | ||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| it('시간 부분이 누락된 경우 예외가 발생한다', () => { | ||||||||||||||||||||||||||||||||
| const input = '2025.05.25 '; | ||||||||||||||||||||||||||||||||
| expect(() => parseRecruitmentDateString(input)).toThrow( | ||||||||||||||||||||||||||||||||
| '유효하지 않은 날짜 형식입니다. 형식은 "YYYY.MM.DD HH:mm" 이어야 합니다.', | ||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| it('날짜 부분이 누락된 경우 예외가 발생한다', () => { | ||||||||||||||||||||||||||||||||
| const input = ' 13:45'; | ||||||||||||||||||||||||||||||||
| expect(() => parseRecruitmentDateString(input)).toThrow( | ||||||||||||||||||||||||||||||||
| '유효하지 않은 날짜 형식입니다. 형식은 "YYYY.MM.DD HH:mm" 이어야 합니다.', | ||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| it('빈 문자열이 주어지면 예외가 발생한다', () => { | ||||||||||||||||||||||||||||||||
| const input = ''; | ||||||||||||||||||||||||||||||||
| expect(() => parseRecruitmentDateString(input)).toThrow( | ||||||||||||||||||||||||||||||||
| '유효하지 않은 날짜 형식입니다. 형식은 "YYYY.MM.DD HH:mm" 이어야 합니다.', | ||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| it('YYYY.MM.DD HH:mm 형식이 아닌 입력에 대해 에러를 던진다', () => { | ||||||||||||||||||||||||||||||||
| const input = '1.1.1 1:1'; | ||||||||||||||||||||||||||||||||
| expect(() => parseRecruitmentDateString(input)).toThrow( | ||||||||||||||||||||||||||||||||
| '유효하지 않은 날짜 형식입니다. 형식은 "YYYY.MM.DD HH:mm" 이어야 합니다.', | ||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| import { parse, isValid } from 'date-fns'; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Verification agent 🧩 Analysis chain파일명의 확장자를 확인해주세요. 파일명이 다음 스크립트로 파일명을 확인해보겠습니다: 🏁 Script executed: #!/bin/bash
# Description: 중복된 .ts 확장자를 가진 파일 확인
# Test: .ts.ts 확장자를 가진 파일 검색
fd "\.ts\.ts$" frontend/src/Length of output: 79 파일명 확장자 중복 제거 요청
- frontend/src/utils/recruitmentPeriodParser.ts.ts
+ frontend/src/utils/recruitmentPeriodParser.ts🤖 Prompt for AI Agents |
||
|
|
||
| export const parseRecruitmentDateString = (s: string): Date => { | ||
| const regex = /^\d{4}\.\d{2}\.\d{2} \d{2}:\d{2}$/; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion 정규식 패턴을 명명된 상수로 추출해야 합니다. 코딩 가이드라인에 따라 매직 넘버와 문자열을 명명된 상수로 교체해야 합니다. 정규식 패턴을 상수로 추출하면 가독성과 재사용성이 향상됩니다. 다음과 같이 수정해주세요: +const DATE_TIME_REGEX = /^\d{4}\.\d{2}\.\d{2} \d{2}:\d{2}$/;
+
export const parseRecruitmentDateString = (s: string): Date => {
- const regex = /^\d{4}\.\d{2}\.\d{2} \d{2}:\d{2}$/;
- if (!regex.test(s)) {
+ if (!DATE_TIME_REGEX.test(s)) {🤖 Prompt for AI Agents |
||
| if (!regex.test(s)) { | ||
| throw new Error( | ||
| '유효하지 않은 날짜 형식입니다. 형식은 "YYYY.MM.DD HH:mm" 이어야 합니다.', | ||
| ); | ||
|
Comment on lines
+6
to
+8
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion 중복된 에러 메시지를 상수로 추출해야 합니다. 동일한 에러 메시지가 두 곳에서 반복되고 있습니다. DRY 원칙에 따라 상수로 추출하는 것이 좋습니다. 다음과 같이 수정해주세요: +const INVALID_DATE_FORMAT_ERROR = '유효하지 않은 날짜 형식입니다. 형식은 "YYYY.MM.DD HH:mm" 이어야 합니다.';
+
export const parseRecruitmentDateString = (s: string): Date => {
const regex = /^\d{4}\.\d{2}\.\d{2} \d{2}:\d{2}$/;
if (!regex.test(s)) {
- throw new Error(
- '유효하지 않은 날짜 형식입니다. 형식은 "YYYY.MM.DD HH:mm" 이어야 합니다.',
- );
+ throw new Error(INVALID_DATE_FORMAT_ERROR);
}
const date = parse(s, 'yyyy.MM.dd HH:mm', new Date());
if (!isValid(date)) {
- throw new Error(
- '유효하지 않은 날짜 형식입니다. 형식은 "YYYY.MM.DD HH:mm" 이어야 합니다.',
- );
+ throw new Error(INVALID_DATE_FORMAT_ERROR);
}Also applies to: 12-14 🤖 Prompt for AI Agents |
||
| } | ||
| const date = parse(s, 'yyyy.MM.dd HH:mm', new Date()); | ||
| if (!isValid(date)) { | ||
| throw new Error( | ||
| '유효하지 않은 날짜 형식입니다. 형식은 "YYYY.MM.DD HH:mm" 이어야 합니다.', | ||
| ); | ||
| } | ||
| return date; | ||
| }; | ||
|
|
||
| export const parseRecruitmentPeriod = ( | ||
| periodStr: string, | ||
| ): { recruitmentStart: Date | null; recruitmentEnd: Date | null } => { | ||
| const parts = periodStr.split('~').map((s) => s.trim()); | ||
| if (parts.length !== 2) { | ||
| return { recruitmentStart: null, recruitmentEnd: null }; | ||
| } | ||
|
|
||
| return { | ||
| recruitmentStart: parseRecruitmentDateString(parts[0]), | ||
| recruitmentEnd: parseRecruitmentDateString(parts[1]), | ||
| }; | ||
| }; | ||
This file was deleted.
Uh oh!
There was an error while loading. Please reload this page.