Skip to content

Commit ffc9782

Browse files
committed
test: 열차 조회 - 조회하는 구간의 요금 정보가 없는 경우 예외 발생 테스트 작성 (#201)
1 parent 8220bc2 commit ffc9782

1 file changed

Lines changed: 43 additions & 0 deletions

File tree

src/test/java/com/sudo/railo/train/application/TrainSearchServiceTest.java

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import com.sudo.railo.train.application.dto.response.TrainSearchSlicePageResponse;
3434
import com.sudo.railo.train.domain.Station;
3535
import com.sudo.railo.train.domain.Train;
36+
import com.sudo.railo.train.exception.TrainErrorCode;
3637
import com.sudo.railo.train.infrastructure.SeatRepository;
3738
import com.sudo.railo.train.infrastructure.StationRepository;
3839
import com.sudo.railo.train.infrastructure.TrainScheduleRepository;
@@ -283,6 +284,48 @@ record PagingTest(int pageSize, int expectedFirstPageSize, int expectedSecondPag
283284
});
284285
}
285286

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+
286329
/**
287330
* 열차 스케줄 생성 헬퍼
288331
*/

0 commit comments

Comments
 (0)