Skip to content

Commit ce8ff15

Browse files
committed
test: 삭제 테스트 추가
1 parent ee25e21 commit ce8ff15

File tree

2 files changed

+90
-6
lines changed

2 files changed

+90
-6
lines changed

src/main/java/com/back/domain/study/plan/dto/StudyPlanResponse.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,6 @@ public RepeatRuleResponse(com.back.domain.study.plan.entity.RepeatRule repeatRul
6060
}
6161
}
6262

63-
/**
64-
* 💡 수정됨: byDay 필드가 List<String>이므로, 문자열 분리(split) 대신
65-
* List<String>의 각 요소를 DayOfWeek enum으로 매핑합니다.
66-
*/
6763
public List<DayOfWeek> getByDaysList() {
6864
if (byDay == null || byDay.isEmpty()) {
6965
return List.of();

src/test/java/com/back/domain/study/plan/controller/StudyPlanControllerTest.java

Lines changed: 90 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,7 @@ void t12() throws Exception {
515515
StudyPlan originalPlan = createSinglePlan();
516516
Long planId = originalPlan.getId();
517517

518-
ResultActions resultActions = mvc.perform(MockMvcRequestBuilders.delete("/api/plans/{planId}?applyScope=THIS_ONLY", planId)
518+
ResultActions resultActions = mvc.perform(MockMvcRequestBuilders.delete("/api/plans/{planId}?selectedDate=2025-10-01&applyScope=THIS_ONLY", planId)
519519
.header("Authorization", "Bearer faketoken")
520520
.contentType(MediaType.APPLICATION_JSON))
521521
.andDo(print());
@@ -524,12 +524,100 @@ void t12() throws Exception {
524524
.andExpect(status().isOk()) // 200 OK
525525
.andExpect(handler().handlerType(StudyPlanController.class))
526526
.andExpect(jsonPath("$.success").value(true))
527-
.andExpect(jsonPath("$.message").value("학습 계획이 성공적으로 삭제되었습니다.")); // 예상 응답 메시지
527+
.andExpect(jsonPath("$.message").value("학습 계획이 성공적으로 삭제되었습니다."));
528528

529529
// DB에서 실제로 삭제되었는지 확인
530530
boolean exists = studyPlanRepository.existsById(planId);
531531
assertThat(exists).isFalse();
532+
}
533+
534+
@Test
535+
@DisplayName("계획 삭제 - 반복성 단일 삭제")
536+
void t13() throws Exception {
537+
StudyPlan originalPlan = createDailyPlan();
538+
Long planId = originalPlan.getId();
539+
540+
ResultActions resultActions = mvc.perform(MockMvcRequestBuilders.delete("/api/plans/{planId}?selectedDate=2025-10-01&applyScope=THIS_ONLY", planId)
541+
.header("Authorization", "Bearer faketoken")
542+
.contentType(MediaType.APPLICATION_JSON))
543+
.andDo(print());
544+
545+
resultActions
546+
.andExpect(status().isOk()) // 200 OK
547+
.andExpect(handler().handlerType(StudyPlanController.class))
548+
.andExpect(jsonPath("$.success").value(true))
549+
.andExpect(jsonPath("$.message").value("학습 계획이 성공적으로 삭제되었습니다."));
550+
// 10월 1일에 해당하는 계획은 없어야함
551+
mvc.perform(get("/api/plans/date/2025-10-01")
552+
.header("Authorization", "Bearer faketoken")
553+
.contentType(MediaType.APPLICATION_JSON))
554+
.andDo(print())
555+
.andExpect(jsonPath("$.data.totalCount").value(0));
556+
557+
// 10월 10일에 해당하는 계획은 있어야함
558+
mvc.perform(get("/api/plans/date/2025-10-10")
559+
.header("Authorization", "Bearer faketoken")
560+
.contentType(MediaType.APPLICATION_JSON))
561+
.andDo(print())
562+
.andExpect(jsonPath("$.data.totalCount").value(1));
563+
}
564+
565+
@Test
566+
@DisplayName("계획 삭제 - 반복성 원본 일괄 삭제")
567+
void t14() throws Exception {
568+
StudyPlan originalPlan = createDailyPlan();
569+
Long planId = originalPlan.getId();
570+
571+
ResultActions resultActions = mvc.perform(MockMvcRequestBuilders.delete("/api/plans/{planId}?selectedDate=2025-10-01&applyScope=FROM_THIS_DATE", planId)
572+
.header("Authorization", "Bearer faketoken")
573+
.contentType(MediaType.APPLICATION_JSON))
574+
.andDo(print());
532575

576+
resultActions
577+
.andExpect(status().isOk()) // 200 OK
578+
.andExpect(handler().handlerType(StudyPlanController.class))
579+
.andExpect(jsonPath("$.success").value(true))
580+
.andExpect(jsonPath("$.message").value("학습 계획이 성공적으로 삭제되었습니다."));
581+
582+
// 10월 10일에 해당하는 계획도 없어야함
583+
mvc.perform(get("/api/plans/date/2025-10-10")
584+
.header("Authorization", "Bearer faketoken")
585+
.contentType(MediaType.APPLICATION_JSON))
586+
.andDo(print())
587+
.andExpect(jsonPath("$.data.totalCount").value(0));
588+
}
589+
590+
@Test
591+
@DisplayName("계획 삭제 - 반복성 가상 일괄삭제")
592+
void t15() throws Exception {
593+
StudyPlan originalPlan = createDailyPlan();
594+
Long planId = originalPlan.getId();
595+
596+
ResultActions resultActions = mvc.perform(MockMvcRequestBuilders.delete("/api/plans/{planId}?selectedDate=2025-10-10&applyScope=FROM_THIS_DATE", planId)
597+
.header("Authorization", "Bearer faketoken")
598+
.contentType(MediaType.APPLICATION_JSON))
599+
.andDo(print());
600+
601+
resultActions
602+
.andExpect(status().isOk()) // 200 OK
603+
.andExpect(handler().handlerType(StudyPlanController.class))
604+
.andExpect(jsonPath("$.success").value(true))
605+
.andExpect(jsonPath("$.message").value("학습 계획이 성공적으로 삭제되었습니다."));
606+
607+
// 10월 1일에 해당하는 계획은 있어야함
608+
mvc.perform(get("/api/plans/date/2025-10-01")
609+
.header("Authorization", "Bearer faketoken")
610+
.contentType(MediaType.APPLICATION_JSON))
611+
.andDo(print())
612+
.andExpect(jsonPath("$.data.totalCount").value(1));
613+
614+
// 10.10 이후에 해당하는 계획은 없어야함
615+
mvc.perform(get("/api/plans?start=2025-10-10&end=2025-10-15")
616+
.header("Authorization", "Bearer faketoken")
617+
.contentType(MediaType.APPLICATION_JSON))
618+
.andDo(print())
619+
//검색 결과가 없다면 빈 배열
620+
.andExpect(jsonPath("$.data", Matchers.hasSize(0)));
533621
}
534622

535623

0 commit comments

Comments
 (0)