|
33 | 33 | import com.sudo.railo.train.application.dto.response.TrainSearchSlicePageResponse; |
34 | 34 | import com.sudo.railo.train.domain.Station; |
35 | 35 | import com.sudo.railo.train.domain.Train; |
| 36 | +import com.sudo.railo.train.exception.TrainErrorCode; |
36 | 37 | import com.sudo.railo.train.infrastructure.SeatRepository; |
37 | 38 | import com.sudo.railo.train.infrastructure.StationRepository; |
38 | 39 | import com.sudo.railo.train.infrastructure.TrainScheduleRepository; |
@@ -283,6 +284,48 @@ record PagingTest(int pageSize, int expectedFirstPageSize, int expectedSecondPag |
283 | 284 | }); |
284 | 285 | } |
285 | 286 |
|
| 287 | + @DisplayName("조회하는 구간의 요금 정보가 없으면 STATION_FARE_NOT_FOUND 예외를 던진다") |
| 288 | + @Test |
| 289 | + void shouldThrowStationFareNotFoundWhenFareIsMissing() { |
| 290 | + // given |
| 291 | + LocalDate searchDate = LocalDate.now().plusDays(1); |
| 292 | + |
| 293 | + // 역 생성 |
| 294 | + Station seoul = trainScheduleTestHelper.getOrCreateStation("서울"); |
| 295 | + Station busan = trainScheduleTestHelper.getOrCreateStation("부산"); |
| 296 | + |
| 297 | + // 서울→부산 요금 등록 |
| 298 | + trainScheduleTestHelper.createOrUpdateStationFare("서울", "부산", 50000, 80000); |
| 299 | + |
| 300 | + Train train = trainTestHelper.createRealisticTrain(1, 1, 10, 6); |
| 301 | + // 요금 없는 방향으로 부산→서울 스케줄 생성 |
| 302 | + createTrainSchedule(train, searchDate, "KTX Rev", |
| 303 | + LocalTime.of(15, 0), LocalTime.of(18, 0), |
| 304 | + "부산", "서울" |
| 305 | + ); |
| 306 | + |
| 307 | + // when & then |
| 308 | + TrainSearchRequest request = new TrainSearchRequest( |
| 309 | + busan.getId(), // 출발: 요금 미등록 방향 |
| 310 | + seoul.getId(), // 도착 |
| 311 | + searchDate, |
| 312 | + 1, |
| 313 | + "15" // 15시 이후 |
| 314 | + ); |
| 315 | + |
| 316 | + assertThatThrownBy(() -> |
| 317 | + trainSearchService.searchTrains(request, PageRequest.of(0, 10)) |
| 318 | + ) |
| 319 | + .isInstanceOf(BusinessException.class) |
| 320 | + .satisfies(ex -> { |
| 321 | + BusinessException be = (BusinessException)ex; |
| 322 | + assertThat(be.getErrorCode()) |
| 323 | + .isEqualTo(TrainErrorCode.STATION_FARE_NOT_FOUND); |
| 324 | + assertThat(be.getMessage()) |
| 325 | + .contains(TrainErrorCode.STATION_FARE_NOT_FOUND.getMessage()); |
| 326 | + }); |
| 327 | + } |
| 328 | + |
286 | 329 | /** |
287 | 330 | * 열차 스케줄 생성 헬퍼 |
288 | 331 | */ |
|
0 commit comments