Skip to content

Commit

Permalink
test : 버스 시간표 조회 v2 테스트 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
Choon0414 committed Apr 18, 2024
1 parent 6a9ffe7 commit 86b7ef0
Showing 1 changed file with 65 additions and 1 deletion.
66 changes: 65 additions & 1 deletion src/test/java/in/koreatech/koin/acceptance/BusApiTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.springframework.http.HttpStatus;

import in.koreatech.koin.AcceptanceTest;
import in.koreatech.koin.domain.bus.dto.BusTimetableResponse;
import in.koreatech.koin.domain.bus.dto.SingleBusTimeResponse;
import in.koreatech.koin.domain.bus.model.BusRemainTime;
import in.koreatech.koin.domain.bus.model.city.CityBusArrival;
Expand All @@ -40,8 +41,10 @@
import in.koreatech.koin.domain.bus.repository.BusRepository;
import in.koreatech.koin.domain.bus.repository.CityBusCacheRepository;
import in.koreatech.koin.domain.bus.repository.ExpressBusCacheRepository;
import in.koreatech.koin.domain.version.dto.VersionResponse;
import in.koreatech.koin.domain.version.model.Version;
import in.koreatech.koin.domain.version.repository.VersionRepository;
import in.koreatech.koin.domain.version.service.VersionService;
import in.koreatech.koin.support.JsonAssertions;
import io.restassured.RestAssured;
import io.restassured.response.ExtractableResponse;
Expand All @@ -62,6 +65,9 @@ class BusApiTest extends AcceptanceTest {
@Autowired
private ExpressBusCacheRepository expressBusCacheRepository;

@Autowired
private VersionService versionService;

private final Instant UPDATED_AT = ZonedDateTime.parse(
"2024-02-21 18:00:00 KST",
ofPattern("yyyy-MM-dd " + "HH:mm:ss z")
Expand Down Expand Up @@ -158,7 +164,6 @@ void getNextShuttleBusRemainTime() {
);
}


@Test
@DisplayName("다음 시내버스까지 남은 시간을 조회한다. - Redis")
void getNextCityBusRemainTimeRedis() {
Expand Down Expand Up @@ -519,6 +524,7 @@ void getShuttleBusTimetable() {
.param("region", region)
.get("/bus/timetable")
.then()
.log().all()
.statusCode(HttpStatus.OK.value())
.extract();

Expand Down Expand Up @@ -548,4 +554,62 @@ void getShuttleBusTimetable() {
]
""");
}

@Test
@DisplayName("셔틀버스 시간표를 조회한다(업데이트 시각 포함).")
void getShuttleBusTimetableWithUpdatedAt() {
when(dateTimeProvider.getNow()).thenReturn(Optional.of(UPDATED_AT));

versionRepository.save(
Version.builder()
.version("20240_1712920946")
.type("shuttle_bus_timetable")
.build()
);

BusType busType = BusType.from("shuttle");
String direction = "from";
String region = "천안";

ExtractableResponse<Response> response = RestAssured
.given()
.when()
.param("bus_type", busType.name().toLowerCase())
.param("direction", direction)
.param("region", region)
.get("/bus/timetable/v2")
.then()
.log().all()
.statusCode(HttpStatus.OK.value())
.extract();

JsonAssertions.assertThat(response.asPrettyString())
.isEqualTo("""
{
"bus_timetable": [
{
"route_name": "주중",
"arrival_info": [
{
"nodeName": "한기대",
"arrivalTime": "18:10"
},
{
"nodeName": "신계초,운전리,연춘리",
"arrivalTime": "정차"
},
{
"nodeName": "천안역(학화호두과자)",
"arrivalTime": "18:50"
},{
"nodeName": "터미널(신세계 앞 횡단보도)",
"arrivalTime": "18:55"
}
]
}
],
"updated_at": "2024-02-21T18:00:00"
}
""");
}
}

0 comments on commit 86b7ef0

Please sign in to comment.